如何将图像从RGB域转换到YST域?

2024-10-06 12:36:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我是YST领域的新手。我想把一个rgb32x32像素的图像转换成同样大小的YST颜色域。 在阅读了一些研究论文后,我得到了转换公式,但不知道如何使用python进行转换。

I have mentioned the formula.


Tags: 图像颜色像素领域公式新手ystrgb32x32
2条回答

您可以将转换定义为矩阵,并使用矩阵乘法进行乘法:

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)

编辑:

要转换完整图像,必须执行以下操作:

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

使用numpy可以

  • 构建矩阵.array()
  • 把它乘以一个向量.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)

相关问题 更多 >