Click here to Skip to main content
15,880,608 members
Articles / Programming Languages / C#

Photometric Normalisation Algorithms

Rate me:
Please Sign up or sign in to vote.
3.23/5 (18 votes)
14 Nov 2006CPOL1 min read 66.6K   1.8K   23   11
Pre-processing faces images in order to increase the performance of verification and recognition algorithms

Sample Image - normalisation_algorithms.jpg

Output of multiscale retinex algorithm.

Introduction

The variation of illumination conditions of an object can produce large changes in the image plane, significantly impairing the performance of face verification and recognition algorithms. I present three photometric normalisation algorithms for use in pre-processing face images in order to be used in verification and recognition algorithms. Mainly I follow the ideas of paper "A Comparison of Photometric Normalisation Algorithms for Face Verification", James Short, Josef Kittler and Kieron Messer(2004) and "Lighting Normalization Algorithms for Face Verification", Guillaume Heusch, Fabien Cardinaux, Sebastien Marcel(2005). Multiscale retinex method is coded exactly like the theory says. The anisotropic and isotropic smoothing methods have a little modifications but essentially they are the same. If you want to see more details about them, you can see the papers previously mentioned.

Using the Code

You can apply the multiscale retinex method like:

C#
MultiscaleRetinex retinex = new MultiscaleRetinex
	(param.Sigmas, param.Widths, param.FilterSize);
picFiltered.Image = retinex.Apply((Bitmap)bitmap.Clone());

This is the code of multiscale retinex algorithm:

C#
public override unsafe Bitmap Apply(Bitmap bitmap)
{
    int count = sigmas.Length;
    Bitmap bmp;
    double[,] sum = new double[bitmap.Width, bitmap.Height];
    
    for (int i = 0; i < count;i++ )
    {
        bmp = new GaussianBlur(sigmas[i], size).Apply(bitmap);
        sum = SumBitmap(bmp,sum,widths[i]);
    }
    return Normalise(DivBitmap(bitmap, sum));
}

You can apply the isotropic smoothing method like:

C#
IsotropicSmoothing iso = new IsotropicSmoothing(param.Value);
picFiltered.Image = iso.Apply((Bitmap)bitmap.Clone());

This is the code of isotropic smoothing algorithm:

C#
public override unsafe Bitmap Apply(Bitmap bitmap)
{
    Bitmap = bitmap;
    Point size = PixelSize;
    double[,] src = new double[size.X, size.Y];
    bool first = true;
    byte N, S, E, W, A;
    double Lw, Le, Ls, Ln, tmp, min = 0, max = 0;
    
    LockBitmap();
    
    for (int y = 0; y < size.Y ; y++)
    {
        PixelData* pPixel = PixelAt(0, y);
        for (int x = 0; x < size.X ; x++)
        {
            tmp = pPixel->gray;
            
            //Applying the process to all pixels of image except to the borders
            if ((x > 0) && (x < size.X-1) && (y > 0) && (y < size.Y-1))
            {
                //Adjacent neighbouring pixels
                A = pPixel->gray;           //current
                E = PixelAt(x, y+1)->gray;  //east 
                S = PixelAt(x+1, y)->gray;  //south 
                N = PixelAt(x-1, y)->gray;  //north 
                W = PixelAt(x, y-1)->gray;  //west  
                
                //Ld refers to the derivative with respect to 
                //each of the four adjacent neighbouring pixels
                Lw = A - W;
                Le = A - E;
                Ln = A - N;
                Ls = A - S;
                
                //Isotropic smoothing
                tmp = A + smooth * (Ln + Ls + Le + Lw);
            }
            
            src[x, y] = tmp;
            
            //Computing the min and max values from all pixels of image
            if (first) { min = max = tmp; first = false; }
            else
            {
                if (tmp < min) min = tmp;
                else
                    if (tmp > max) max = tmp;
            }
            pPixel++;
        }
    }
    UnlockBitmap();
    return Normalise(src, min, max);
}

Sample Image - example_isotropic.jpg

Output of isotropic smoothing algorithm.

You can apply the anisotropic smoothing method like:

