Analyze only opaque pixels

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
tom_dl
Posts: 43
Joined: 2015-02-26T08:25:44-07:00
Authentication code: 6789

Analyze only opaque pixels

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Analyze only opaque pixels

Post 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
tom_dl
Posts: 43
Joined: 2015-02-26T08:25:44-07:00
Authentication code: 6789

Re: Analyze only opaque pixels

Post by tom_dl »

I didn't realise the -scale operator ignored all transparent values. That's really helpful. Thanks!
Post Reply