views:

51

answers:

2

Hi,

I am building an image editor for Silverlight 4.0 and need some insight or possibly a snippet of code or library to implement contrast/brightness management.

I would appreciate if somebody would share how it can be achieved.

Thanks!

+1  A: 

Here's a great article on changing brightness at runtime. It essentially involves transforming a Brush color to HSB, applying a new "brightness" level, and then transforming back to the new Brush color.

As for contrast... I suppose you could do the same basic trick, but this time check RGB values of each color; if one color happens to dominate the other colors, increase its color value and decrease the other color values by some factor. Your reds become redder, your greens become greener, your blues become bluer. The factor would need tweaking, but it might work.

Randolpho
Thanks Randolpho, I appreciate your assistance. I guess I need to read that article first.
Anvar
+2  A: 

Contrast is how "wide" a swath of pixel brightness values are present, out of the total range of values possible.

Brightness is the "offset" of this swath from the minimum possible level.

To increase contrast, subtract (smallest present value - smallest possible value) from all pixel values to put the swath back at 0. Then multiply all values by (max possible value / max value present ) to scale the "swath" to the range of all possible values.

To adjust brightness, add or subtract an absolute value from each pixel.

You probably want to do this with the Luminance or Value channel in a HSL or HSV colorspace.

I found some code here. http://www.dfanning.com/ip_tips/contrast.html

Joe Koberg
Thanks Joe, I appreciate it.
Anvar