[英]How to convert an image from RGB domain to YST domain?
I am a newbie to the YST domain area.我是 YST 域的新手。 I want to convert an RGB 32x32 pixel image into the YST color domain of the same size.
我想将 RGB 32x32 像素图像转换为相同大小的 YST 颜色域。 After reading some research papers I got the formula for conversion but not sure how to go about it using python.
在阅读了一些研究论文后,我得到了转换公式,但不知道如何使用 python 来转换 go。
You can define the conversion as a matrix and multiply it using matrix multiplication:您可以将转换定义为矩阵并使用矩阵乘法将其相乘:
import numpy as np
x = [[0.299, 0.587, 0.114],[0.147, -0.289, 0.436],[0.615, -0.515, -0.1]]
rgb = [1,2,3]
x = np.matrix(x)
yst = x.dot(rgb)
EDIT:编辑:
To convert your complete image you would have to do:要转换您的完整图像,您必须执行以下操作:
test_img=np.ones((32,32,3))
x = [[0.299, 0.587, 0.114],[0.147, -0.289, 0.436],[0.615, -0.515, -0.1]]
x = np.array(x)
yst_img = []
for i in range(len(test_img)):
yst_img.append([])
for rgb in test_img[i]:
yst_img[i].append(x.dot(rgb))
yst_img = np.array(yst_img) #in case you want your data as an array
Using numpy
you can使用
numpy
你可以
.array()
.array()
.dot(vector)
.dot(vector)
import numpy as np
x = [[0.299, 0.587, 0.114],[0.147, -0.289, 0.436],[0.615, -0.515, -0.1]]
x = np.array(x)
rgb = [155, 23, 49]
yst = x.dot(rgb)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.