问题描述
我在查找以下使用 imatest 绘制的图的背景时遇到了一些麻烦。基本上我想知道的是我如何或从哪里找到这个情节的背景。 imatest 网站提到图表的颜色是在恒定亮度 L* = 90
和变化 a* and b* from -80 to +80
下生成的。我一直在寻找 Lab 颜色生成器,但所有软件都会生成彩色点。但我想通过改变 a 和 b 值来获得连续图像。有什么想法吗?
解决方法
使用 matlab
,您可以简单地将 cielab 空间转换为 RGB 空间:
range = -80:0.5:80; % a,b range,change the step to change the size of the output image.
L = 100*ones(size(range,2),size(range,2)); % L intensity
[b,a] = meshgrid(range); % generate a 2D grid
Lab = cat(3,L,a,b); % create the 3D Lab array
I = lab2rgb(rot90(Lab)); % Lab -> RGB
imshow(I) % Display the result
我们得到:
,只是为了好玩,如果有人想要一个 Python OpenCV 版本,我做了一个这样的:
#!/usr/bin/env python3
import cv2
import numpy as np
# Set size of output image
h,w = 500,500
# Create "L" channel,L=90
L = np.full((h,w),90.00,np.float32)
# Create "a" channel,-80 to +80
a = np.linspace(-80,80,w,endpoint=True,dtype=np.float32)
a = np.resize(a,(h,w))
# Create "b" channel by rotating "a" channel 90 degrees
b = cv2.rotate(a,cv2.ROTATE_90_COUNTERCLOCKWISE)
# Stack the 3-channels into single image and convert from Lab to BGR
res = np.dstack((L,b))
res = cv2.cvtColor(res,cv2.COLOR_LAB2BGR)
# Save result
cv2.imwrite('result.png',(res*65535).astype(np.uint16))