dtwxmn8741 2017-03-07 13:32
浏览 137
已采纳

Imagemagick转换颜色矩阵

I have a ColorMatrix used to filter a image in 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
         ]

Using same matrix I try to filter the image using imagemagick convert tool. If i use a 3x3 matrix all is good, but using this matrix wont work. Please help

Command from command line :

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
  • 写回答

1条回答 默认 最新

  • douju4278 2017-03-07 19:39
    关注

    The color matrix you have provided is invalid. For a RGB image, there's not much reason to go past 3x3, as they map to color channels.

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

    ImageMagick can support any form of custom matrices up to 6x6. BUT you would be responsible for prototyping the matrix size ahead of the channel arrays. e.g...

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

    Some examples (copying data from your question randomly)

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

    rose_3x3.png

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

    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
    

    rose_6x6.png

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog