def vector_image_to_vector_part()

in data_process.py [0:0]


def vector_image_to_vector_part(vector_images, target_part, side=64, line_diameter=16, padding=16, data_name='bird'):
	"""
	save processed vector image for target_parts: input partial images, input parts and target images with target parts
	"""
	original_side = 512.
	# scale to match the new size
	# add padding at the edges for the line_diameter
	# and add additional padding to account for antialiasing
	total_padding = padding * 2. + line_diameter
	new_scale = float(side) / float(original_side + total_padding)
	processed_vector_input_parts = []
	processed_vector_parts = []
	# each item in processed_vector_images is a list that corresponds to all target parts that appear in that sketch
	for i, vector_data in enumerate(vector_images):
		# check if target part is drawn
		processed_vector_input_parts.append([])
		processed_vector_parts.append([])
		# store the strokes for each part
		if data_name == 'bird':
			strokes_input_parts = {'initial':[], 'eye':[], 'beak':[], 'body':[], 'head':[], 'legs':[], 'mouth':[], 'tail':[], 'wings':[]}
		elif data_name == 'creature':
			strokes_input_parts = {'initial':[], 'eye':[], 'arms':[], 'beak':[], 'mouth':[], 'body':[], 'ears':[], 'feet':[],  'fin':[], 'hair':[], 'hands':[], 
									'head':[], 'horns':[], 'legs':[],  'nose':[], 'paws':[], 'tail':[], 'wings':[]}
		if target_part not in vector_data['partsUsed']:
			continue
		vector_image = []
		x_max = y_max = 0
		for step in vector_data['all_strokes']:
			vector_image.append([]) # for each step
			for stroke in step:
				if len(stroke) == 0: # skip the empty stroke
					vector_image[-1].append([])
					continue
				vector_image[-1].append(np.array([stroke[0][:2]]+[point[2:4] for point in stroke])) # add each stroke N x 2
				x_max_stroke, y_max_stroke = np.max(vector_image[-1][-1], 0)
				x_max = x_max_stroke if x_max_stroke>x_max else x_max
				y_max = y_max_stroke if y_max_stroke>y_max else y_max
		offset = ((original_side, original_side) - np.array([x_max, y_max])) / 2.
		offset = offset.reshape(1,2)
		for j in range(len(vector_image)):
			for k in range(len(vector_image[j])):
				vector_image[j][k] = vector_image[j][k]+offset  if len(vector_image[j][k]) > 0 else vector_image[j][k]
		# save strokes
		for j, step in enumerate(vector_image): 
			if vector_data['partsUsed'][j] == target_part: # find one part
				processed_vector_input_parts[-1].append(copy.deepcopy(strokes_input_parts))
			if j != len(vector_image)-1 and vector_data['partsUsed'][j] != 'details': # last one and details
				strokes_input_parts[vector_data['partsUsed'][j]] += step
			else:
				continue
			if vector_data['partsUsed'][j] == target_part:
				# record the input + part
				processed_vector_parts[-1].append(step)
		# record all the parts
		processed_vector_input_parts[-1].append(copy.deepcopy(strokes_input_parts))
	return processed_vector_input_parts, processed_vector_parts