本文整理汇总了Python中skimage.color.rgb2lab方法的典型用法代码示例。如果您正苦于以下问题:Python color.rgb2lab方法的具体用法?Python color.rgb2lab怎么用?Python color.rgb2lab使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skimage.color
的用法示例。
在下文中一共展示了color.rgb2lab方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: snap_ab
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2lab [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
示例2: _transform
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2lab [as 别名]
def _transform(self, filename):
try:
image = misc.imread(filename)
if len(image.shape) < 3: # make sure images are of shape(h,w,3)
image = np.array([image for i in range(3)])
if self.image_options.get("resize", False) and self.image_options["resize"]:
resize_size = int(self.image_options["resize_size"])
resize_image = misc.imresize(image,
[resize_size, resize_size])
else:
resize_image = image
if self.image_options.get("color", False):
option = self.image_options['color']
if option == "LAB":
resize_image = color.rgb2lab(resize_image)
elif option == "HSV":
resize_image = color.rgb2hsv(resize_image)
except:
print ("Error reading file: %s of shape %s" % (filename, str(image.shape)))
raise
return np.array(resize_image)
示例3: ransac_guess_color
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2lab [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
示例4: applyTexture
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2lab [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')
示例5: __add_color
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2lab [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
示例6: _draw_process
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2lab [as 别名]
def _draw_process(self, small_input_image, big_input_image):
lab = rgb2lab(numpy.array(small_input_image))
lab[:, :, 0] /= 100
small_image = self.drawer.draw(
input_images_array=lab.astype(numpy.float32).transpose(2, 0, 1)[numpy.newaxis],
rgb_images_array=numpy.array(self.reference_image, dtype=numpy.float32).transpose(2, 0, 1)[numpy.newaxis],
)[0]
small_image = small_image.convert('RGB')
if self.drawer_sr is not None:
drawn_panel_image = self._superresolution_process(small_image, big_input_image)
else:
drawn_panel_image = small_image
return drawn_panel_image
示例7: tensorlab2tensor
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2lab [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)
示例8: tensorlab2tensor
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2lab [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)
示例9: tensorlab2tensor
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2lab [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)
示例10: loadDNN
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2lab [as 别名]
def loadDNN(useGpu = False):
global net,W_in,H_in,H_out,W_out,lm_lab_l_rs
if useGpu:
gpu_id = 0
caffe.set_mode_gpu()
caffe.set_device(gpu_id)
net = caffe.Net('colorization_deploy_v0.prototxt', 'colorization_release_v0.caffemodel', caffe.TEST)
print '\n done loading network! \n'
(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
l_mean = sio.loadmat('ilsvrc_2012_mean.mat')
lm = np.array(l_mean['mean_data'])
lm = lm/np.max(lm)
lm_lab = color.rgb2lab(lm)
lm_lab_l = lm_lab[:,:,0]
lm_lab_l = lm_lab_l - np.mean(np.mean(lm_lab_l)) + 50
lm_lab_l = Image.fromarray(lm_lab_l)
lm_lab_l_rs = lm_lab_l.resize((W_in,H_in), Image.ANTIALIAS)
示例11: process_image
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2lab [as 别名]
def process_image(image_data, batch_size, imsize):
input = torch.zeros(batch_size, 1, imsize, imsize)
labels = torch.zeros(batch_size, 2, imsize, imsize)
images_np = image_data.numpy().transpose((0, 2, 3, 1))
for k in range(batch_size):
img_lab = rgb2lab(images_np[k], illuminant='D50')
img_l = img_lab[:, :, 0] / 100
input[k] = torch.from_numpy(np.expand_dims(img_l, 0))
img_a_scale = (img_lab[:, :, 1:2] + 88) / 185
img_b_scale = (img_lab[:, :, 2:3] + 127) / 212
img_ab_scale = np.concatenate((img_a_scale, img_b_scale), axis=2)
labels[k] = torch.from_numpy(img_ab_scale.transpose((2, 0, 1)))
return input, labels
示例12: write_image
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2lab [as 别名]
def write_image(self, img_file, image, img_embedding):
img = transform.resize(image, img_shape, mode="constant")
lab = color.rgb2lab(img).astype(np.float32)
l_channel = 2 * lab[:, :, 0] / 100 - 1
ab_channels = lab[:, :, 1:] / 127
example = tf.train.Example(
features=tf.train.Features(
feature={
"image_name": self._bytes_feature(img_file),
"image_l": self._float32_list(l_channel.flatten()),
"image_ab": self._float32_list(ab_channels.flatten()),
"image_embedding": self._float32_list(img_embedding.flatten()),
}
)
)
self.write(example.SerializeToString())
示例13: format_image
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2lab [as 别名]
def format_image(img_path, size):
"""
Load img with opencv and reshape
"""
img_color = cv2.imread(img_path)
img_color = img_color[:, :, ::-1]
img_black = cv2.imread(img_path, 0)
img_color = cv2.resize(img_color, (size, size), interpolation=cv2.INTER_AREA)
img_black = cv2.resize(img_black, (size, size), interpolation=cv2.INTER_AREA)
img_lab = color.rgb2lab(img_color)
img_lab = img_lab.reshape((1, size, size, 3)).transpose(0, 3, 1, 2)
img_color = img_color.reshape((1, size, size, 3)).transpose(0, 3, 1, 2)
img_black = img_black.reshape((1, size, size, 1)).transpose(0, 3, 1, 2)
return img_color, img_lab, img_black
示例14: intensity_entropy
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2lab [as 别名]
def intensity_entropy(inp):
img = color.rgb2lab(inp)
l_bins = 20
L = []
img = img.reshape(-1, 3)
img = [tuple(l) for l in img]
for pixel in img:
L.append(pixel[0])
p, x = np.histogram(L, bins=l_bins, range=(0, 100), normed=True)
p.ravel()
p = p * 100.
p = p + 0.000000000001
p_log = [math.log(y) for y in p]
p_result = p * p_log
result = np.sum(p_result)
return result
# The uncertainty of colour in a leaf, given the leaf. Based on the shannon entropy
示例15: execute
# 需要导入模块: from skimage import color [as 别名]
# 或者: from skimage.color import rgb2lab [as 别名]
def execute(b64):
b64 = base64.b64decode(b64)
b64 = BytesIO(b64)
img = Image.open(b64)
img= np.array(img)
img = util.img_as_ubyte(img)
# Convert the LAB space
lab = color.rgb2lab(img)
L = lab[:, :, 0]
A = lab[:, :, 1]
B = lab[:, :, 2]
# Get average and standard deviation for each value separately
meanL = np.mean(L)
stdL = np.std(L)
meanA = np.mean(A)
stdA = np.std(A)
meanB = np.mean(B)
stdB = np.std(B)
result = [meanL, stdL, meanA, stdA, meanB, stdB]
return result