本文介绍了Image Magick / Detect图像中包含的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What would be the simple process that would gives an array of the colors contained in an image ?

推荐答案

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

ImageMagick's "convert" command can generate a histogram.

$ 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示例:

Depending on your language of choice and how you want the colors represented, you could go lots of directions from here. Here's a quick Ruby example though:

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] .....

这篇关于Image Magick / Detect图像中包含的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 08:04