Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!

I have been trying to make a piece of code, that will allow me to adjust the contrast of an image.

Earlier I found a fast and easy way using matrix to adjust brightness, and I really need a similar system for the contrast.

What I have found until now is either working way too slow (adjusting a pixel at a time) or seem to be a variation of brightness adjustment(?) like this:

C#
float[][] wk_colormatrix ={
         new float[] {wk_float, 0, 0, 0, 0},
         new float[] {0, wk_float, 0, 0, 0},
         new float[] {0, 0, wk_float, 0, 0},
         new float[] {0, 0, 0, 1, 0},
         new float[] {wk_float_x, wk_float_x, wk_float_x, 0, 1}
     };


My experience tell me, that if I can't find what I need on the internet, it's either impossible, or so easy and simple that no one ever needed to ask about it ;-)

However, it is obviously possible, since it works great int i.e. Paint.net, where I can adjust contrast of an image "on the fly" so to speak!

So, I've decided to throw in the towel: Anything that can help me here will be more than welcome!

Sincerely/Best regards

Mads Kristian
Posted
Comments
Prasad Khandekar 26-Mar-13 10:10am    
Might want to have alook at this (http://stackoverflow.com/questions/3115076/adjust-the-contrast-of-an-image-in-c-sharp-efficiently). And this fantastic CP article (http://www.codeproject.com/Articles/33838/Image-Processing-using-C)
Mads1967 27-Mar-13 3:11am    
Thank you for the links.
I had already found them, but now I did take a closer look especially on that last one.
Actually, when adjusting the contrast it does approximately the same as I found earlier, and thought it was - well - not the right way to do it: The image somehow turns *very* "yellowish" on places where it should be white.
However, when giving the result in Paint.net a second inspection, it looks like they actually make it black and white when contrast is taken close to the limit. This way an eventual yellow shade vanishes into a white.
I'm not an expert into image manipulation, and there is a lot of parameters I don't know, like saturation, hue, etc.
What I need is something that would turn dark grey letters on a light grey surface into something as close to "black letters on a white surface" as possible.
Maybe the solution is somewhere in the CP article about Image-Processing-using-C after all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900