65.9K
CodeProject is changing. Read more.
Home

Skin Recognition in C#

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.86/5 (35 votes)

Aug 29, 2004

1 min read

viewsIcon

95135

downloadIcon

3600

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.