3
votes

What is the easiest way to properly adjust Brightness, Contrast and Gamma of an image. The word 'properly' is here because I know how to perform these adjustments improperly: loop over all the RGB pixels and do the following to each channel:

int changeBrightness( int value, int brightness) {
    return qBound<int>(0, value + brightness * 255 / 100, 255);
}
int changeContrast( int value, int contrast ) {
    return qBound<int>(0, int(( value - 127 ) * contrast / 100 ) + 127, 255 );
}
int changeGamma( int value, int gamma ) {
    return qBound<int>(0, int( pow( value / 255.0, 100.0 / gamma ) * 255 ), 255 );
}

Although this code will add the effect of brightness/conrast/gamma change, it does not look very well. Professional imaging software, like Photoshop does it much better.

What is the best library to deal with this kind of stuff? I know there is ImageMagick, but it's really heavy, I dont want to link to only one feature of hundreds. Are there any lightweight alternatives?

1
Photoshop may very well being doing something in addition to just basic bri/con/gamma adjustments, if it doesn't produce the same results as your implementation. I'd vote for OpenCV however.Chris O
ImageMagick shows similar results to Photoshop. I think they both use a proper technique. I'm sure it's not rocket surgery, but still pretty complicatedak.

1 Answers

2
votes