Click here to Skip to main content
Click here to Skip to main content

Image Processing: Skin Detection, Some Filters and EXIF Tags

By , 17 Jul 2009
 

Introduction

RedMatter library is simple tool, which includes filters for skin detection and color correction and instruments for EXIF tags reading. Also you may develop your own filter and use it - it's very easy. Now RedMatter includes the following filters and tools:

  • Skin detection filters: implementation of apriority and parametric algorithms
  • Soft contour filter
  • Rectangle vignette filter
  • Color wave filter
  • Selective monochromatic filter
  • Statistic color correction tool
  • EXIF tags reading tool
  • Additional: simple fractal drawing

Using the Code

Skin Detection Filters

Apriority skin detection methods use a set of rules. These rules create a polygon in the color space. For example:

(R > 95 and G > 40 and B < 20 and
max{R, G, B} – min{ R, G, B }> 15
and |R - G| > 15 and R > G and R > B)
or 
(R > 220 and G > 210 and B > 170 and
|R - G| = 15 and
R > B and G > B)

Or:

Fig1.jpg

All skin detection classes implement a simple interface ISkinDetector:

public interface ISkinDetector: IImageSelector
    {
        bool IsSkin(Color color);
    }   

You may use these filters very easily:

    BaseDetector detector = new BaseDetector(sourceImage, new SimpleSkinDetector());
    pbxImage.Image = detector.SkinDetectionImage; 

The library includes six apriority filters with different sets of rules.

Guys_1.jpg

Guys_skin_detected_1.jpg

Figure 1. Apriority skin detection.

Parametric methods (for example, the Gauss method) use the comparison image with the sample of skin. Skin color distribution can be modelled by an elliptical Gaussian joint probability density function (PDF), de?ned as:
form2.jpg
Here, c is a color vector and µ and Ss are the distribution parameters.
form3.jpg
where n is the total number of skin color samples cj.

Example of usage:

// corrImage – It is sample of skin.
GaussianSkinDetector gauss = new GaussianSkinDetector(corrImage);
gauss.Threshold = 6;
BaseDetector detector = new BaseDetector(sourceImage, gauss);
pbxImage.Image = detector.SkinDetectionImage;

Soft Contour Filter

Example of usage:

SoftContourFilter soft = new SoftContourFilter(sourceImage);
soft.Softness = 20.0;
soft.Threshold = 125;
pbxImage.Image = soft.ResultImage;

Car.jpg Car_SoftContour_1.jpg

Figure 2. Soft contour filter.

Rectangle Vignette Filter

Example of code:

VignetteFilter vign = new VignetteFilter(sourceImage);
vign.Fade = 35;
vign.VignetteWidth = 50;
pbxImage.Image = vign.ResultImage;
Cats_1.jpg

Cats_vingette_1.jpg

Figure 3. Simple vignette.

Color Wave Filter

This effect like the noise on the old TV.

village_waves_1.jpg

Figure 4.Color wave effect.

You may use this filter very easily:

WavesFilter waves = new WavesFilter(sourceImage);
waves.Period = 50;
waves.Fade = 0.5;
pbxImage.Image = waves.ResultImage; 

Selective Monochromatic Filter

Did you see the movie "Sin city"? This effect is similar to the visual design of the film.

Car.jpg Car_SinCity.jpg
Figure 5. “Sin City” effect.

It's very easy:

SinCityFilter sin = new SinCityFilter(sourceImage, colorDialog.Color);
sin.Tolerance = 50;
pbxImage.Image = sin.ResultImage; 

Statistic Color Correction

Cats_1.jpg  +  Guys_1.jpg = Cats_corrected_1.jpg

Figure 6. Statistic color correction.

We need two images - the image for correction and image-source of color. Example of code:

StatisticColorCorrector scc = new StatisticColorCorrector(sourceImage, corrImage);
pbxImage.Image = scc.ResultImage; 

EXIF Tags Reading

Exchangeable image file format (Exif) is a specification for the image file format used by digital cameras (for all specifications, see here).
You may get a list of all EXIF tags:

PropertyReader pr = new PropertyReader(bitmap);
foreach (EXIFTag tag in pr.GetAllTags())
{
    // some code with  { tag.TagName, tag.TagValue }            
}

properties.jpg

Figure 7. Exif tags.

Conclusion

This library can be useful for image processing, solution problems of skin detection, and creation filters. I use this library in my research very often.

License

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

About the Author

Maxim_Barsuk
Software Developer
Russian Federation Russian Federation
Hello! My name is Maxim Subbotin.
 
Now I work in sphere of web-development. I'm interesting researches in SEO field.
If you interesting, you can see this tool:
 
KeywordCompetitor

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generalawesome code!!memberunnamed50023-Apr-13 8:13 
works great for my project. :thumbsup
Generalpleez help!memberbessso13-May-11 13:31 
I didn't understand this code ,i'm begginer in c#..
and i have a project in this week about skin detection...
can any one help me in simple code for skin detection or explain to me...
thank you..
GeneralMy vote of 5memberthatraja1-Nov-10 0:57 
Excellent...with example images...Have my 5 dude.
QuestionWhat Happenmemberbishtharish17-Aug-10 21:08 
What will be the output for this skin detection algorithm while the persons in the pic are black.
Is the resultant is similar as the demo or different.Cool | :cool:
 

 

 

 

 

 

 

 

 

 

 

 
cd rw data recovery

 

 

 

 

 

 

 

 

 

 

 

 
cd rw data recovery

GeneralExcelentemembernixsus30-May-10 8:01 
Felicitaciones!!
GeneralNew Skin Detection TechniquesmemberMember 220289128-Nov-09 10:10 
Do you think to implement color components in other color spaces, such as HSV or YCrCb formats? Because RGB components are subject to the lighting conditions which may induce skin detection to fail.
 
In additional: congratulations for the codes!
GeneralSkin DetectionmemberNedDarkD20-Jul-09 17:02 
The skin detection seems unstable. Which one is mostly advanced among v0~v5 ? Should I do some steps in advance ?
 
As my opinion, v3 is mostly group-intact , but include too many no-skin color like green and red.
 
v5 has too many fracture , contains no green , but red still included in it.
 
Will this algorithm be still developped ?
 
If you want more person picture in differenct environment , try the website "Beauty Clock"
http://www.bijint.com/jp/
 
It will change a picture each minute with one or two girls in it in diff. place.
 
NDark
GeneralRe: Skin DetectionmemberMaxim_Barsuk20-Jul-09 19:30 
Each filter has its own set of rules. The same filter gives different results for different images. Which filter is best? It depends on the color balance of images. If this algorithm is interesting for you, I will to develop it in the future. Thank you! Smile | :)
GeneralRe: Skin DetectionmemberNedDarkD20-Jul-09 20:03 
Actually the special effect like SinCity , color wave , and vignette are interesting to me at mostly, 'cause they are creative filters and different from other image processing application.
 
However , the skin detection is an old problem in this area, and every research group is intenting to find a new , fast , and most importantly , correct solution.
 
NDark
GeneralNew filters.memberMaxim_Barsuk16-Jul-09 18:40 
Please tell me your ideas about creating new interesting (and useful) filters. Thank you! Smile | :)
GeneralRe: New filters.memberWizzard020-Jul-09 12:10 
It would be great to see image comparison filters.
 
Especially those that can recognise where the cropped and resized part of the image lies within the original image.
GeneralRe: New filters.memberpvecchiato5-Sep-09 0:12 
Eliptical vignette ? Instead of rectangular vignette

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130617.1 | Last Updated 17 Jul 2009
Article Copyright 2009 by Maxim_Barsuk
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid