• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python color.rgb2lab函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中skimage.color.rgb2lab函数的典型用法代码示例。如果您正苦于以下问题:Python rgb2lab函数的具体用法?Python rgb2lab怎么用?Python rgb2lab使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: run_color

def run_color(image, image_out):
    caffe.set_mode_cpu()
    net = caffe.Net('colorization_deploy_v0.prototxt', 'colorization_release_v0.caffemodel', caffe.TEST)

    (H_in,W_in) = net.blobs['data_l'].data.shape[2:] # get input shape
    (H_out,W_out) = net.blobs['class8_ab'].data.shape[2:] # get output shape
    net.blobs['Trecip'].data[...] = 6/np.log(10) # 1/T, set annealing temperature
    
    img_rgb = caffe.io.load_image(image)
    img_lab = color.rgb2lab(img_rgb) # convert image to lab color space
    img_l = img_lab[:,:,0] # pull out L channel
    (H_orig,W_orig) = img_rgb.shape[:2] # original image size

    # 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]

    net.blobs['data_l'].data[0,0,:,:] = img_l_rs-50 # subtract 50 for mean-centering
    net.forward() # run network

    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

    scipy.misc.imsave(image_out, img_rgb_out)
开发者ID:tfolkman,项目名称:384_final_project,代码行数:27,代码来源:run_color.py


示例2: applyNailPolish

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
开发者ID:badarsh2,项目名称:Virtual-Makeup,代码行数:9,代码来源:nail.py


示例3: convertLAB

def convertLAB(img):
    "convert an RGB img into LAB color space"
    if img.shape[2]==4:
        return rgb2lab(img[:,:,0:3])
    else:
        if img.shape[2]==3:
            return rgb2lab(img)
        else:
            print ("Image format not supported")
开发者ID:dgormez,项目名称:pattern-recognition,代码行数:9,代码来源:pattern-reco.py


示例4: process_pair

def process_pair(ref, recons):
    ref_lab = color.rgb2lab(decode_y4m_buffer(ref))
    recons_lab = color.rgb2lab(decode_y4m_buffer(recons))
    # "Color Image Quality Assessment Based on CIEDE2000"
    # Yang Yang, Jun Ming and Nenghai Yu, 2012
    # http://dx.doi.org/10.1155/2012/273723
    dE = color.deltaE_ciede2000(ref_lab, recons_lab, kL=0.65, kC=1.0, kH=4.0)
    scores.append(45. - 20. * np.log10(dE.mean()))
    print('%08d: %2.4f' % (ref.count, scores[-1]))
开发者ID:AlecGamble,项目名称:daala,代码行数:9,代码来源:dump_ciede2000.py


示例5: get_train_data

def get_train_data(img_file):
    image = img_to_array(load_img(img_file))
    image_shape = image.shape
    image = np.array(image, dtype=float)
    x = rgb2lab(1.0 / 255 * image)[:, :, 0]
    y = rgb2lab(1.0 / 255 * image)[:, :, 1:]
    y /= 128
    x = x.reshape(1, image_shape[0], image_shape[1], 1)
    y = y.reshape(1, image_shape[0], image_shape[1], 2)
    return x, y, image_shape
开发者ID:fantasy-mark,项目名称:faceai,代码行数:10,代码来源:colorize.py


示例6: merge_images

    def merge_images(self, img_a, img_b):
        i_a = skic.rgb2lab(img_a)
        i_b = skic.rgb2lab(img_b)

        norm_lum = np.max(np.asarray([i_a[..., 0], i_b[..., 0]]), axis=0)

        res_img = i_a.copy()
        res_img[..., 0] = norm_lum

        return skic.lab2rgb(res_img)
开发者ID:groakat,项目名称:webcamSeriesCapture,代码行数:10,代码来源:acquisition.py


示例7: applyBlushColor

def applyBlushColor(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
开发者ID:d3xt3-bitstechlab,项目名称:Virtual-Makeup,代码行数:10,代码来源:blush.py


示例8: apply_texture

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
开发者ID:srivatsan-ramesh,项目名称:Virtual-Makeup,代码行数:11,代码来源:nail.py


示例9: LAB

def LAB(img, k, filename):
    # print 'lab'
    # restructure image pixel values into range from 0 to 1 - needed for library
    img = img * 1.0 / MAX_COLOR_VAL

    # convert rgb to LAB
    pixels_lab = color.rgb2lab(img)
    # remove the L channel
    L = pixels_lab[:, :, 0]

    # reshape, cluster, and retrieve quantized values
    pixels_l = np.reshape(L, (L.shape[0] * L.shape[1], 1))
    clustered = cluster_pixels(pixels_l, k, (L.shape[0], L.shape[1]))
    pixels_lab[:, :, 0] = clustered[:, :, 0]

    # convert result to 255 RGB space
    quanted_img = color.lab2rgb(pixels_lab) * MAX_COLOR_VAL
    quanted_img = quanted_img.astype('uint8')

    fig = plt.figure(1)
    plt.imshow(quanted_img)
    plt.title("LAB quantization where k is " + str(k))
    plt.savefig('Q2/' + filename + '_LAB.png')
    plt.close(fig)
    return quanted_img
开发者ID:chongyeegan,项目名称:computer-vision-hw-1,代码行数:25,代码来源:q2.py


示例10: b

def b():
    from skimage import io, color
    print 'imported'
    rgb = io.imread('window_exp_1_1.jpg')
    print 'opened'
    lab = color.rgb2lab(rgb)
    print lab[0,0]
开发者ID:axil,项目名称:fusion,代码行数:7,代码来源:linearize.py


示例11: compute_saliency

def compute_saliency(img):
    """
        Computes Boolean Map Saliency (BMS).
    """

    img_lab = rgb2lab(img)
    img_lab -= img_lab.min()
    img_lab /= img_lab.max()
    thresholds = np.arange(0, 1, 1.0 / N_THRESHOLDS)[1:]

    # compute boolean maps
    bool_maps = []
    for thresh in thresholds:
        img_lab_T = img_lab.transpose(2, 0, 1)
        img_thresh = (img_lab_T > thresh)
        bool_maps.extend(list(img_thresh))

    # compute mean attention map
    attn_map = np.zeros(img_lab.shape[:2], dtype=np.float)
    for bool_map in bool_maps:
        attn_map += activate_boolean_map(bool_map)
    attn_map /= N_THRESHOLDS

    # gaussian smoothing
    attn_map = cv2.GaussianBlur(attn_map, (0, 0), 3)

    # perform normalization
    norm = np.sqrt((attn_map**2).sum())
    attn_map /= norm
    attn_map /= attn_map.max() / 255

    return attn_map.astype(np.uint8)
开发者ID:caomw,项目名称:saliency-bms,代码行数:32,代码来源:saliency.py


示例12: dominant_colors

def dominant_colors(image, num_colors, mask=None):
    """Reduce image colors to a representative set of a given size.

    Args:
        image (ndarray): BGR image of shape n x m x 3.
        num_colors (int): Number of colors to reduce to.
        mask (array_like, optional): Foreground mask. Defaults to None.

    Returns:
        list: The list of Color objects representing the most dominant colors in the image.

    """
    image = rgb2lab(image / 255.0)

    if mask is not None:
        data = image[mask > 250]
    else:
        data = np.reshape(image, (-1, 3))

    # kmeans algorithm has inherent randomness - result will not be exactly the same
    # every time. Fairly consistent with >= 30 iterations
    centroids, labels = kmeans2(data, num_colors, iter=30)
    counts = np.histogram(labels, bins=range(0, num_colors + 1), normed=True)[0]

    centroids_RGB = lab2rgb(centroids.reshape(-1, 1, 3))[:, 0, :] * 255.0
    colors = [Color(centroid, count) for centroid, count in zip(centroids_RGB, counts)]
    colors.sort(key=lambda color: np.mean(color.BGR))

    return colors
开发者ID:jrdurrant,项目名称:vision,代码行数:29,代码来源:color_analysis.py


示例13: __init__

    def __init__(self, image_path):
        rgb = io.imread(image_path)
        self.lab = color.rgb2lab(rgb)
        self.im_shp = self.lab.shape
        self.r_image = np.zeros((self.im_shp[0], self.im_shp[1]-1))

        pass
开发者ID:hijinks,项目名称:auto-wolman,代码行数:7,代码来源:delta_filter.py


示例14: snap_ab

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:richzhang,项目名称:colorization,代码行数:25,代码来源:lab_gamut.py


示例15: color2gray

def color2gray(image, itns):

  global width
  global height
  global lab

  width = image.shape[1]
  height = image.shape[0]
 
 # Convert rgb to lab color space
  lab = color.rgb2lab(image);

  g0 = lab[:, :, 0]
  g0 = g0.astype(np.uint8)
  g0 = g0.flatten()

  # Solve Least square Optimization
  res = minimize(objective, g0, method='BFGS', jac=objective_der, options={'maxiter':itns, 'disp': True})
  
  output = res.x.reshape(height, width)
  output = output.astype(np.uint8)

  output += 50

  return output
开发者ID:sasmita,项目名称:Color-to-Gray-Methods,代码行数:25,代码来源:color2gray.py


示例16: run

	def run(self, im, skin_thresh=[-1,1], n_peaks=3):
		'''
		im : color image
		'''
		im_skin = rgb2lab(im.astype(np.int16))[:,:,2]
		self.im_skin = im_skin
		# im_skin = skimage.exposure.equalize_hist(im_skin)
		# im_skin = skimage.exposure.rescale_intensity(im_skin, out_range=[0,1])
		im_skin *= im_skin > skin_thresh[0]
		im_skin *= im_skin < skin_thresh[1]

		skin_match_c = nd.correlate(-im_skin, self.hand_template)
		self.skin_match = skin_match_c

		# Display Predictions - Color Based matching
		optima = peak_local_max(skin_match_c, min_distance=20, num_peaks=n_peaks, exclude_border=False)
		# Visualize
		if len(optima) > 0:
			optima_values = skin_match_c[optima[:,0], optima[:,1]]
			optima_thresh = np.max(optima_values) / 2
			optima = optima.tolist()

			for i,o in enumerate(optima):
				if optima_values[i] < optima_thresh:
					optima.pop(i)
					break
		self.markers = optima

		return self.markers
开发者ID:MerDane,项目名称:pyKinectTools,代码行数:29,代码来源:PoseTracking.py


示例17: call_color_sig

def call_color_sig(path_to_image):

    size = 360
    nclusters = 15

    image_array = io.imread(path_to_image)
    image_array = transform.resize(image_array,(size,size), \
    mode='nearest')
    image_array = color.rgb2lab(image_array)
    image_array = image_array.reshape(-1,3)

    k_means = cluster.MiniBatchKMeans(nclusters,init='k-means++',n_init=1,\
              max_iter=300,tol=0.01,random_state=451792)
    k_means.fit(image_array)
    centers = k_means.cluster_centers_.squeeze()
    labels = k_means.labels_

    pixels_tot = 0
    pixels_loc = np.empty((nclusters,1),dtype=int)
    for index in np.arange(0,nclusters):
        pixels_loc[index] = np.sum((labels == index).astype('int'))
        pixels_tot += pixels_loc[index]

    weights = pixels_loc.astype('float')/pixels_tot

    #print "Total number of pixels ", pixels_tot
    signature = \
    np.concatenate((weights,centers),axis=1).T.flatten()

    return signature
开发者ID:cccue,项目名称:Watch_and_learn,代码行数:30,代码来源:model.py


示例18: test_rgb_lch_roundtrip

 def test_rgb_lch_roundtrip(self):
     rgb = img_as_float(self.img_rgb)
     lab = rgb2lab(rgb)
     lch = lab2lch(lab)
     lab2 = lch2lab(lch)
     rgb2 = lab2rgb(lab2)
     assert_array_almost_equal(rgb, rgb2)
开发者ID:AceHao,项目名称:scikit-image,代码行数:7,代码来源:test_colorconv.py


示例19: _convert_colorspace

    def _convert_colorspace(self,image,colorspace,blur=False, sigma=3):
        """ 
        INPUT:
                image: The image to be converted to the specified colorspace, should have shape=(image_x,image_y,3)
                        the input colorspace should be RGB mapped between [0 and 1], (it will return the same image if colorspace is set to RGB)
                colorspace: the colorspace that the images will be put in;
                        'CIELab' for CIELab colorspace
                        'CIEL*a*b*' for the mapped CIELab colorspace (by function remap_CIELab in NNPreprocessor)
                        'RGB' for rgb mapped between [0 and 1]
                        'YCbCr' for YCbCr
                        'HSV' for HSV
                blur: Blur the target output of the image if True.
                        Supported colorspaces:
                            'CIELab'
                            'CIEL*a*b*'
                            'HSV'
                            'YUV'
        OUTPUT:
                The image converted to the specified colorspace of shape=(image_x,image_y,3)
        """

        # Convert to CIELab
        if ( (colorspace == 'CIELab') or (colorspace == 'CIEL*a*b*') ):
            # This converts the rgb to XYZ where:
            # X is in [0, 95.05]
            # Y is in [0, 100]
            # Z is in [0, 108.9]
            # Then from XYZ to CIELab where: (DOES DEPEND ON THE WHITEPOINT!, here for default)
            # L is in [0, 100]
            # a is in [-431.034,  431.034] --> [-500*(1-16/116), 500*(1-16/116)]
            # b is in [-172.41379, 172.41379] --> [-200*(1-16/116), 200*(1-16/116)]
            image = color.rgb2lab(image)

        return image
开发者ID:joostmeulenbeld,项目名称:AutoColorizer,代码行数:34,代码来源:labmeshtest.py


示例20: add_lab_stats

def add_lab_stats(pic, sp_mask, features):
    lab = color.rgb2lab(pic)
    layered = to_layered(lab)
    add_statistics(layered[0], sp_mask, features, 'lab_l')
    add_statistics(layered[1], sp_mask, features, 'lab_a')
    add_statistics(layered[2], sp_mask, features, 'lab_b')
    return
开发者ID:pauljv92,项目名称:cs446_mapgen,代码行数:7,代码来源:feature_extractor.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python color.rgb2xyz函数代码示例发布时间:2022-05-27
下一篇:
Python color.rgb2hsv函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap