Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do something similar to Auto Tone of Photoshop with Aforge.net or c#

Im developing an image skin detection app.

But there is a problem with my camera, that try to compensate the light and the result image is bad, in most of cases i have a cold or warm effect on the image. When i use photoshop there is the AutoTone function that normalize an image and reduce this problem.

Image

Image after Photoshop AutoTone

With aforge i want to use HistogramEqualization() filter but the result is very bad:

Image after HistogramEqualization

// create filter
HistogramEqualization filter = new HistogramEqualization( );
// process image
filter.ApplyInPlace( sourceImage );

So my question is: There is a function in Accord or Aforge to have the same result of the autotone of Photoshop? If not, there is some library or script that let to do this?

Thank you all.

like image 735
Univers3 Avatar asked Oct 05 '22 14:10

Univers3


2 Answers

I use the LevelsLinear filter and base it on image stats:

ImageStatistics stats = new ImageStatistics(sourceImage);
LevelsLinear levelsLinear = new LevelsLinear {
    InRed = stats.Red.GetRange( 0.90 ),
    InGreen = stats.Green.GetRange( 0.90 ),
    InBlue  = stats.Blue.GetRange( 0.90 )
};

levelsLinear.ApplyInPlace(sourceImage);

You can play with the range to tweak the result.

like image 104
Joan Charmant Avatar answered Oct 25 '22 16:10

Joan Charmant


You probably don't want to equalize the histogram, because as you see, a photo that wouldn't normally have much red, would have alot of red created and make it look nasty. Instead you probably want to examine for a bias to a hue that occurs almost everywhere. For example, your original photo probably had a bias towards blue in almost every pixel, and thus probably shouldn't be there. Look for a minimum bias and remove that amount everywhere.

A more practical solution is to experiment with the white balance setting on your camera to see what gives you the best result. Choosing the right preset, will leverage an algorithm that's probably as good as what you would write by hand. But maybe you are doing this as a learning experience.

like image 20
AaronLS Avatar answered Oct 25 '22 16:10

AaronLS