Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
RE: Calculating the "Mean" of a histogram...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Calculating the "Mean" of a histogram...



Thanks, Bruce. I got it now.

The equation you gave was my first instinct to try, but it only works when
there are an equal amount of pixels per level. If the number of pixels for
each level is different, it doesn't work. We need to factor in the total
amount of pixels each level occupies, so we need to multiply each level by
its pixel count, add those numbers up, and then divide by the total pixels.

So your example would be: [(68 x 1) + (175 x 1) + (112 x 1) + (29 x 1)] / 4
= 96.

As far as the large numbers go, my script (if I can get it to work ;o) will
only be meant to work with a histogram of a small selection.

Thanks again. This was frustating for me, but intersting.

Carl.

> ----------
> From: Bruce J. Lindbloom
> Sent: Tuesday, August 5, 2003 10:40 AM
> To: ColorSync User List
> Cc: email@hidden
> Subject: Re: Calculating the "Mean" of a histogram...
>
> Carl Stawicki wrote:
> > I'm working on an AppleScript that will calculate the Mean value of a
> > channel's histogram. The Mean is the average intensity value, and I'm
> giving
> > myself a headache trying to figure out the math.
>
> Just add up the pixel values and then divide the result by the number of
> pixels. For example, if you had an image that was two pixels by two
> pixels,
> there are four total pixels:
>
> 68 175
> 112 29
>
> The mean would be (68 + 175 + 112 + 29) / 4 = 96.
>
> But something you must watch out for is that most images are larger than 2
> x
> 2 pixels, and in fact may easily be MUCH larger than 2 x 2 pixels. So the
> sum of all pixel values could be a very large number, and depending on the
> data type that is used to store it, it may overflow which would yield the
> wrong result. If a 32-bit signed integer was used for the sum with an
> 8-bit
> per channel image, an overflow could occur with an image larger than 2900
> x
> 2900 pixels. If you are working with 16-bit channels, the scenario is much
> worse (180 x 180). You should probably use floating point, if the
> scripting
> allows that sort of control (sorry, I'm not an AppleScript guy).
> --
> Bruce J. Lindbloom
> email@hidden
> http://www.brucelindbloom.com
_______________________________________________
colorsync-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/colorsync-users
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.