开发者

Removing non red toned pixels

开发者 https://www.devze.com 2023-02-21 16:56 出处:网络
I have a very simple image processing application. I am trying to remove the pixels which do not involve red tones.

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 开发者_如何学Pythonam 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

Removing non red toned pixels

Removing non red toned pixels

Any algorithm or thought will be very appreciated.

Thanks in advance

Removing non red toned pixels


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消