当前位置: 首页>>代码示例>>Python>>正文


Python color.lab2rgb方法代码示例

本文整理汇总了Python中skimage.color.lab2rgb方法的典型用法代码示例。如果您正苦于以下问题:Python color.lab2rgb方法的具体用法?Python color.lab2rgb怎么用?Python color.lab2rgb使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在skimage.color的用法示例。


在下文中一共展示了color.lab2rgb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: snap_ab

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import lab2rgb [as 别名]
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 
开发者ID:junyanz,项目名称:interactive-deep-colorization,代码行数:27,代码来源:lab_gamut.py

示例2: batch_lab2rgb_transpose_mc

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import lab2rgb [as 别名]
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 
开发者ID:msracver,项目名称:Deep-Exemplar-based-Colorization,代码行数:21,代码来源:util.py

示例3: lab2rgb_transpose_mc

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import lab2rgb [as 别名]
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 
开发者ID:msracver,项目名称:Deep-Exemplar-based-Colorization,代码行数:21,代码来源:util.py

示例4: colorize

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import lab2rgb [as 别名]
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))) 
开发者ID:vipstone,项目名称:faceai,代码行数:21,代码来源:colorize.py

示例5: ransac_guess_color

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import lab2rgb [as 别名]
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 
开发者ID:jfemiani,项目名称:facade-segmentation,代码行数:26,代码来源:megafacade.py

示例6: applyTexture

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import lab2rgb [as 别名]
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') 
开发者ID:badarsh2,项目名称:Virtual-Makeup,代码行数:22,代码来源:nail.py

示例7: __add_color

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import lab2rgb [as 别名]
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 
开发者ID:hriddhidey,项目名称:visage,代码行数:22,代码来源:apply_makeup.py

示例8: lab_array_to_image

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import lab2rgb [as 别名]
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 
开发者ID:DwangoMediaVillage,项目名称:Comicolorization,代码行数:18,代码来源:image.py

示例9: tensorlab2tensor

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import lab2rgb [as 别名]
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) 
开发者ID:richzhang,项目名称:PerceptualSimilarity,代码行数:19,代码来源:__init__.py

示例10: tensorlab2tensor

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import lab2rgb [as 别名]
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) 
开发者ID:thunil,项目名称:TecoGAN,代码行数:24,代码来源:util.py

示例11: tensorlab2tensor

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import lab2rgb [as 别名]
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) 
开发者ID:BCV-Uniandes,项目名称:SMIT,代码行数:24,代码来源:util.py

示例12: __call__

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import lab2rgb [as 别名]
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] 
开发者ID:blandocs,项目名称:Tag2Pix,代码行数:27,代码来源:dataloader.py

示例13: lab2rgb_1d

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import lab2rgb [as 别名]
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 
开发者ID:junyanz,项目名称:interactive-deep-colorization,代码行数:10,代码来源:lab_gamut.py

示例14: update_gamut

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import lab2rgb [as 别名]
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 
开发者ID:junyanz,项目名称:interactive-deep-colorization,代码行数:15,代码来源:lab_gamut.py

示例15: lab2rgb_transpose

# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import lab2rgb [as 别名]
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 
开发者ID:junyanz,项目名称:interactive-deep-colorization,代码行数:11,代码来源:colorize_image.py


注:本文中的skimage.color.lab2rgb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。