python - 如何将图像从 RGB 域转换为 YST 域?
问题描述
我是 YST 域的新手。我想将 RGB 32x32 像素图像转换为相同大小的 YST 颜色域。在阅读了一些研究论文后,我得到了转换公式,但不知道如何使用 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
推荐阅读
- wordpress - 使用 Docker Desktop + WSL2 安装后无法完成 wordpress 设置
- html - 无法使用标签选择器更改 CSS 中的元素属性
- kubernetes - 如何在 bash 中为 mike yq v4 处理变量
- flutter - Google Drive API:使用 http 请求上传和创建文件夹,例如在 DIO 中使用 Flutter
- api - HashiCorp 通过 Vault 的 API 进行更新插入
- ethereum - 使用 web3js 和 galanche 调用具有价值的以太坊智能合约
- jira - 如何在 JIRA REST API 中为不同的用户(不同的域/实例 url)生成访问令牌?
- php - 事件侦听器不适用于捆绑 FMElfinder
- python - 如何配置 mod_wsgi + apache2 以使用 Flask + SocketIO?
- python - 使用非结构化数据的 href 链接抓取表格