:: AForge.NET Framework :: Articles :: Forums ::

C# newbie using Brightness Filter

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

C# newbie using Brightness Filter

Postby raynne » Thu Mar 05, 2009 5:18 am

I am trying to update a picturebox realtime using a trackbar. The picturebox does updated but for some reason, my image brightens very quickly and it goes all white or all black depending on what direction I move the trackbar. Can anyone tell me what i'm doing wrong? Thanks in advance...

Here are my events for my form:
public PhotoColorForm(Manager mg,Object obj)
libraryMgr = mg;
Photo originalPhoto = (Photo)obj;
originalPicBox.Image = new Bitmap(originalPhoto.getPhotoImage());
newPicBox.Image = new Bitmap(originalPhoto.getPhotoImage());
trackBarBrightness.Minimum = -1000;
trackBarBrightness.Maximum = 1000;
trackBarContrast.Minimum = -1000;
trackBarContrast.Maximum = 1000;
trackBarBrightness.Value = 0;
trackBarContrast.Value = 0;
private void trackBarBrightness__ValueChanged(object sender, EventArgs e)
textBoxBright.Text = ((double)trackBarBrightness.Value/1000).ToString();


private void textBoxBright_TextChanged(object sender, EventArgs e)
Bitmap newImage = Editor.changeBrightness((Bitmap)newPicBox.Image, double.Parse(textBoxBright.Text));
newPicBox.Image = (Bitmap)newImage.Clone();

The editor static class instantiates the BrightnessFilter class and calls the following method:
static public Bitmap changeBrightness(Bitmap bm, double value)
Bitmap newImage;
AForge.Imaging.Image.FormatImage(ref bm);
filter.AdjustValue = value;
newImage = filter.Apply(bm);
return newImage;
Posts: 1
Joined: Thu Mar 05, 2009 4:45 am

Re: C# newbie using Brightness Filter

Postby andrew.kirillov » Thu Mar 05, 2009 7:15 am


I believe you are using the BrightnessCorrection class (you did not specify it clearly in your code).

raynne wrote:my image brightens very quickly and it goes all white or all black depending on what direction I move the trackbar

How quickly? At which values of AdjustValue property? I need to note that the maximum adjust value, which is 1.0, is to turn absolutely dark picture (black) into absolutely bright (white). Try IPLab and experiment with black picture. But, most pictures are not black, so increasing brightness by 50% already may give a white image. You need to understand, that the image processing filter does not set brightness of the image to the specified value. The image processing filter increases/decreases brightness by specified value. See docs: "The filter operates in HSL color space and adjusts pixels' brightness value using luminance value of HSL color space, increasing it or decreasing by specified percentage."
With best regards,

Interested in supporting AForge.NET Framework?
User avatar
Site Admin, AForge.NET Developer
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Return to AForge.NET Framework