Page 1 of 1

Analyze only opaque pixels

Posted: 2015-11-09T11:32:31-07:00
by tom_dl
Hi, I'm running IM 6.9.0-10 Q16 x64.

I have an image where I'd like to analyze a certain portion of the image. The portion is an irregular shape, so I cannot crop to the portion. I have decided to make all other pixels transparent, but

Code: Select all

-format "%[mean]" info:
doesn't care - it still analyzes the whole image, including the transparent pixels. If I set all the transparent pixels to white, or all to black, it obviously skews the mean up massively, or down massively, respectively. What am I to do!? I just want to know the mean value of the opaque pixels!

Any help would be very much appreciated.

Tom

Re: Analyze only opaque pixels

Posted: 2015-11-09T11:41:12-07:00
by fmw42
see the "Better Method" at http://www.fmwconcepts.com/imagemagick/ ... shape_mean

After making all other pixels transparent, do

Code: Select all

-scale 1x1! -format "%[fx:u*quantumrange]" info:`
for range 0 to quantumrange

or

Code: Select all

-scale 1x1! -format "%[fx:u*255]" info:`
for range 0 to 255

Code: Select all

-scale 1x1! -format "%[fx:u]" info:`
for range 0 to 1

Re: Analyze only opaque pixels

Posted: 2015-11-10T04:32:07-07:00
by tom_dl
I didn't realise the -scale operator ignored all transparent values. That's really helpful. Thanks!