Click here to Skip to main content
15,867,704 members
Articles / Multimedia / GDI+

Image Processing: Skin Detection, Some Filters and EXIF Tags

Rate me:
Please Sign up or sign in to vote.
4.93/5 (19 votes)
17 Jul 2009CPOL2 min read 87.5K   6K   84   14
Simple algorithms of skin detection and some useful filters

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:

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

You may use these filters very easily:

C#
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:

C#
// 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:

C#
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:

C#
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:

C#
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:

C#
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:

C#
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:

C#
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)


Written By
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

Comments and Discussions

 
Generalgood Pin
haithink28-Jun-15 22:25
haithink28-Jun-15 22:25 
Generalawesome code!! Pin
unnamed50023-Apr-13 8:13
unnamed50023-Apr-13 8:13 
Generalpleez help! Pin
bessso13-May-11 13:31
bessso13-May-11 13:31 
GeneralMy vote of 5 Pin
thatraja1-Nov-10 0:57
professionalthatraja1-Nov-10 0:57 
QuestionWhat Happen Pin
bishtharish17-Aug-10 21:08
bishtharish17-Aug-10 21:08 
GeneralExcelente Pin
nixsus30-May-10 8:01
nixsus30-May-10 8:01 
GeneralNew Skin Detection Techniques Pin
Member 220289128-Nov-09 10:10
Member 220289128-Nov-09 10:10 
GeneralSkin Detection Pin
NedDarkD20-Jul-09 17:02
NedDarkD20-Jul-09 17:02 
GeneralRe: Skin Detection Pin
Maxim_Barsuk20-Jul-09 19:30
Maxim_Barsuk20-Jul-09 19:30 
GeneralRe: Skin Detection Pin
NedDarkD20-Jul-09 20:03
NedDarkD20-Jul-09 20:03 
GeneralNew filters. Pin
Maxim_Barsuk16-Jul-09 18:40
Maxim_Barsuk16-Jul-09 18:40 
GeneralRe: New filters. Pin
Wizzard020-Jul-09 12:10
Wizzard020-Jul-09 12:10 
GeneralRe: New filters. Pin
pvecchiato5-Sep-09 0:12
pvecchiato5-Sep-09 0:12 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.