C#
AnisotropicSmoothing anis = new AnisotropicSmoothing(param.Value);
picFiltered.Image = anis.Apply((Bitmap)bitmap.Clone());

This is the code of anisotropic smoothing algorithm:

C#
public override unsafe Bitmap Apply(Bitmap bitmap) 
{
    Bitmap = bitmap;
    Point size = PixelSize;
    double[,] src = new double[size.X,size.Y];
    bool first = true;
    byte N, S, E, W, A;
    double Lw, Le, Ls, Ln, pw, pe, ps, pn, eps = .1, tmp, min = 0, max = 0;
    
    LockBitmap();
    
    for (int y = 0; y < size.Y; y++)
    {
        PixelData* pPixel = PixelAt(0, y);
        for (int x = 0; x < size.X; x++)
        {
            tmp = pPixel->gray;
            
            //Applying the process to all pixels of image except to the borders
            if ((x > 0) && (x < size.X-1) && (y > 0) && (y < size.Y-1))
            {
                //Adjacent neighbouring pixels
                A = pPixel->gray;           //current
                E = PixelAt(x, y+1)->gray;  //east 
                S = PixelAt(x+1, y)->gray;  //south 
                N = PixelAt(x-1, y)->gray;  //north 
                W = PixelAt(x, y-1)->gray;  //west  
                
                //Ld refers to the derivative with respect to 
                //each of the four adjacent neighbouring pixels
                Lw = A - W;
                Le = A - E;
                Ln = A - N;
                Ls = A - S;
                
                //Weber’s contrast inverse
                pw = Math.Min(A, W) / (Math.Abs(A - W) + eps);
                pe = Math.Min(A, E) / (Math.Abs(A - E) + eps);
                pn = Math.Min(A, N) / (Math.Abs(A - N) + eps);
                ps = Math.Min(A, S) / (Math.Abs(A - S) + eps);
                
                //Anisotropic smoothing
                tmp = A + smooth * (Ln * pn + Ls * ps + Le * pe + Lw * pw);
            }
            
            src[x, y] = tmp;
            
            //Computing the min and max values from all pixels of image
            if (first) { min = max = tmp; first = false; }
            else
            {
                if (tmp < min) min = tmp;
                else
                    if (tmp > max) max = tmp;
            }
            pPixel++;
        }
    }
    UnlockBitmap();
    return Normalise(src,min, max);
}

Sample Image - example_anisotropic.jpg

Output of anisotropic smoothing algorithm.

Credits

Versions

  • 1.0 14 Nov 2006

License

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


Written By
Web Developer
Cuba Cuba
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionhow to setup mutiscale retinex config? Pin
poi11922-Nov-12 0:36
poi11922-Nov-12 0:36 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey26-Feb-12 21:46
professionalManoj Kumar Choubey26-Feb-12 21:46 
GeneralWeird output Pin
Tolga Birdal8-Nov-09 5:26
Tolga Birdal8-Nov-09 5:26 
GeneralBit color without loose face details Pin
Ariston Darmayuda22-Mar-07 7:26
Ariston Darmayuda22-Mar-07 7:26 
GeneralRe: Bit color without loose face details Pin
Christian Graus22-Mar-07 7:37
protectorChristian Graus22-Mar-07 7:37 
GeneralRe: Bit color without loose face details Pin
mosquets22-Mar-07 9:51
mosquets22-Mar-07 9:51 
GeneralRe: Bit color without loose face details Pin
Ariston Darmayuda25-Mar-07 3:42
Ariston Darmayuda25-Mar-07 3:42 
GeneralColor Image Pin
japacheco22-Jan-07 10:43
japacheco22-Jan-07 10:43 
GeneralRe: Color Image Pin
mosquets23-Jan-07 4:05
mosquets23-Jan-07 4:05 
QuestionHow can I enhance the original image by the output of Multi Scale Retinex? Pin
Brian Lau3-Dec-06 19:54
Brian Lau3-Dec-06 19:54 
AnswerRe: How can I enhance the original image by the output of Multi Scale Retinex? Pin
mosquets4-Dec-06 4:17
mosquets4-Dec-06 4:17 

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.