本文整理匯總了Python中cv2.COLOR_RGB2Lab方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.COLOR_RGB2Lab方法的具體用法?Python cv2.COLOR_RGB2Lab怎麽用?Python cv2.COLOR_RGB2Lab使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cv2
的用法示例。
在下文中一共展示了cv2.COLOR_RGB2Lab方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: sample_from_data
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2Lab [as 別名]
def sample_from_data(self, bg_mat):
bg_orig = bg_mat.copy()
bg_mat = cv2.cvtColor(bg_mat, cv2.COLOR_RGB2Lab)
bg_mat = np.reshape(bg_mat, (np.prod(bg_mat.shape[:2]),3))
bg_mean = np.mean(bg_mat, axis = 0)
norms = np.linalg.norm(self.colorsLAB - bg_mean[None,:], axis = 1)
# choose a random color amongst the top 3 closest matches:
#nn = np.random.choice(np.argsort(norms)[:3])
nn = np.argmin(norms)
## nearest neighbour color:
data_col = self.colorsRGB[np.mod(nn, self.ncol),:]
# color
col1 = self.sample_normal(data_col[:3],data_col[3:6])
col2 = self.sample_normal(data_col[6:9],data_col[9:12])
if nn < self.ncol:
return (col2, col1)
else:
# need to swap to make the second color close to the input backgroun color
return (col1, col2)
示例2: proc_clahe
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2Lab [as 別名]
def proc_clahe(img):
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
lab = cv2.cvtColor(img, cv2.COLOR_RGB2Lab)
lab[:, :, 0] = clahe.apply(lab[:, :, 0])
return cv2.cvtColor(lab, cv2.COLOR_Lab2RGB)
# create a scaled image of uint8 from a image of floats
示例3: get_color_matrix
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2Lab [as 別名]
def get_color_matrix(col_file):
with open(col_file,'rb') as f:
colorsRGB = cp.load(f, encoding ='latin1')
ncol = colorsRGB.shape[0]
colorsLAB = np.r_[colorsRGB[:,0:3], colorsRGB[:,6:9]].astype(np.uint8)
colorsLAB = np.squeeze(cv2.cvtColor(colorsLAB[None,:,:], cv2.COLOR_RGB2Lab))
return colorsRGB, colorsLAB
示例4: data_preparation
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2Lab [as 別名]
def data_preparation(self, input_data):
input = input_data[0].astype(np.float32)
img_lab = cv2.cvtColor(input, cv2.COLOR_RGB2Lab)
img_l = np.copy(img_lab[:, :, 0])
img_l_rs = np.copy(img_lab[:, :, 0])
return img_l, img_l_rs
示例5: test_every_colorspace
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_RGB2Lab [as 別名]
def test_every_colorspace(self):
def _image_to_channel(image, cspace):
if cspace == iaa.CSPACE_YCrCb:
image_cvt = cv2.cvtColor(image, cv2.COLOR_RGB2YCR_CB)
return image_cvt[:, :, 0:0+1]
elif cspace == iaa.CSPACE_HSV:
image_cvt = cv2.cvtColor(image, cv2.COLOR_RGB2HSV)
return image_cvt[:, :, 2:2+1]
elif cspace == iaa.CSPACE_HLS:
image_cvt = cv2.cvtColor(image, cv2.COLOR_RGB2HLS)
return image_cvt[:, :, 1:1+1]
elif cspace == iaa.CSPACE_Lab:
if hasattr(cv2, "COLOR_RGB2Lab"):
image_cvt = cv2.cvtColor(image, cv2.COLOR_RGB2Lab)
else:
image_cvt = cv2.cvtColor(image, cv2.COLOR_RGB2LAB)
return image_cvt[:, :, 0:0+1]
elif cspace == iaa.CSPACE_Luv:
if hasattr(cv2, "COLOR_RGB2Luv"):
image_cvt = cv2.cvtColor(image, cv2.COLOR_RGB2Luv)
else:
image_cvt = cv2.cvtColor(image, cv2.COLOR_RGB2LUV)
return image_cvt[:, :, 0:0+1]
else:
assert cspace == iaa.CSPACE_YUV
image_cvt = cv2.cvtColor(image, cv2.COLOR_RGB2YUV)
return image_cvt[:, :, 0:0+1]
# Max differences between input image and image after augmentation
# when no child augmenter is used (for the given example image below).
# For some colorspaces the conversion to input colorspace isn't
# perfect.
# Values were manually checked.
max_diff_expected = {
iaa.CSPACE_YCrCb: 1,
iaa.CSPACE_HSV: 0,
iaa.CSPACE_HLS: 0,
iaa.CSPACE_Lab: 2,
iaa.CSPACE_Luv: 4,
iaa.CSPACE_YUV: 1
}
image = np.arange(6*6*3).astype(np.uint8).reshape((6, 6, 3))
for cspace in self.valid_colorspaces:
with self.subTest(colorspace=cspace):
child = _BatchCapturingDummyAugmenter()
aug = iaa.WithBrightnessChannels(
children=child,
to_colorspace=cspace)
image_aug = aug(image=image)
expected = _image_to_channel(image, cspace)
diff = np.abs(
image.astype(np.int32) - image_aug.astype(np.int32))
assert np.all(diff <= max_diff_expected[cspace])
assert np.array_equal(child.last_batch.images[0], expected)