Python skimage.color.lab2rgb() Examples
The following are 30
code examples of skimage.color.lab2rgb().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
skimage.color
, or try the search function
.
Example #1
Source File: lab_gamut.py From interactive-deep-colorization with MIT License | 6 votes |
def snap_ab(input_l, input_rgb, return_type='rgb'): ''' given an input lightness and rgb, snap the color into a region where l,a,b is in-gamut ''' T = 20 warnings.filterwarnings("ignore") input_lab = rgb2lab_1d(np.array(input_rgb)) # convert input to lab conv_lab = input_lab.copy() # keep ab from input for t in range(T): conv_lab[0] = input_l # overwrite input l with input ab old_lab = conv_lab tmp_rgb = color.lab2rgb(conv_lab[np.newaxis, np.newaxis, :]).flatten() tmp_rgb = np.clip(tmp_rgb, 0, 1) conv_lab = color.rgb2lab(tmp_rgb[np.newaxis, np.newaxis, :]).flatten() dif_lab = np.sum(np.abs(conv_lab - old_lab)) if dif_lab < 1: break # print(conv_lab) conv_rgb_ingamut = lab2rgb_1d(conv_lab, clip=True, dtype='uint8') if (return_type == 'rgb'): return conv_rgb_ingamut elif(return_type == 'lab'): conv_lab_ingamut = rgb2lab_1d(conv_rgb_ingamut) return conv_lab_ingamut
Example #2
Source File: dataloader.py From Tag2Pix with MIT License | 6 votes |
def __call__(self, img): """numpy array [b, [-1~1], [-1~1], [-1~1]] to target space / result rgb[0~255]""" img = img.data.numpy() if self.color_space == 'rgb': img = (img + 1) * 0.5 img = img.transpose(0, 2, 3, 1) if self.color_space == 'lab': # to [0~100, -128~127, -128~127] img[:,:,:,0] = (img[:,:,:,0] + 1) * 50 img[:,:,:,1] = (img[:,:,:,1] * 127.5) - 0.5 img[:,:,:,2] = (img[:,:,:,2] * 127.5) - 0.5 img_list = [] for i in img: img_list.append(color.lab2rgb(i)) img = np.array(img_list) elif self.color_space == 'hsv': # to [0~1, 0~1, 0~1] img = (img + 1) * 0.5 img_list = [] for i in img: img_list.append(color.hsv2rgb(i)) img = np.array(img_list) img = (img * 255).astype(np.uint8) return img # [0~255] / [b, h, w, 3]
Example #3
Source File: util.py From SMIT with MIT License | 6 votes |
def tensorlab2tensor(lab_tensor, return_inbnd=False): from skimage import color import warnings warnings.filterwarnings("ignore") lab = tensor2np(lab_tensor) * 100. lab[:, :, 0] = lab[:, :, 0] + 50 # print('lab',lab) rgb_back = 255. * np.clip(color.lab2rgb(lab.astype('float')), 0, 1) # print('rgb',rgb_back) if (return_inbnd): # convert back to lab, see if we match lab_back = color.rgb2lab(rgb_back.astype('uint8')) # print('lab_back',lab_back) # print('lab==lab_back',np.isclose(lab_back,lab,atol=1.)) # print('lab-lab_back',np.abs(lab-lab_back)) mask = 1. * np.isclose(lab_back, lab, atol=2.) mask = np2tensor(np.prod(mask, axis=2)[:, :, np.newaxis]) return (im2tensor(rgb_back), mask) else: return im2tensor(rgb_back)
Example #4
Source File: util.py From TecoGAN with Apache License 2.0 | 6 votes |
def tensorlab2tensor(lab_tensor,return_inbnd=False): from skimage import color import warnings warnings.filterwarnings("ignore") lab = tensor2np(lab_tensor)*100. lab[:,:,0] = lab[:,:,0]+50 # print('lab',lab) rgb_back = 255.*np.clip(color.lab2rgb(lab.astype('float')),0,1) # print('rgb',rgb_back) if(return_inbnd): # convert back to lab, see if we match lab_back = color.rgb2lab(rgb_back.astype('uint8')) # print('lab_back',lab_back) # print('lab==lab_back',np.isclose(lab_back,lab,atol=1.)) # print('lab-lab_back',np.abs(lab-lab_back)) mask = 1.*np.isclose(lab_back,lab,atol=2.) mask = np2tensor(np.prod(mask,axis=2)[:,:,np.newaxis]) return (im2tensor(rgb_back),mask) else: return im2tensor(rgb_back)
Example #5
Source File: __init__.py From PerceptualSimilarity with BSD 2-Clause "Simplified" License | 6 votes |
def tensorlab2tensor(lab_tensor,return_inbnd=False): from skimage import color import warnings warnings.filterwarnings("ignore") lab = tensor2np(lab_tensor)*100. lab[:,:,0] = lab[:,:,0]+50 rgb_back = 255.*np.clip(color.lab2rgb(lab.astype('float')),0,1) if(return_inbnd): # convert back to lab, see if we match lab_back = color.rgb2lab(rgb_back.astype('uint8')) mask = 1.*np.isclose(lab_back,lab,atol=2.) mask = np2tensor(np.prod(mask,axis=2)[:,:,np.newaxis]) return (im2tensor(rgb_back),mask) else: return im2tensor(rgb_back)
Example #6
Source File: image.py From Comicolorization with MIT License | 6 votes |
def lab_array_to_image(images_array, normalized=True): # type: (numpy.ndarray, any) -> typing.List[Image.Image] images_array = images_array.transpose(0, 2, 3, 1) if normalized: images_array[:, :, :, 0] = images_array[:, :, :, 0] + 1 images_array *= 50 def lab2image(image_array): image_array = image_array.astype(dtype=numpy.float64) rgb = (lab2rgb(image_array) * 255).astype(numpy.uint8) image = Image.fromarray(rgb) return image images = [lab2image(image_array) for image_array in images_array] return images
Example #7
Source File: apply_makeup.py From visage with MIT License | 6 votes |
def __add_color(self, intensity): """ Adds base colour to all points on lips, at mentioned intensity. """ val = color.rgb2lab( (self.image[self.lip_y, self.lip_x] / 255.) .reshape(len(self.lip_y), 1, 3) ).reshape(len(self.lip_y), 3) l_val, a_val, b_val = np.mean(val[:, 0]), np.mean(val[:, 1]), np.mean(val[:, 2]) l1_val, a1_val, b1_val = color.rgb2lab( np.array( (self.red_l / 255., self.green_l / 255., self.blue_l / 255.) ).reshape(1, 1, 3) ).reshape(3,) l_final, a_final, b_final = (l1_val - l_val) * \ intensity, (a1_val - a_val) * \ intensity, (b1_val - b_val) * intensity val[:, 0] = np.clip(val[:, 0] + l_final, 0, 100) val[:, 1] = np.clip(val[:, 1] + a_final, -127, 128) val[:, 2] = np.clip(val[:, 2] + b_final, -127, 128) self.image[self.lip_y, self.lip_x] = color.lab2rgb(val.reshape( len(self.lip_y), 1, 3)).reshape(len(self.lip_y), 3) * 255
Example #8
Source File: nail.py From Virtual-Makeup with Apache License 2.0 | 6 votes |
def applyTexture(x, y, texture = texture_input): text = imread(texture_input) height,width = text.shape[:2] xmin, ymin = amin(x),amin(y) xmax, ymax = amax(x),amax(y) scale = max(((xmax - xmin + 2)/height),((ymax - ymin + 2)/width)) text = imresize(text, scale) # print text.shape[:2] # print xmax - xmin +2, ymax - ymin+2 X = (x-xmin).astype(int) Y = (y-ymin).astype(int) val1 = color.rgb2lab((text[X, Y]/255.).reshape(len(X), 1, 3)).reshape(len(X), 3) val2 = color.rgb2lab((im[x, y]/255.).reshape(len(x), 1, 3)).reshape(len(x), 3) L, A, B = mean(val2[:,0]), mean(val2[:,1]), mean(val2[:,2]) val2[:, 0] = np.clip(val2[:, 0] - L + val1[:,0], 0, 100) val2[:, 1] = np.clip(val2[:, 1] - A + val1[:,1], -127, 128) val2[:, 2] = np.clip(val2[:, 2] - B + val1[:,2], -127, 128) im[x,y] = color.lab2rgb(val2.reshape(len(x), 1, 3)).reshape(len(x), 3)*255 # points = np.loadtxt('nailpoint_5')
Example #9
Source File: megafacade.py From facade-segmentation with MIT License | 6 votes |
def ransac_guess_color(colors, n_iter=50, std=2): colors = rgb2lab(colors) colors = colors.reshape(-1, 3) masked = colors[:, 0] < 0.1 colors = colors[~masked] assert len(colors) > 0, "Must have at least one color" best_mu = np.array([0, 0, 0]) best_n = 0 for k in range(n_iter): subset = colors[np.random.choice(np.arange(len(colors)), 1)] mu = subset.mean(0) #inliers = (((colors - mu) ** 2 / std) < 1).all(1) inliers = ((np.sqrt(np.sum((colors - mu)**2, axis=1)) / std) < 1) mu = colors[inliers].mean(0) n = len(colors[inliers]) if n > best_n: best_n = n best_mu = mu #import ipdb; ipdb.set_trace() best_mu = np.squeeze(lab2rgb(np.array([[best_mu]]))) return best_mu
Example #10
Source File: colorize.py From faceai with MIT License | 6 votes |
def colorize(): path = './img/colorize/colorize2.png' # cv2.imwrite('./img/colorize3.png', cv2.imread(path, 0)) x, y, image_shape = get_train_data(path) model = build_model() model.load_weights('./data/simple_colorize.h5') output = model.predict(x) output *= 128 tmp = np.zeros((200, 200, 3)) tmp[:, :, 0] = x[0][:, :, 0] tmp[:, :, 1:] = output[0] colorizePath = path.replace(".png", "-res.png") imsave(colorizePath, lab2rgb(tmp)) cv2.imshow("I", cv2.imread(path)) cv2.imshow("II", cv2.imread(colorizePath)) cv2.waitKey(0) cv2.destroyAllWindows() # imsave("test_image_gray.png", rgb2gray(lab2rgb(tmp)))
Example #11
Source File: util.py From Deep-Exemplar-based-Colorization with MIT License | 6 votes |
def batch_lab2rgb_transpose_mc(img_l_mc, img_ab_mc): if isinstance(img_l_mc, Variable): img_l_mc = img_l_mc.data.cpu() if isinstance(img_ab_mc, Variable): img_ab_mc = img_ab_mc.data.cpu() if img_l_mc.is_cuda: img_l_mc = img_l_mc.cpu() if img_ab_mc.is_cuda: img_ab_mc = img_ab_mc.cpu() assert img_l_mc.dim()==4 and img_ab_mc.dim()==4, 'only for batch input' img_l = img_l_mc*l_norm + l_mean img_ab = img_ab_mc*ab_norm + ab_mean pred_lab = torch.cat((img_l, img_ab), dim=1) grid_lab = vutils.make_grid(pred_lab).numpy().astype('float64') grid_rgb = (np.clip(color.lab2rgb(grid_lab.transpose((1, 2, 0))), 0, 1)*255).astype('uint8') return grid_rgb
Example #12
Source File: util.py From Deep-Exemplar-based-Colorization with MIT License | 6 votes |
def lab2rgb_transpose_mc(img_l_mc, img_ab_mc): if isinstance(img_l_mc, Variable): img_l_mc = img_l_mc.data.cpu() if isinstance(img_ab_mc, Variable): img_ab_mc = img_ab_mc.data.cpu() if img_l_mc.is_cuda: img_l_mc = img_l_mc.cpu() if img_ab_mc.is_cuda: img_ab_mc = img_ab_mc.cpu() assert img_l_mc.dim()==3 and img_ab_mc.dim()==3, 'only for batch input' img_l = img_l_mc*l_norm + l_mean img_ab = img_ab_mc*ab_norm + ab_mean pred_lab = torch.cat((img_l, img_ab), dim=0) grid_lab = pred_lab.numpy().astype('float64') grid_rgb = (np.clip(color.lab2rgb(grid_lab.transpose((1, 2, 0))), 0, 1)*255).astype('uint8') return grid_rgb
Example #13
Source File: lab_gamut.py From interactive-deep-colorization with MIT License | 5 votes |
def lab2rgb_1d(in_lab, clip=True, dtype='uint8'): warnings.filterwarnings("ignore") tmp_rgb = color.lab2rgb(in_lab[np.newaxis, np.newaxis, :]).flatten() if clip: tmp_rgb = np.clip(tmp_rgb, 0, 1) if dtype == 'uint8': tmp_rgb = np.round(tmp_rgb * 255).astype('uint8') return tmp_rgb
Example #14
Source File: general_utils.py From DeepLearningImplementations with MIT License | 5 votes |
def plot_batch_eval(color_model, q_ab, X_batch_black, X_batch_color, batch_size, h, w, nb_q, T): # Format X_colorized X_colorized = color_model.predict(X_batch_black / 100.)[:, :, :, :-1] X_colorized = X_colorized.reshape((batch_size * h * w, nb_q)) # Reweight probas X_colorized = np.exp(np.log(X_colorized) / T) X_colorized = X_colorized / np.sum(X_colorized, 1)[:, np.newaxis] # Reweighted q_a = q_ab[:, 0].reshape((1, 313)) q_b = q_ab[:, 1].reshape((1, 313)) X_a = np.sum(X_colorized * q_a, 1).reshape((batch_size, 1, h, w)) X_b = np.sum(X_colorized * q_b, 1).reshape((batch_size, 1, h, w)) X_colorized = np.concatenate((X_batch_black, X_a, X_b), axis=1).transpose(0, 2, 3, 1) X_colorized = [np.expand_dims(color.lab2rgb(im), 0) for im in X_colorized] X_colorized = np.concatenate(X_colorized, 0).transpose(0, 3, 1, 2) X_batch_color = [np.expand_dims(color.lab2rgb(im.transpose(1, 2, 0)), 0) for im in X_batch_color] X_batch_color = np.concatenate(X_batch_color, 0).transpose(0, 3, 1, 2) list_img = [] for i, img in enumerate(X_colorized[:min(32, batch_size)]): arr = np.concatenate([X_batch_color[i], np.repeat(X_batch_black[i] / 100., 3, axis=0), img], axis=2) list_img.append(arr) plt.figure(figsize=(20,20)) list_img = [np.concatenate(list_img[4 * i: 4 * (i + 1)], axis=2) for i in range(len(list_img) // 4)] arr = np.concatenate(list_img, axis=1) plt.imshow(arr.transpose(1,2,0)) ax = plt.gca() ax.get_xaxis().set_ticks([]) ax.get_yaxis().set_ticks([]) plt.tight_layout() plt.show()
Example #15
Source File: general_utils.py From DeepLearningImplementations with MIT License | 5 votes |
def plot_batch(color_model, q_ab, X_batch_black, X_batch_color, batch_size, h, w, nb_q, epoch): # Format X_colorized X_colorized = color_model.predict(X_batch_black / 100.)[:, :, :, :-1] X_colorized = X_colorized.reshape((batch_size * h * w, nb_q)) X_colorized = q_ab[np.argmax(X_colorized, 1)] X_a = X_colorized[:, 0].reshape((batch_size, 1, h, w)) X_b = X_colorized[:, 1].reshape((batch_size, 1, h, w)) X_colorized = np.concatenate((X_batch_black, X_a, X_b), axis=1).transpose(0, 2, 3, 1) X_colorized = [np.expand_dims(color.lab2rgb(im), 0) for im in X_colorized] X_colorized = np.concatenate(X_colorized, 0).transpose(0, 3, 1, 2) X_batch_color = [np.expand_dims(color.lab2rgb(im.transpose(1, 2, 0)), 0) for im in X_batch_color] X_batch_color = np.concatenate(X_batch_color, 0).transpose(0, 3, 1, 2) list_img = [] for i, img in enumerate(X_colorized[:min(32, batch_size)]): arr = np.concatenate([X_batch_color[i], np.repeat(X_batch_black[i] / 100., 3, axis=0), img], axis=2) list_img.append(arr) plt.figure(figsize=(20,20)) list_img = [np.concatenate(list_img[4 * i: 4 * (i + 1)], axis=2) for i in range(len(list_img) // 4)] arr = np.concatenate(list_img, axis=1) plt.imshow(arr.transpose(1,2,0)) ax = plt.gca() ax.get_xaxis().set_ticks([]) ax.get_yaxis().set_ticks([]) plt.tight_layout() plt.savefig("../../figures/fig_epoch%s.png" % epoch) plt.clf() plt.close()
Example #16
Source File: make_dataset.py From DeepLearningImplementations with MIT License | 5 votes |
def check_HDF5(size=64): """ Plot images with landmarks to check the processing """ # Get hdf5 file hdf5_file = os.path.join(data_dir, "CelebA_%s_data.h5" % size) with h5py.File(hdf5_file, "r") as hf: data_color = hf["training_color_data"] data_lab = hf["training_lab_data"] data_black = hf["training_black_data"] for i in range(data_color.shape[0]): fig = plt.figure() gs = gridspec.GridSpec(3, 1) for k in range(3): ax = plt.subplot(gs[k]) if k == 0: img = data_color[i, :, :, :].transpose(1,2,0) ax.imshow(img) elif k == 1: img = data_lab[i, :, :, :].transpose(1,2,0) img = color.lab2rgb(img) ax.imshow(img) elif k == 2: img = data_black[i, 0, :, :] / 255. ax.imshow(img, cmap="gray") gs.tight_layout(fig) plt.show() plt.clf() plt.close()
Example #17
Source File: training_utils.py From deep-koalarization with MIT License | 5 votes |
def lab_to_rgb(img_l, img_ab): """ Convert a pair of numpy arrays (l channel and ab channels) into an rgb image :param img_l: :return: """ lab = np.empty([*img_l.shape[0:2], 3]) lab[:, :, 0] = np.squeeze(((img_l + 1) * 50)) lab[:, :, 1:] = img_ab * 127 return color.lab2rgb(lab)
Example #18
Source File: util.py From Text2Colors with MIT License | 5 votes |
def lab2rgb_1d(in_lab, clip=True): warnings.filterwarnings("ignore") tmp_rgb = lab2rgb(in_lab[np.newaxis, np.newaxis, :], illuminant='D50').flatten() if clip: tmp_rgb = np.clip(tmp_rgb, 0, 1) return tmp_rgb
Example #19
Source File: colorize.py From reddit_crawlers with BSD 2-Clause "Simplified" License | 5 votes |
def runDNN(imagePath): global net,W_in,H_in,H_out,W_out if net is None: print 'Fuck you!' return -1 # load the original image img_rgb = caffe.io.load_image(imagePath) (H_orig,W_orig) = img_rgb.shape[:2] # original image size img_lab = color.rgb2lab(img_rgb) # convert image to lab color space img_l = img_lab[:,:,0] # pull out L channel # Strech the histogram powerFactor = 1 img_l = img_l - np.min(img_l) img_l = img_l / np.max(img_l) * 2 img_l = np.power(img_l,powerFactor) * 100/np.power(2,powerFactor) # resize image to network input size img_rs = caffe.io.resize_image(img_rgb,(H_in,W_in)) # resize image to network input size img_lab_rs = color.rgb2lab(img_rs) img_l_rs = img_lab_rs[:,:,0] # Strech the histogram img_l_rs = img_l_rs - np.min(img_l_rs) img_l_rs = img_l_rs / np.max(img_l_rs) * 2 img_l_rs = np.power(img_l_rs,powerFactor) * 100/np.power(2,powerFactor) net.blobs['data_l'].data[0,0,:,:] = img_l_rs - lm_lab_l_rs # subtract 50 for mean-centering net.forward() # run network print '\n finish going through network! \n' ab_dec = net.blobs['class8_ab'].data[0,:,:,:].transpose((1,2,0)) # this is our result ab_dec_us = sni.zoom(ab_dec,(1.*H_orig/H_out,1.*W_orig/W_out,1)) # upsample to match size of original image L img_lab_out = np.concatenate((img_l[:,:,np.newaxis],ab_dec_us),axis=2) # concatenate with original image L img_rgb_out = np.clip(color.lab2rgb(img_lab_out),0,1) # convert back to rgb return (img_rgb_out[:,:,[2,1,0]]*255.0).astype('uint8')
Example #20
Source File: lab_gamut.py From interactive-deep-colorization with MIT License | 5 votes |
def update_gamut(self, l_in): warnings.filterwarnings("ignore") thresh = 1.0 pts_lab = np.concatenate((l_in + np.zeros((self.A, self.B, 1)), self.pts_full_grid), axis=2) self.pts_rgb = (255 * np.clip(color.lab2rgb(pts_lab), 0, 1)).astype('uint8') pts_lab_back = color.rgb2lab(self.pts_rgb) pts_lab_diff = np.linalg.norm(pts_lab - pts_lab_back, axis=2) self.mask = pts_lab_diff < thresh mask3 = np.tile(self.mask[..., np.newaxis], [1, 1, 3]) self.masked_rgb = self.pts_rgb.copy() self.masked_rgb[np.invert(mask3)] = 255 return self.masked_rgb, self.mask
Example #21
Source File: colorize_image.py From interactive-deep-colorization with MIT License | 5 votes |
def lab2rgb_transpose(img_l, img_ab): ''' INPUTS img_l 1xXxX [0,100] img_ab 2xXxX [-100,100] OUTPUTS returned value is XxXx3 ''' pred_lab = np.concatenate((img_l, img_ab), axis=0).transpose((1, 2, 0)) pred_rgb = (np.clip(color.lab2rgb(pred_lab), 0, 1) * 255).astype('uint8') return pred_rgb
Example #22
Source File: gui_draw.py From interactive-deep-colorization with MIT License | 5 votes |
def suggest_color(self, h, w, K=5): if self.dist_model is not None and self.image_loaded: ab, conf = self.dist_model.get_ab_reccs(h=h, w=w, K=K, N=25000, return_conf=True) L = np.tile(self.im_lab[h, w, 0], (K, 1)) colors_lab = np.concatenate((L, ab), axis=1) colors_lab3 = colors_lab[:, np.newaxis, :] colors_rgb = np.clip(np.squeeze(color.lab2rgb(colors_lab3)), 0, 1) colors_rgb_withcurr = np.concatenate((self.model.get_img_forward()[h, w, np.newaxis, :] / 255., colors_rgb), axis=0) return colors_rgb_withcurr else: return None
Example #23
Source File: TensorflowUtils.py From Colorization.tensorflow with MIT License | 5 votes |
def save_image(image, save_dir, name): """ Save image by unprocessing and converting to rgb. :param image: iamge to save :param save_dir: location to save image at :param name: prefix to save filename :return: """ image = color.lab2rgb(image) io.imsave(os.path.join(save_dir, name + ".png"), image)
Example #24
Source File: saturation.py From rasterio-cookbook with MIT License | 5 votes |
def lch2rgb(lch): """Convert LCH to RGB colorspace (via LAB) Input and output are in (bands, cols, rows) order """ # reshape for skimage (bands, cols, rows) -> (cols, rows, bands) slch = np.swapaxes(lch, 0, 2) # convert colorspace rgb = lab2rgb(lch2lab(slch)) # return in (bands, cols, rows) order return np.swapaxes(rgb, 2, 0)
Example #25
Source File: data_utils.py From Coloring-greyscale-images with MIT License | 5 votes |
def save_each_image(colored_layers, BW_layer, cycle, nr, path, ending): cur = np.zeros((128, 128, 3)) cur[:,:,0] = BW_layer[:,:,0] * 100 cur[:,:,1:] = colored_layers * 128 imsave(os.path.join(path, cycle + nr + ending), lab2rgb(cur))
Example #26
Source File: util.py From Deep-Exemplar-based-Colorization with MIT License | 5 votes |
def lab2rgb_transpose(img_l, img_ab): ''' INPUTS img_l 1xXxX [0,100] img_ab 2xXxX [-100,100] OUTPUTS returned value is XxXx3 ''' pred_lab = np.concatenate((img_l, img_ab), axis=0).transpose((1, 2, 0)) pred_rgb = (np.clip(color.lab2rgb(pred_lab), 0, 1)*255).astype('uint8') return pred_rgb
Example #27
Source File: nail.py From Virtual-Makeup with Apache License 2.0 | 5 votes |
def applyNailPolish(x , y , r = Rg, g = Gg, b = Bg): val = color.rgb2lab((im[x, y]/255.).reshape(len(x), 1, 3)).reshape(len(x), 3) L, A, B = mean(val[:,0]), mean(val[:,1]), mean(val[:,2]) L1, A1, B1 = color.rgb2lab(np.array((r/255., g/255., b/255.)).reshape(1, 1, 3)).reshape(3,) ll, aa, bb = L1 - L, A1 - A, B1 - B val[:, 0] = np.clip(val[:, 0] + ll, 0, 100) val[:, 1] = np.clip(val[:, 1] + aa, -127, 128) val[:, 2] = np.clip(val[:, 2] + bb, -127, 128) im[x, y] = color.lab2rgb(val.reshape(len(x), 1, 3)).reshape(len(x), 3)*255
Example #28
Source File: blush.py From Virtual-Makeup with MIT License | 5 votes |
def apply_blush_color(r=Rg, g=Gg, b=Bg): global im val = color.rgb2lab((im / 255.)).reshape(width * height, 3) L, A, B = mean(val[:, 0]), mean(val[:, 1]), mean(val[:, 2]) L1, A1, B1 = color.rgb2lab(np.array((r / 255., g / 255., b / 255.)).reshape(1, 1, 3)).reshape(3, ) ll, aa, bb = (L1 - L) * intensity, (A1 - A) * intensity, (B1 - B) * intensity val[:, 0] = np.clip(val[:, 0] + ll, 0, 100) val[:, 1] = np.clip(val[:, 1] + aa, -127, 128) val[:, 2] = np.clip(val[:, 2] + bb, -127, 128) im = color.lab2rgb(val.reshape(height, width, 3)) * 255
Example #29
Source File: nail.py From Virtual-Makeup with MIT License | 5 votes |
def apply_texture(x, y): xmin, ymin = amin(x), amin(y) X = (x - xmin).astype(int) Y = (y - ymin).astype(int) val1 = color.rgb2lab((text[X, Y] / 255.).reshape(len(X), 1, 3)).reshape(len(X), 3) val2 = color.rgb2lab((im[x, y] / 255.).reshape(len(x), 1, 3)).reshape(len(x), 3) L, A, B = mean(val2[:, 0]), mean(val2[:, 1]), mean(val2[:, 2]) val2[:, 0] = np.clip(val2[:, 0] - L + val1[:, 0], 0, 100) val2[:, 1] = np.clip(val2[:, 1] - A + val1[:, 1], -127, 128) val2[:, 2] = np.clip(val2[:, 2] - B + val1[:, 2], -127, 128) im[x, y] = color.lab2rgb(val2.reshape(len(x), 1, 3)).reshape(len(x), 3) * 255
Example #30
Source File: nail.py From Virtual-Makeup with MIT License | 5 votes |
def apply_nail_polish(x, y, r=Rg, g=Gg, b=Bg): val = color.rgb2lab((im[x, y] / 255.).reshape(len(x), 1, 3)).reshape(len(x), 3) L, A, B = mean(val[:, 0]), mean(val[:, 1]), mean(val[:, 2]) L1, A1, B1 = color.rgb2lab(np.array((r / 255., g / 255., b / 255.)).reshape(1, 1, 3)).reshape(3, ) ll, aa, bb = L1 - L, A1 - A, B1 - B val[:, 0] = np.clip(val[:, 0] + ll, 0, 100) val[:, 1] = np.clip(val[:, 1] + aa, -127, 128) val[:, 2] = np.clip(val[:, 2] + bb, -127, 128) im[x, y] = color.lab2rgb(val.reshape(len(x), 1, 3)).reshape(len(x), 3) * 255