Skin Color Detection with HSV Lookup

 

 

Skin color detection algorithms are used to detect human body. A primitive algorithm to this is the HSV lookup. At first a pixel is converted to its HSV values and according to definition (1) either a pixel is skin component or not. If pixel is not a skin component then it is painted white. H is for Hue value and S is for Saturation value.

 

                                               (1)

 

           

 

(a)                                                                  (b)

 

                 

(c)                                                                              (d)

 

                 

(e)                                                                              (f)

 

(g)                                                                              (h)

Figure 1. (a), (c), (e) and (g) are original images and (b), (d), (f) and (h) are skin detected images

 

 

C Source Code

 

            Below there is only skin color detection procedure. You can reach complete source code from here.

 

int Find_Skin(long **RRed, long **GGreen, long **BBlue, long width, long height)
{
   long i, j, Value, R, G, B, tmp;
   double Saturation, Hue, Cr, Cg, Cb; 

   for(i=0;i<height;i++)
   {
      for(j=0;j<width;j++)
      {
        R = RRed[i][j];
        G = GGreen[i][j];
        B = BBlue[i][j];
        ///////////////////  VALUE
        // find maximum
        if ( (R >= G) && (R >= B))
           Value = R;
        else if ( (G >= R) && (G >= B))
           Value = G;
        else if ( (B >= G) && (B >= R))
           Value = B;
        ///////////////////  SATURATION
        // find minimum
        if ( (R <= G) && (R <= B))
           tmp = R;
        else if ( (G <= R) && (G <= B))
           tmp = G;
        else if ( (B <= G) && (B <= R))
           tmp = B;
        if (Value == 0)
           Saturation = 0;
        else
           Saturation = ((double)Value - (double)tmp)/(double)Value;
        ///////////////////  SATURATION
        if (Saturation == 0)
           Hue = -1;
        else
        {
           Cr = ((double)Value-(double)R)/((double)Value-(double)tmp);
           Cg = ((double)Value-(double)G)/((double)Value-(double)tmp);
           Cb = ((double)Value-(double)B)/((double)Value-(double)tmp);
           if (R == Value)
              Hue = Cb - Cg;
           if (G == Value)
              Hue = 2 + Cr - Cb;
           if (B == Value)
              Hue = 4 + Cg - Cr;
           Hue *= 60;
           if (Hue < 0)
                                    Hue +=360;
        }
        ///////////////////////
        // DETECT SKIN COLOR //
        ///////////////////////
        if ( (Hue >= 0.0) && (Hue <= 50.0) && (Saturation >= 0.23) && (Saturation <= 0.68) )
        {
           RRed[i][j] = R;
           GGreen[i][j] = G;
           BBlue[i][j] = B;
        }
        else
        {
          RRed[i][j] = 255;
          GGreen[i][j] = 255;
          BBlue[i][j] = 255;
        }
      }
   }

   return 0;
}
Copyright by Chasan Chouse