python画24色卡图及对比图,sRGB反gamma操作得到线性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)

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=' ')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值