Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm facing a problem with detecting skin color in images loaded in picureBox1, I implemented the equations in the article below.

I need your suggestions that make my code working.

http://i.stack.imgur.com/2KyvO.png
http://i.stack.imgur.com/pPend.png

Thanks
VB
   Bitmap bm = (Bitmap)pictureBox1.Image;
        Bitmap bmp = new Bitmap(pictureBox1.Image.Width, pictureBox1.Image.Height);
        Color color = new Color();
        double Cb,Cr,r,g,b,R,G,B; 
        double CbMean = 156.56;
        double CrMean = 117.43;
        double K1 = 160.13 ;
        double K2 = 12.143;
        double K3 = 12.143;
        double K4 = 299.46;
        for (int i = 0; i < pictureBox1.Width; i++)
        {
            for (int j = 0; j < pictureBox1.Height; j++)
            {
                color = bm.GetPixel(i, j);
                R = Convert.ToDouble(color.R);
                G = Convert.ToDouble(color.G);
                B = Convert.ToDouble(color.B);

                r = R / (R+G+B);
                g = G / (R+G+B);
                b = B / (R+G+B);
                Cb = (-0.169 * r - 0.331 * g + 0.500 * b);
                Cr = (0.500 * r - 0.418 * g - 0.082 * b);
                Cb -= CbMean;
                Cr -= CrMean;
                double CbDist = (K1 * Cb) + (K3 * Cr);
                double CrDist = (K2 * Cb) + (K4 * Cr);
                double CbDist1 =(0.5 * Cb) + (0.5 * Cr);
                double CrDist1 = (0.5 * Cb) + (0.5 * Cr);
                double dist = CbDist + CrDist;
                double dist1 = CbDist1 + CrDist1;
                double gmm = Math.Exp(dist * dist1);
                bmp.SetPixel(i, j, Color.FromArgb(255, (int)gmm, (int)gmm, (int)gmm));
            }
        }
pictureBox2.Image = bmp;
Posted
Updated 8-Jan-14 9:49am
v4
Comments
Ron Beyer 8-Jan-14 14:53pm    
It would help if you told us where you were getting this error.
directx88 8-Jan-14 14:55pm    
in some images, the output is shown as BLACK image in pictureBox2, and sometimes it get ArgumentException error in GMM values. My equation is right. I need to know where is my error according to the paper above. I need to draw the likelihood image show also in the paper
jauma 8-Jan-14 15:21pm    
Please tell us the line of your code in which the exception is raised
Matt T Heffron 8-Jan-14 15:48pm    
Have you verified that the computed gmm value is between 0-255? (Actually (int)gmm is in that range.)
Is the computed gmm on a 0.0-1.0 range that you need to convert to 0-255?
directx88 8-Jan-14 16:23pm    
the error in line "bmp.SetPixel(i, j, Color.FromArgb(255, (int)gmm, (int)gmm, (int)gmm));"
I can't draw gmm values, this is the problem, is my code right?

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