views:

37

answers:

2

Hi All,

For a database app I'm trying to determine the average shade of a section of photo, against a colour scale.

Being a novice I'm finding this very difficult to explain so I've created a simple diagram showing exactly what I'm trying to achieve.

http://www.knockyoursocksoff.com/shade/

If anybody has the time to give me some ideas I'd be very grateful.

Best wishes,

Warren.

A: 

I think I would start by just averaging the pixel values:

for x = start_x to end_x
for y = stary_y to end_y
  total += getPixel(x,y)
shade = total / (xlen*ylen)

Its going to be more complicated if you're doing it in color.

nont
A: 

If you are using color photos, you should first convert the selected area from RBG (red, green, blue) to HSL/HSV (article).

HSL stands for "hue, saturation, lightness".1 The number you are interested in is the lightness.

In the most general terms, the lightness refers to how you perceive the brightness of a colored surface. It's hard to use the red/green/blue components to say whether a patch of red is brighter/darker than, say, a patch of blue. Converting to HSL takes care of that problem.

Once you have done the conversion, you can simply average the lightness values of your selected area.

Quick note on lightness values: Technically, you can't simply average the lightness values because the perception of lightness is not linear (article). But, unless you are writing a deeply scientific application, simply averaging the lightness will give you an "accurate enough" value.


1 In Adobe Photoshop, they call it HSB (hue, saturation, brightness)

Robert Cartaino