首页 > 解决方案 > 如何将图像从 RGB 域转换为 YST 域?

问题描述

我是 YST 域的新手。我想将 RGB 32x32 像素图像转换为相同大小的 YST 颜色域。在阅读了一些研究论文后,我得到了转换公式,但不知道如何使用 python 进行转换。

我已经提到了公式。

标签: python

解决方案


您可以将转换定义为矩阵并使用矩阵乘法将其相乘:

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

推荐阅读