def myrgb2lab(I: np.ndarray, row_num: int, col_num: int):
"""
change rgb to lab format
:param I: rgb format image
:return:
L: L channel, range from 0 to 255, dtype: uint8, shape: (row_num * col_num,)
a: a channel, range from 0 to 255, dtype: uint8, shape: (row_num * col_num,)
b: b channel, range from 0 to 255, dtype: uint8, shape: (row_num * col_num,)
"""
lab_img = color.rgb2lab(I).transpose([2, 1, 0])
L = lab_img[0].copy().reshape([row_num * col_num])
a = lab_img[1].copy().reshape([row_num * col_num])
b = lab_img[2].copy().reshape([row_num * col_num])
L /= (100 / 255) # L is [0, 100], change it to [0, 255]
L += 0.5
a += 128 + 0.5 # A is [-128, 127], change it to [0, 255]
b += 128 + 0.5 # B is [-128, 127], change it to [0, 255]
return L.astype(np.uint8), a.astype(np.uint8), b.astype(np.uint8)
myrgb2lab.py 文件源码
python
阅读 15
收藏 0
点赞 0
评论 0
评论列表
文章目录