RawPy对象中的颜色矩阵是什么?

2024-06-26 12:34:09 发布

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

我正在阅读一幅大小为3120 x 4208的DNG图像

dng = rawpy.imread("TestImages/IMG_20200108_161323.dng")

调试时,我看到dng有一个名为color_matrix的字段-一个形状为3x4的numpy数组,它看起来像:

[[ 0.24399559  0.57969594  0.1763085   0.        ]
 [-0.00469256  0.96858126  0.03611127  0.        ]
 [-0.00366105 -0.06751718  1.0711782   0.        ]]

。根据RawPy document

Color matrix, read from file for some cameras, calculated for others. Return type: ndarray of shape (3,4)

搜索之后,我仍然不了解那个领域。你能给我解释一下吗?谢谢你的阅读


Tags: 图像numpyimgfor数组documentmatrixcolor
1条回答
网友
1楼 · 发布于 2024-06-26 12:34:09

颜色矩阵如下所示:

A B C D
E F G H
I J K L

通常意味着您根据旧红色(Ro)、旧绿色(Go)和旧蓝色(Bo)计算新红色值(Rn)、新绿色值(Gn)和新蓝色值(Bn),如下所示:

Rn = A*Ro + B*Go + C*Bo + D
Gn = E*Ro + F*Go + G*Bo + H
Bn = I*Ro + J*Go + K*Bo + L

DHL只是常数“偏移量”

让我们用这个图像做一个例子:

enter image description here

因此,如果要交换红色和蓝色通道,并将绿色通道转换为实心64,可以执行以下操作:

#!/usr/bin/env python3

from PIL import Image

# Open image
im = Image.open('start.jpg')

# Define color matrix to swap the red and blue channels and set green to absolute 64
# This says:
# New red   = 0*old red + 0*old green + 1*old blue + 0offset
# New green = 0*old red + 0*old green + 0*old blue + 64offset
# New blue  = 1*old red + 0*old green + 0*old blue + 0offset
Matrix = ( 0, 0, 1, 0,
           0, 0, 0, 64,
           1, 0, 0, 0)

# Apply matrix and save
result = im.convert("RGB", Matrix).save('result.png')

enter image description here


现在来到你的特定矩阵。。。矩阵中FK的值几乎为1,因此,矩阵对绿色和蓝色通道的更改最小。然而,由于B=0.57969594和第一行上的其他条目较低,因此新的红色通道在很大程度上来自现有的绿色通道

关键词:Python、图像处理、颜色矩阵、颜色矩阵、交换频道

相关问题 更多 >