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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题