本文整理汇总了Python中cv2.COLOR_BGR2LAB属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.COLOR_BGR2LAB属性的具体用法?Python cv2.COLOR_BGR2LAB怎么用?Python cv2.COLOR_BGR2LAB使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cv2
的用法示例。
在下文中一共展示了cv2.COLOR_BGR2LAB属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_to_original_colors
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2LAB [as 别名]
def convert_to_original_colors(content_img, stylized_img):
content_img = postprocess(content_img)
stylized_img = postprocess(stylized_img)
if args.color_convert_type == 'yuv':
cvt_type = cv2.COLOR_BGR2YUV
inv_cvt_type = cv2.COLOR_YUV2BGR
elif args.color_convert_type == 'ycrcb':
cvt_type = cv2.COLOR_BGR2YCR_CB
inv_cvt_type = cv2.COLOR_YCR_CB2BGR
elif args.color_convert_type == 'luv':
cvt_type = cv2.COLOR_BGR2LUV
inv_cvt_type = cv2.COLOR_LUV2BGR
elif args.color_convert_type == 'lab':
cvt_type = cv2.COLOR_BGR2LAB
inv_cvt_type = cv2.COLOR_LAB2BGR
content_cvt = cv2.cvtColor(content_img, cvt_type)
stylized_cvt = cv2.cvtColor(stylized_img, cvt_type)
c1, _, _ = cv2.split(stylized_cvt)
_, c2, c3 = cv2.split(content_cvt)
merged = cv2.merge((c1, c2, c3))
dst = cv2.cvtColor(merged, inv_cvt_type).astype(np.float32)
dst = preprocess(dst)
return dst
示例2: renderEnvLuminosityNoise
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2LAB [as 别名]
def renderEnvLuminosityNoise(self, origin_image, noise_var=0.1, in_RGB=False, out_RGB=False):
"""
render the different environment luminosity
"""
# variate luminosity and color
origin_image_LAB = cv2.cvtColor(
origin_image, cv2.COLOR_RGB2LAB if in_RGB else cv2.COLOR_BGR2LAB, cv2.CV_32F)
origin_image_LAB[:, :, 0] = origin_image_LAB[:,
:, 0] * (np.random.randn() * noise_var + 1.0)
origin_image_LAB[:, :, 1] = origin_image_LAB[:,
:, 1] * (np.random.randn() * noise_var + 1.0)
origin_image_LAB[:, :, 2] = origin_image_LAB[:,
:, 2] * (np.random.randn() * noise_var + 1.0)
out_image = cv2.cvtColor(
origin_image_LAB, cv2.COLOR_LAB2RGB if out_RGB else cv2.COLOR_LAB2BGR, cv2.CV_8UC3)
return out_image
示例3: equalize_light
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2LAB [as 别名]
def equalize_light(image, limit=3, grid=(7,7), gray=False):
if (len(image.shape) == 2):
image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR)
gray = True
clahe = cv2.createCLAHE(clipLimit=limit, tileGridSize=grid)
lab = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)
l, a, b = cv2.split(lab)
cl = clahe.apply(l)
limg = cv2.merge((cl,a,b))
image = cv2.cvtColor(limg, cv2.COLOR_LAB2BGR)
if gray:
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
return np.uint8(image)
示例4: histogram_equalization
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2LAB [as 别名]
def histogram_equalization(img):
lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
# -----Splitting the LAB image to different channels-------------------------
l, a, b = cv2.split(lab)
# -----Applying CLAHE to L-channel-------------------------------------------
clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(8, 8))
cl = clahe.apply(l)
# -----Merge the CLAHE enhanced L-channel with the a and b channel-----------
limg = cv2.merge((cl, a, b))
# -----Converting image from LAB Color model to RGB model--------------------
final = cv2.cvtColor(limg, cv2.COLOR_LAB2BGR)
return final
示例5: showImageLab
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2LAB [as 别名]
def showImageLab(image_file):
image_bgr = cv2.imread(image_file)
image_Lab = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2LAB)
L = image_Lab[:, :, 0]
a = image_Lab[:, :, 1]
b = image_Lab[:, :, 2]
plt.subplot(1, 3, 1)
plt.title('L')
plt.gray()
plt.imshow(L)
plt.axis('off')
plt.subplot(1, 3, 2)
plt.title('a')
plt.gray()
plt.imshow(a)
plt.axis('off')
plt.subplot(1, 3, 3)
plt.title('b')
plt.gray()
plt.imshow(b)
plt.axis('off')
plt.show()
示例6: transfer_avg_color
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2LAB [as 别名]
def transfer_avg_color(img_old,img_new):
assert(img_old.shape==img_new.shape)
source = cv2.cvtColor(img_old, cv2.COLOR_BGR2LAB).astype("float32")
target = cv2.cvtColor(img_new, cv2.COLOR_BGR2LAB).astype("float32")
(lMeanSrc, lStdSrc, aMeanSrc, aStdSrc, bMeanSrc, bStdSrc) = image_stats(source)
(lMeanTar, lStdTar, aMeanTar, aStdTar, bMeanTar, bStdTar) = image_stats(target)
(l, a, b) = cv2.split(target)
l -= lMeanTar
a -= aMeanTar
b -= bMeanTar
l = (lStdTar / lStdSrc) * l
a = (aStdTar / aStdSrc) * a
b = (bStdTar / bStdSrc) * b
l += lMeanSrc
a += aMeanSrc
b += bMeanSrc
l = numpy.clip(l, 0, 255)
a = numpy.clip(a, 0, 255)
b = numpy.clip(b, 0, 255)
transfer = cv2.merge([l, a, b])
transfer = cv2.cvtColor(transfer.astype("uint8"), cv2.COLOR_LAB2BGR)
return transfer
示例7: lightness
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2LAB [as 别名]
def lightness(img, amount=0.25):
try:
# Only works with BGR images
lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
lab[:, :, 0] *= RANDOM.uniform(1 - amount, 1 + amount)
lab[:, :, 0].clip(0, 255)
img = cv2.cvtColor(lab, cv2.COLOR_LAB2BGR)
except:
pass
return img
示例8: light_removing
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2LAB [as 别名]
def light_removing(frame) :
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
lab = cv2.cvtColor(frame, cv2.COLOR_BGR2LAB)
L = lab[:,:,0]
med_L = cv2.medianBlur(L,99) #median filter
invert_L = cv2.bitwise_not(med_L) #invert lightness
composed = cv2.addWeighted(gray, 0.75, invert_L, 0.25, 0)
return L, composed
示例9: correct_lightness
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2LAB [as 别名]
def correct_lightness(img: np.ndarray):
if len(np.shape(img)) == 3:
img_lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
l, a, b = cv2.split(img_lab)
clahe = cv2.createCLAHE(clipLimit=40.0, tileGridSize=(4, 4))
l = clahe.apply(l)
img = cv2.merge((l, a, b))
img = cv2.cvtColor(img, cv2.COLOR_LAB2BGR)
return img
示例10: bgr_to_lab
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2LAB [as 别名]
def bgr_to_lab(img):
lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(17, 17))
lab = clahe.apply(lab[:, :, 0])
if lab.mean() > 127:
lab = 255 - lab
return lab[..., np.newaxis]
示例11: rgb2gray_lab
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2LAB [as 别名]
def rgb2gray_lab(rgb_img, channel):
"""Convert image from RGB colorspace to LAB colorspace. Returns the specified subchannel as a gray image.
Inputs:
rgb_img = RGB image data
channel = color subchannel (l = lightness, a = green-magenta, b = blue-yellow)
Returns:
l | a | b = grayscale image from one LAB color channel
:param rgb_img: numpy.ndarray
:param channel: str
:return channel: numpy.ndarray
"""
# Auto-increment the device counter
params.device += 1
# The allowable channel inputs are l, a or b
names = {"l": "lightness", "a": "green-magenta", "b": "blue-yellow"}
channel = channel.lower()
if channel not in names:
fatal_error("Channel " + str(channel) + " is not l, a or b!")
# Convert the input BGR image to LAB colorspace
lab = cv2.cvtColor(rgb_img, cv2.COLOR_BGR2LAB)
# Split LAB channels
l, a, b = cv2.split(lab)
# Create a channel dictionaries for lookups by a channel name index
channels = {"l": l, "a": a, "b": b}
if params.debug == "print":
print_image(channels[channel], os.path.join(params.debug_outdir,
str(params.device) + "_lab_" + names[channel] + ".png"))
elif params.debug == "plot":
plot_image(channels[channel], cmap="gray")
return channels[channel]
示例12: light
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2LAB [as 别名]
def light(im1_name, im2_name):
# im1
im = cv2.imread(im1_name)
im = im.astype(np.float32)
im /= 255.
im_lab = cv2.cvtColor(im, cv2.COLOR_BGR2LAB)
l = im_lab[:, :, 0]
L1_mean = np.mean(l)
L1_std = np.std(l)
# im2
im = cv2.imread(im2_name)
im = im.astype(np.float32)
im /= 255.
im_lab = cv2.cvtColor(im, cv2.COLOR_BGR2LAB)
l = im_lab[:, :, 0]
L2_mean = np.mean(l)
L2_std = np.std(l)
if L2_std != 0:
l = (l - L2_mean) / L2_std * L1_std + L1_mean
l = l[:, :, np.newaxis]
im_lab = np.concatenate((l, im_lab[:, :, 1:]), axis=2)
im = cv2.cvtColor(im_lab, cv2.COLOR_LAB2BGR)
im *= 255.
return im
示例13: increase_contrast
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2LAB [as 别名]
def increase_contrast(img):
"""
Increase contrast of an RGB image
@Author: Appcell
@param img: image to be processed
@return: a numpy.ndarray object of this image
"""
lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
l, a, b = cv2.split(lab)
clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(4, 4))
cl = clahe.apply(l)
limg = cv2.merge((cl,a,b))
final = cv2.cvtColor(limg, cv2.COLOR_LAB2BGR)
return final
示例14: color_transfer_mix
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2LAB [as 别名]
def color_transfer_mix(img_src,img_trg):
img_src = np.clip(img_src*255.0, 0, 255).astype(np.uint8)
img_trg = np.clip(img_trg*255.0, 0, 255).astype(np.uint8)
img_src_lab = cv2.cvtColor(img_src, cv2.COLOR_BGR2LAB)
img_trg_lab = cv2.cvtColor(img_trg, cv2.COLOR_BGR2LAB)
rct_light = np.clip ( linear_color_transfer(img_src_lab[...,0:1].astype(np.float32)/255.0,
img_trg_lab[...,0:1].astype(np.float32)/255.0 )[...,0]*255.0,
0, 255).astype(np.uint8)
img_src_lab[...,0] = (np.ones_like (rct_light)*100).astype(np.uint8)
img_src_lab = cv2.cvtColor(img_src_lab, cv2.COLOR_LAB2BGR)
img_trg_lab[...,0] = (np.ones_like (rct_light)*100).astype(np.uint8)
img_trg_lab = cv2.cvtColor(img_trg_lab, cv2.COLOR_LAB2BGR)
img_rct = color_transfer_sot( img_src_lab.astype(np.float32), img_trg_lab.astype(np.float32) )
img_rct = np.clip(img_rct, 0, 255).astype(np.uint8)
img_rct = cv2.cvtColor(img_rct, cv2.COLOR_BGR2LAB)
img_rct[...,0] = rct_light
img_rct = cv2.cvtColor(img_rct, cv2.COLOR_LAB2BGR)
return (img_rct / 255.0).astype(np.float32)
示例15: upsample_color_image
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGR2LAB [as 别名]
def upsample_color_image(grayscale_highres, color_lowres_bgr, colorspace='LAB'):
"""
Generate a high res color image from a high res grayscale image, and a low res color image,
using the trick described in:
http://www.planetary.org/blogs/emily-lakdawalla/2013/04231204-image-processing-colorizing-images.html
"""
assert(len(grayscale_highres.shape) == 2)
assert(len(color_lowres_bgr.shape) == 3 and color_lowres_bgr.shape[2] == 3)
if colorspace == 'LAB':
# convert color image to LAB space
lab = cv2.cvtColor(src=color_lowres_bgr, code=cv2.COLOR_BGR2LAB)
# replace lightness channel with the highres image
lab[:, :, 0] = grayscale_highres
# convert back to BGR
color_highres_bgr = cv2.cvtColor(src=lab, code=cv2.COLOR_LAB2BGR)
elif colorspace == 'HSV':
# convert color image to HSV space
hsv = cv2.cvtColor(src=color_lowres_bgr, code=cv2.COLOR_BGR2HSV)
# replace value channel with the highres image
hsv[:, :, 2] = grayscale_highres
# convert back to BGR
color_highres_bgr = cv2.cvtColor(src=hsv, code=cv2.COLOR_HSV2BGR)
elif colorspace == 'HLS':
# convert color image to HLS space
hls = cv2.cvtColor(src=color_lowres_bgr, code=cv2.COLOR_BGR2HLS)
# replace lightness channel with the highres image
hls[:, :, 1] = grayscale_highres
# convert back to BGR
color_highres_bgr = cv2.cvtColor(src=hls, code=cv2.COLOR_HLS2BGR)
return color_highres_bgr