Page 1 of 1
How to check for empty (mono-color) image?
Posted: 2011-04-07T07:26:00-07:00
by graceman9
subj.
For example, I cut the picture on the tiles, and I want to know which of them are empty? (transparent, or the same color). Thanks for the replies.
Re: How to check for empty (mono-color) image?
Posted: 2011-04-07T11:40:04-07:00
by fmw42
get the standard-deviation from the verbose statistics for each tile. If the standard deviation is 0, then the image is one color. You may have to look channel by channel including the alpha channel.
Alternate is to use string formats. See
http://www.imagemagick.org/script/escape.php
convert image -format "%[standard_deviation]" info:
returns values between 0 and QuantumRange (255 for 8-bit or 65535 for 16-bit IM compiles0
or
convert image -format "%[fx:u.standard_deviation]" info:
returns values between 0 and 1
Re: How to check for empty (mono-color) image?
Posted: 2011-04-07T22:34:28-07:00
by anthony
Number of colors %k will also do this! If you have one unique color then it will be 1
Re: How to check for empty (mono-color) image?
Posted: 2011-04-08T02:12:29-07:00
by graceman9
fmw42 wrote:convert image -format "%[standard_deviation]" info:
Not work for me. I also try
Code: Select all
identify -format %[standard-deviation]
but two same (empty and transparent images, size 450 and 452 bytes) give different results:
Code: Select all
$ identify -format %[standard-deviation] 1.png
11571.2
$ identify -format %[standard-deviation] 2.png
7529.32
MY TWO TRANSPARENT IMAGES BELOW:

I see no difference in eog or gimp, but when I upload image i saw this (white lines in top of image):
http://pic.lg.ua/s/g/0YCfF/DYPSF
anthony wrote:Number of colors %k will also do this! If you have one unique color then it will be 1
Yes, it is!
And new question: how can I diff "white mono-color image" from "gray mono-color image" ?
Re: How to check for empty (mono-color) image?
Posted: 2011-04-08T10:13:19-07:00
by fmw42
see -compose minus or -compose different or compare
http://www.imagemagick.org/Usage/compose/#minus
http://www.imagemagick.org/Usage/compose/#difference
http://www.imagemagick.org/Usage/compare/
Can you be more specific about what type of compare you want -- what kind of result -- an image or a number
Re: How to check for empty (mono-color) image?
Posted: 2011-04-10T01:04:04-07:00
by graceman9
Excuse me for the delay in replying.
I need the result - a number.
That's what I found:
Code: Select all
alpha=`convert $f -resize 1x1 txt: | sed '1d' | sed 's/\([^)]*\).*/\1/' | sed 's/,/ /g' | awk '{print $NF}'`
But I still want to do this without "sed" expression

any advice?
Re: How to check for empty (mono-color) image?
Posted: 2011-04-10T05:32:26-07:00
by anthony
graceman9 wrote:And new question: how can I diff "white mono-color image" from "gray mono-color image" ?
Just crop a single pixel from the image and output a TXT: image.
Code: Select all
convert image.png -crop 1x1+0+0 txt:
See
TXT: image file format and
Extracting Image Color
OR just get IM to print the images 0,0 color using
-format and
info:
Code: Select all
convert image.png -format "%[pixel:s]" info:
See
info: identify output and
FX Expressions as Escapes
With one image you can also
-print (only outputs its formatted string once, not once per image.
Code: Select all
convert image.png -print "%[pixel:s]" null:
See
Formated Text Output Options