def draw_long_hair(shapes,hair_file,im, color): face_width = shapes.part(0).x - shapes.part(16).x ratio = -face_width/400. y_long_shift = 0 if "ncc" in hair_file: hair_idx = hair_file[-7] hair_file = "hair/"+hair_idx + "-l.png" if hair_idx == "5": y_long_shift = 25 hair_im = Image.open(hair_file) #resize pt_0 = ((hair_im.size[0]/2. - 200)*ratio, 410*ratio) hair_im = hair_im.resize((int(hair_im.size[0]*ratio), int(hair_im.size[1]*ratio)),resample=Image.BICUBIC) #color hair print color if color[0] < 55 and color[1] < 55 and color[2] < 55: #black hair #black hair, greyscale it. r, g, b, alpha = hair_im.split() hair_im = hair_im.convert('LA') hair_im = hair_im.convert('RGBA') hair_im.putalpha(alpha) print 'hair turned to black' else: color_hsv = colorsys.rgb_to_hsv(color[0], color[1], color[2]) hue = color_hsv[0] * 360 hair_im = autoanime.colorize(hair_im, hue) print 'colorized hair to hue ', hue shift_x = int(shapes.part(0).x - pt_0[0]) shift_y = int(shapes.part(0).y - pt_0[1]) + y_long_shift im.paste(hair_im, box=(shift_x,shift_y), mask=hair_im) return im
def draw_hair(shapes,hair_file,im, angle, color): # resize hairfile face_width = shapes.part(0).x - shapes.part(16).x ratio = -face_width/400. shift_y_long = 0 if "ncc" in hair_file: hair_idx = hair_file[-7] hair_file = "hair/"+hair_idx + "-s-f.png" if hair_idx == "5": shift_y_long = 25 hair_im = Image.open(hair_file) #change color #default RGB = 128,83,48 print color if color[0] < 55 and color[1] < 55 and color[2] < 55: #black hair #black hair, greyscale it. r, g, b, alpha = hair_im.split() hair_im = hair_im.convert('LA') hair_im = hair_im.convert('RGBA') hair_im.putalpha(alpha) print 'hair turned to black' else: color_hsv = colorsys.rgb_to_hsv(color[0], color[1], color[2]) print 'hair hsv is ', color_hsv hue = color_hsv[0] * 360 hair_im = autoanime.colorize(hair_im, hue) print 'colorized hair to hue ', hue pt_0 = ((hair_im.size[0]/2. - 200)*ratio, 410*ratio) hair_im = hair_im.resize((int(hair_im.size[0]*ratio), int(hair_im.size[1]*ratio)),resample=Image.BICUBIC) #then rotate it hair_im = hair_im.rotate(angle, resample=Image.BICUBIC, expand = 1) print "we rotated the hair by ", angle shift_x = int(shapes.part(0).x - pt_0[0]) shift_y = int(shapes.part(0).y - pt_0[1]) + shift_y_long im.paste(hair_im, box=(shift_x,shift_y), mask=hair_im) return im