Click here to Skip to main content
15,886,584 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to do an image segmentation which depends on the histogram values, first I did k-mean, then I convert the image to grey and taken the histogram value from it. Finally, I using the threshold to get the requested part.

What I have tried:

private void button2_Click(object sender, EventArgs e)
        {
            int width = image.Width;
            int height = image.Height;
            
            Color p;

            //Grayscale
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    p = image.GetPixel(x, y);
                    int a = p.A;
                    int r = p.R;
                    int g = p.G;
                    int b = p.B;
                    double someDouble = ((r * 0.3) + (g * 0.59) + (b * 0.11));
                    int avg = Convert.ToInt32(someDouble);
                    //int avg = (r + g + b) / 3;
                    avg = (avg < 100) && (avg > 80) ? 0 : 255;     // Converting 

                                     gray pixels to either pure black or pure white
                    
                    bmp1.SetPixel(x, y, Color.FromArgb(a,avg, avg, avg));
                }
            }
            pictureBox2.Image = bmp1;
        }


my question? I didn't get good segmentation...can someone give me advice, and what does the command "
avg = (avg < 100) && (avg > 80) ? 0 : 255;
" give me when become true? white "1" or black"0"?
Posted
Updated 9-Sep-19 2:50am
Comments
Member 14129828 9-Sep-19 11:04am    
thank you very much

1 solution

if "avg" is between 81 and 99, it returns 0, else 255.

(RGB 0,0,0 is black).
(RGB 255,255,255 is white).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900