Imagemagick 转换颜色矩阵

Imagemagick convert color-matrix

我有一个 ColorMatrix 用于过滤 html 中的图像 canvas:

matrix = [
                        0.6279345635605994, 0.3202183420819367, -0.03965408211312453, 0, 9.651285835294123,
                        0.02578397704808868, 0.6441188644374771, 0.03259127616149294, 0, 7.462829176470591,
                        0.0466055556782719, -0.0851232987247891, 0.5241648018700465, 0, 5.159190588235296,
                        0, 0, 0, 1, 0
         ]

使用相同的矩阵,我尝试使用 imagemagick 转换工具过滤图像。 如果我使用 3x3 矩阵一切都很好,但使用这个矩阵将不起作用。请帮助

来自命令行的命令:

convert test.jpg  -color-matrix  
    "0.5997023498159715 0.34553243048391263 -0.2708298674538042 0      
    47.43192855600873 -0.037703249837783157 0.8609577587992641 
    0.15059552388459913 0 -36.96841498319127 0.24113635128153335 
    -0.07441037908422492 0.44972182064877153 0 -7.562075277591283 0 0 0 1 0" 
test2.jpg

您提供的颜色矩阵无效。对于 RGB 图像,没有太多理由超过 3x3,因为它们映射到颜色通道。

red'    = 1 * red + 0 * green + 0 * blue
green'  = 0 * red + 1 * green + 0 * blue
blue'   = 0 * red + 0 * green + 1 * blue

ImageMagick 可以支持最大 6x6 的任何形式的自定义矩阵。 但是 您将负责在通道阵列之前制作矩阵大小的原型。例如...

 -color-matrix '6x2: 1 0 0 0 0 1
                     0 1 0 0 0 1'

一些例子(从你的问题中随机复制数据)

rose: -color-matrix '0.599  0.3455 -0.2708 
                     0     47.4319 -0.0377 
                     0.8609 0.1505  0' rose_3x3.png

convert rose: -color-matrix '4x1: 0 -36.9684 0.2411 -0.07441' rose_4x1.png

convert rose: -color-matrix '6x6: -7.5620 0       0       0       1       0
                                   0.1505 0     -36.9684  0.2411 -0.0744  0.4497 
                                  -7.5620 0       0       0       1       0 
                                   0.5997 0.3455 -0.2708  0      47.4319 -0.0377
                                   0      1       0       0.1505  0     -36.9684 
                                  -0.2708 0      47.4319 -0.0377  0.8609  0.1505' rose_6x6.png