Click here to Skip to main content
15,886,518 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.9K   6K   84  
Simple algorithms of skin detection and some useful filters
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace RedMatter
{
    /// <summary>
    /// Filter for "Sin City" style.
    /// </summary>
    public class SinCityFilter
    {
        private Bitmap sourceBitmap;

        /// <summary>
        /// Source image.
        /// </summary>
        public Bitmap SourceBitmap
        {
            get { return sourceBitmap; }
            set { sourceBitmap = value; }
        }

        private Bitmap resultImage;

        /// <summary>
        /// Result image.
        /// </summary>
        public Bitmap ResultImage
        {
            get 
            { 
                BuildImage(); 
                return resultImage; 
            }
            set { resultImage = value; }
        }

        private double tolerance = 50;

        /// <summary>
        /// Color tolerance.
        /// </summary>
        public double Tolerance
        {
            get { return tolerance; }
            set { tolerance = value; }
        }

        private Color mainColor;

        /// <summary>
        /// Color for filtering.
        /// </summary>
        public Color MainColor
        {
            get { return mainColor; }
            set { mainColor = value; }
        }


        public SinCityFilter(Bitmap bmp, Color main)
        {
            sourceBitmap = bmp;
            resultImage = new Bitmap(sourceBitmap);
            mainColor = main;
            BuildImage();
        }

        private void BuildImage()
        {
            for (int i = 1; i < sourceBitmap.Width-1; i++)
            {
                for (int j = 1; j < sourceBitmap.Height-1; j++)
                {
                    Color color = sourceBitmap.GetPixel(i, j);
                    double distance = DrawUtils.GetColorDistance(color, mainColor);
                    if (distance < tolerance)
                    {
                        double k = distance / tolerance;
                        resultImage.SetPixel(i, j, DrawUtils.SuperpositionColor(DrawUtils.GetGrayColor(color), color, k));
                    }
                    else
                    {
                        resultImage.SetPixel(i, j, DrawUtils.GetGrayColor(color));
                    }

                }
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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