Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Skin Recognition in C#

0.00/5 (No votes)
28 Aug 2004 1  
Skin Recognition in C#.

Sample Image - Skin_RecC_.jpg

Introduction

     This article is based on a project I started this summer. Originally the project was a simple edge detection system, but now its turning into a face recognition system.

The first thing that I did done when implementing a skin filter is to convert from RGB color space

to IRgBy color space by using this formula:

I = [L(R) + L(B) + L(G)] / 3
Rg = L(R) - L(G)
By = L(B) - [L(G) +L(R)] / 2

where L is a logarithmic function.

The next thing is to find out the hue, by using this formula:
hue = atan2(Rg,By) * (180 / 3.141592654f)

if (I <= 5 && (hue >= 4 && hue <= 255))
{
     //skin
}
else
{
     /*not skin color it black*/
     modified.SetPixel(x, y, Color.Black);
}
 

 

An example of how you would call the method Vision.DetectSkin(Bitmap original, ref Bitmap modified)

Bitmap original = new Bitmap(@"C:\mypicture.bmp");
Bitmap modified = original;
Vision.DetectSkin(original, ref modified);
//now if you save modified and the look at it you will see that it 
//detected all the skin from the original image

As you can see from the picture the algorithm isn't perfect yet and it needs some touching up.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here