【问题标题】:Image Magick / Detect colors contained on a imageImage Magick / 检测图像中包含的颜色
【发布时间】:2013-04-12 20:02:30
【问题描述】:

给出图像中包含的颜色数组的简单过程是什么?

【问题讨论】:

    标签: image-processing colors imagemagick pixel


    【解决方案1】:

    ImageMagick 的“转换”命令可以生成直方图。

    $ convert image.png -define histogram:unique-colors=true -format %c histogram:info:-
    
    19557: (  0,  0,  0) #000000 gray(0,0,0)
     1727: (  1,  1,  1) #010101 gray(1,1,1)
     2868: (  2,  2,  2) #020202 gray(2,2,2)
     2066: (  3,  3,  3) #030303 gray(3,3,3)
     1525: (  4,  4,  4) #040404 gray(4,4,4)
       .
       .
       .
    

    根据您选择的语言以及您希望如何表示颜色,您可以从这里获得很多方向。这是一个快速的 Ruby 示例:

    out = `convert /tmp/lbp_desert1.png \
                   -define histogram:unique-colors=true \
                   -format %c histogram:info:- \
           | sed -e 's/.*: (//' \
           | sed -e 's/).*//'`
    
    out.split("\n")
        .map{ |row| row.split(",").map(&:to_i) }
    
    
    # => [[0, 0, 0], [1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4] .....
    

    【讨论】:

    • +1 表示“取决于您选择的语言”。态度很好。
    猜你喜欢
    • 1970-01-01
    • 2013-01-26
    • 2012-07-01
    • 2011-06-29
    • 2018-07-16
    • 2011-02-19
    • 1970-01-01
    • 2016-08-29
    • 1970-01-01
    相关资源
    最近更新 更多