1

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.

2
  • What languages do you have available to determine the shade of the image (Java, C, C++, etc.)? ANSI SQL can't do this, so you need some other application running as a CRON job or something of the sort to do this. For C, there is always OpenCV: opencv.willowgarage.com/wiki Jan 21, 2010 at 15:13
  • openCV looks interesting. never heard of it before, but I've been trying to programatically get images off a camera, and it looks like just the thing.
    – nont
    Jan 22, 2010 at 0:55

2 Answers 2

1

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)

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.