Page 1 of 1

Calculate brightness? What about shape?

Posted: 2008-03-20T17:14:41-07:00
by wobsie
Is there an easy way to calculate the brightness of an entire image? I want to compare brightness values of thousands of images.

Also, if I have a black & white image, is there a way to calculate how clustered the black pixels are? I'm subtracting the background out of camera images and thresholding it to generate a binary image. Because the image background jiggles over time, the differenced-and-thresholded image isn't very clean -- there are lots of streaks and dots in addition to the dark ovals (it's the dark ovals that I'm interested in). I need a way to distinguish the images containing only the streaks and dots from the ones with the dark ovals. I thought there might be a way to calculate how clustered the black pixels are. Is there?

Thanks.....

Re: Calculate brightness? What about shape?

Posted: 2008-03-21T12:29:22-07:00
by fmw42
First it is not clear what you mean by brightness. You can get IM to tell you what the average gray level value is for a grayscale image (in IM 6.3.9.1+) using:

identify -format "%[mean]" <image>

or

convert <image> -format "%[mean]" info:

see
http://www.imagemagick.org/script/escape.php

If you are on an earlier IM version, you can extract it from the -verbose info: as follows:

data=`convert <image> -verbose info:`
echo "$data" | sed -n '/^.*Mean:.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'

or in one line as

echo "$(convert <image> -verbose info:)" | sed -n '/^.*Mean:.*[(]\([0-9.]*\).*$/{ s//\1/; p; q; }'

With respect to your second issue, can you post some links to pictures to explain your problem?

Re: Calculate brightness? What about shape?

Posted: 2008-03-21T15:23:06-07:00
by wobsie
fmw42 wrote:With respect to your second issue, can you post some links to pictures to explain your problem?
I'd like to calculate a metric so that I can tell "clustered" from "scattered."

Clustered:
Image

Scattered:
Image

One way that I've seen this done (in GIS) is to calculate the average "patch" size where a "patch" is a continuous blob of a single color. But, for one, I don't know how to do that in ImageMagick, and it seems like a very slow operation.

Thanks.

Re: Calculate brightness? What about shape?

Posted: 2008-03-21T22:45:10-07:00
by fmw42
I will try to look at this more over the weekend. But my first thought is to do a fairly large median filter (or a number of iterations of a binary morphologic filter) to remove small specks and fill in holes. What is left are the blobs.

How do you define a patch size? How big is it? What is the minimum number of pixels in a patch? Are patches nearly the same size? There are many factors.

See my answer to another recent question at

viewtopic.php?f=1&t=10889

He has now written something custom. Perhaps if appropriate to your problem he will share with you.

IM does not have blob analysis functions to my knowledge.