I have a very simple image processing application.
I am trying to remove the pixels which do not involve red tones.
So far a basic code seems to achieve what I want.
private void removeUnRedCellsBtn_Click(object sender, EventArgs e)
{
byte threshold = Convert.ToByte(diffTxtBox.Text);
byte r, g, b;
for (int i = 0; i < m_Bitmap.Width; i++)
{
for (int j = 0; j < m_Bitmap.Height; j++)
{
r = im_matrix[i, j].R;
g = im_matrix[i, j].G;
b = im_matrix[i, j].B;
if ((r - b) < threshold || (r - g) < threshold)
{
m_Bitmap.SetPixel(i, j, Color.White);
}
}
}
pictureArea_PictureBox.Image = m_Bitmap;
}
Basically if the difference of (red and blue) or (red and green) is less than a threshold it sets the pixel to white.
My results seems to be promising however I am wondering if there is a better solution for determining whether a pixel involves red tones in it.
My results for a threshold value of 75 is
Any algorithm or thought will be very appreciated.
Thanks in advance
You might have more luck if you convert the RGB values to a different color space, like HSL or HSV. Check out this link on Wikipedia. Converting a pixel to one of those color spaces should help you isolate the hue, which is what you're mostly concerned with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With