当前位置:   article > 正文

python画24色卡图及对比图,sRGB反gamma操作得到线性RGB数值(附代码)_24色摄影色卡 rgb

24色摄影色卡 rgb

1.已知24色卡的RGB数据,画出对应的图像

比如两组RGB数据
list1 = [[115, 82, 69], [204, 161, 141], [101, 134, 179], [89, 109, 61], [141, 137, 194],
[132, 228, 208], [249, 118, 35], [80, 91, 182], [222, 91, 125], [91, 63, 123], [173, 232, 91],
[255, 164, 26], [44, 56, 142], [74, 148, 81], [179, 42, 50], [250, 226, 21], [191, 81, 160],
[6, 142, 172], [252, 252, 252], [230, 230, 230], [200, 200, 200], [143, 143, 142], [100, 100, 100],
[50, 50, 50]]

list2 = [[114, 81, 67], [195, 148, 128], [93, 122, 156], [91, 108, 64], [129, 128, 176], [97, 191, 171],
[221, 123, 48], [71, 91, 170], [193, 82, 97], [92, 57, 106], [160, 189, 62], [228, 161, 41],
[40, 63, 147], [71, 150, 73], [174, 51, 57], [237, 198, 20], [188, 84, 151], [0, 138, 168],
[245, 245, 245], [202, 202, 202], [161, 163, 163], [121, 121, 121], [84, 84, 84], [49, 49, 49]]
得到的对比图像如下:
在这里插入图片描述

import numpy as np
import matplotlib.pyplot as plt
import skimage.io as io

list1 = [[115, 82, 69], [204, 161, 141], [101, 134, 179], [89, 109, 61], [141, 137, 194],
         [132, 228, 208], [249, 118, 35], [80, 91, 182], [222, 91, 125], [91, 63, 123], [173, 232, 91],
         [255, 164, 26], [44, 56, 142], [74, 148, 81], [179, 42, 50], [250, 226, 21], [191, 81, 160],
         [6, 142, 172], [252, 252, 252], [230, 230, 230], [200, 200, 200], [143, 143, 142], [100, 100, 100],
         [50, 50, 50]]

list2 = [[114, 81, 67], [195, 148, 128], [93, 122, 156], [91, 108, 64], [129, 128, 176], [97, 191, 171],
         [221, 123, 48], [71, 91, 170], [193, 82, 97], [92, 57, 106], [160, 189, 62], [228, 161, 41],
         [40, 63, 147], [71, 150, 73], [174, 51, 57], [237, 198, 20], [188, 84, 151], [0, 138, 168],
         [245, 245, 245], [202, 202, 202], [161, 163, 163], [121, 121, 121], [84, 84, 84], [49, 49, 49]]
b1 = np.array(list1)
b2 = np.array(list2)

patch_len = 150
margin_len = 20
step_len = patch_len + margin_len
t1 = 40
image = np.zeros((4 * patch_len + 5 * margin_len, 6 * patch_len + 7 * margin_len, 3))

for i in range(4):
    for j in range(6):
        image[margin_len + i * step_len: margin_len + i * step_len + patch_len, margin_len + j * step_len:margin_len + j * step_len + patch_len, :] = b1[i * 6 + j, :]
        image[margin_len + i * step_len + t1: margin_len + i * step_len + patch_len-t1, margin_len + j * step_len+t1:margin_len + j * step_len + patch_len-t1, :] = b2[i * 6 + j, :]

image = image.astype(np.uint8)
plt.imshow(image)
plt.axis("off")
io.imsave('24colorpatch.jpg', image)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

https: // blog.csdn.net / Jingnian_destiny / article / details / 108643586

2.sRGB反gamma操作得到线性RGB数值

通过colour.cctf_decoding 默认执行sRGB向linearRGB的转换(degamma)
当然也可以设置为其他色域的转换

import colour
import numpy as np
srgb = np.array([115,82,68,
194,150,130,
98,122,157,
87,108,67,
133,128,177,
103,189,170,
214,126,44,
80,91,166,
193,90,99,
94,60,108,
157,188,64,
224,163,46,
56,61,150,
70,148,73,
175,54,60,
231,199,31,
187,86,149,
8,133,161,
243,243,242,
200,200,200,
160,160,160,
122,122,121,
85,85,85,
52,52,52])


print(srgb/255)
srgb_linear = colour.cctf_decoding(srgb/255)

srgb_linear = srgb_linear*255
srgb_linear = srgb_linear.reshape(24, 3)
print(srgb_linear)
filename = r'D:\srgb_linear.txt'
np.savetxt(filename, srgb_linear, fmt='%.3f',delimiter=' ')
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码吟游诗人/article/detail/60408?site
推荐阅读
相关标签
  

闽ICP备14008679号