What would be the simple process that would gives an array of the colors contained in an image ?
The magick identify command recognizes these options. Click on an option to get more details about how that option works. analyze image features (e.g. contract, correlations, etc.). display image moments and perceptual hash. by default, efficiently determine certain image characteristics.
By default, magick identify provides the following output: Filename [frame #] image-format widthxheight page-widthxpage-height+x-offset+y-offset colorspace user-time elapsed-time Next, we look at the same image in greater detail:
The magick identify program describes the format and characteristics of one or more image files. It also reports if an image is incomplete or corrupt.
setFormat doesn't replicate the command line option -format - the one in Imagick tries to set the image format, which should be png, jpg etc. The one in the command line is setting the format for info - the closest match for which in Imagick is calling $imagick->identifyImage (true) and parsing the results of that.
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)
.
.
.
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] .....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With