RGB和CIECAM02颜色空间之间的简单快速转换。
ciecam02的Python项目详细描述
CIECAM02
RGB和CIECAM02颜色空间之间的简单快速转换。
在rgb和名为的ciecam02模型的简化形式之间转换颜色 jch,以快速算法封装在numpy数组中,用于 执行图像、显示等算法。
介绍
^ a2}近似线性化 蒙塞尔色彩系统。
彩色rgb可以广泛应用于显示设备和图像格式。这个 数据格式是一个整数列表[r,g,b],其中r g b在0-255之间。
ciecam02产生多个相关,如h、j、z、q、t、c、m、s。 它们代表相似的概念,例如c表示色度和m表示色度。 在不同的密度下,S饱和度与同一事物相关。我们只需要3个 这些参数的主要性质是完全代表一种颜色,我们 可以获得其他属性或反向算法。
颜色类型j c h是一个浮动列表,如[j,c,h],其中0.0<;j<;100.0, 0.0<;H<;360.0和0.0<;C。C的最大值不受限制,并且可能 转换为RGB时产生超出。最大c的有效值是变化的。 对于红色H 0.0,亮度J 50.0,C可能达到有效值 最大值约为160。
jch来自ciecam02模型输出的浮点列表 [J,C,H],为了得到适当的比例,进行了一些扭曲。
j值与j相同,即亮度。
c值与c相同,即色度。
h将原始h从0-400压缩到0-360,只需*0.9 以极坐标表示的。
视觉环境变量
在CIECAM02模型中考虑了影响,并进行了一些测量 构建。我们只是把它们当作常数。
whitepoint = [95.05, 100.00, 108.88],
env = [1.0, 0.69, 1.0],
lightindensity = 80
bgindensity = 16
您可以config这些值来模拟不同的环境。
实施
实现依赖于numpy,它在 转变。一次将大图像数据作为数组处理。
安装
pip install ciecam02
用法
基本功能:
import numpy as np
from ciecam02 import rgb2jch, jch2rgb
rgb = np.array([[56, 34, 199],
[255, 255, 255]
])
rgb2jch(rgb)
Out[]: array([[ 21.4432157, 74.80048318, 284.3167947 ],
[ 99.99968129, 1.49090566, 242.41103965]])
jch2rgb(rgb2jch(rgb))
Out[]:
array([[ 56, 34, 199],
[255, 255, 255]], dtype=uint8)
对于图像分析,将图像rgb数据转换为np。将平坦的数组转换为2d数组, 然后应用转换:
import numpy as np
from ciecam02 import rgb2jch, jch2rgb
from PIL import Image
im = Image.open("image.png")
rgb = np.array(im)
shape = rgb.shape
jch = rgb2jch(rgb.reshape(-1, 3))
# do the work.
# ...
# reverse back to a new image
rgb = jch2rgb(jch).reshape(shape)
im = Image.fromarray(rgb)
im.show()
执行反向转换时,rgb值可能会超过。jch2rgb
控制
阈值为255的值。如果你想看看那些被淘汰的人
对于范围,请使用以下功能:
import numpy as np
from ciecam02 import jch2xyz, xyz2infinitergb
...
xyz = jch2xyz(jch)
inf_rgb = xyz2infinitergb(rgb)
# then select the exceeded values for your purpose.
功能
这些过程依赖于xyz颜色空间的中间表示。 正向和反向变换首先到达xyz,然后进行变换 到目标空间。
rgb2xyz(rgb):
returns an xyz 2d array astype
float
shapes [[x, y, z], ...].xyz2rgb(xyz):
returns an rgb array astype
uint8
. coud convert to Image object byImage.fromarray(rgb)
xyz2infinitergb(xyz):
returns an rgb array with exceeded values in a
float
astype. if you want transform to an image object, you should convert to auint8
first.xyz2cam02(xyz):
returns the full property of features that cam02 solves, with data undistorted. [[h, H, J, Q, C, M, s],...]
rgb2jch(颜色):
returns a jch array. It is a compound of 'xyz2cam02(rgb2xyz)', then select J, C, H compressed out in a
float
type.jch2xyz(jch):
returns an xyz array in a
float
type.jch2rgb(jch):
returns rgb array astype
uint8
. Compounds ofxyz2rgb(jch2xyz(jch))
.
配置
预定义值如下:
whitepoint = {'white': [95.05, 100.00, 108.88],
'c': [109.85, 100.0, 35.58]}
env = {'dim': [0.9, 0.59, 0.9],
'average': [1.0, 0.69, 1.0],
'dark': [0.8, 0.525, 0.8]}
lightindensity = {'default': 80.0, 'high': 318.31, 'low': 31.83}
bgindensity = {'default': 16.0, 'high': 20.0, 'low': 10.0}
你可以通过set_config(whitepoint, env, light, bg)
来配置它们,
从每个常量中的dict键:
from ciecam02 import set_config
set_config('c', 'dim', 'low', 'high')
或者您可以直接更改全局常数,它们是这样预定义的:
currentwhite = whitepoint['white']
currentenv = env['average']
currentlight = lightindensity['default']
currentbg = bgindensity['default']
为自定义预设进行修改:
currentwhite = [101.0, 100.0, 95]
currentenv = [0.96, 0.59, 0.99]
currentlight = 200.0
currentbg = 18.0
模型外观
请看与Moncell和Cam02的一些区别。
比较
CIECAM02:
蒙塞尔:
CIECAM02:
蒙塞尔:
尺寸
李森斯
麻省理工学院。