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


Python cv2.COLOR_RGB2Lab方法代码示例

本文整理汇总了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) 
开发者ID:youdao-ai,项目名称:SRNet-Datagen,代码行数:26,代码来源:colorize.py

示例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 
开发者ID:luigifreda,项目名称:pyslam,代码行数:10,代码来源:utils_img.py

示例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 
开发者ID:youdao-ai,项目名称:SRNet-Datagen,代码行数:10,代码来源:colorize.py

示例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 
开发者ID:opencv,项目名称:open_model_zoo,代码行数:8,代码来源:colorization_evaluator.py

示例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) 
开发者ID:aleju,项目名称:imgaug,代码行数:60,代码来源:test_color.py


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