I'm using AForge.net for my channel filtering, I have 3 button, red, blue and green. When I click on button red it will apply the filter of red channel. However, when I go on to click on the blue button, it will overlap the red and image goes dark.
Does anyone know how can I "dispose" red channel when blue is click, vice versa, so as the filter will not overlap each other? Below is a snippet of my code.
private void redchannel_Click_1(object sender, EventArgs e)
{
try
{
pictureBox1.Image = pic;
pictureBox2.Image = pic2;
// create filter
ChannelFiltering filter = new ChannelFiltering();
// set channels' ranges to keep
filter.Red = new IntRange(0, 255);
filter.Green = new IntRange(255, 255);
filter.Blue = new IntRange(255, 255);
// apply the filter
filter.ApplyInPlace(pic2);
}
catch (Exception)
{
throw new ApplicationException("Failed loading image");
}
}
private void bluechannel_Click_1(object sender, EventArgs e)
{
try
{
pictureBox1.Image = pic;
pictureBox2.Image = pic2;
// create filter
ChannelFiltering filter = new ChannelFiltering();
// set channels' ranges to keep
filter.Red = new IntRange(255, 255);
filter.Green = new IntRange(255, 255);
filter.Blue = new IntRange(0, 255);
// apply the filter
filter.ApplyInPlace(pic2);
}
catch (Exception)
{
throw new ApplicationException("Failed loading image");
}
}
private void greenchannel_Click_1(object sender, EventArgs e)
{
try
{
pictureBox1.Image = pic;
pictureBox2.Image = pic2;
// create filter
ChannelFiltering filter = new ChannelFiltering();
// set channels' ranges to keep
filter.Red = new IntRange(255, 255);
filter.Green = new IntRange(0, 255);
filter.Blue = new IntRange(255, 255);
// apply the filter
filter.ApplyInPlace(pic2);
}
catch (Exception)
{
throw new ApplicationException("Failed loading image");
}
}
You need to store the original image as well as a potentially modified display image. Perform your calculations on the original and show them with the display image. Never alter the original, only the display image.