Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing non red toned pixels

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 beforeafter

Any algorithm or thought will be very appreciated.

Thanks in advance

matlab imtool

like image 513
cgon Avatar asked Apr 01 '11 13:04

cgon


1 Answers

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.

like image 135
Mike O'Connor Avatar answered Nov 11 '22 19:11

Mike O'Connor