I am working on a face recognition project. I have pictures with different lighting so I need to do illumination normalization. I read a paper which which claims to do illumination normalization. The paper describe the following function and values.
1- gamma correction with gamma = 0.2
2- Difference of Gaussian (DOG) filtering with (sigma0 = 1, sigma1 =2)
3- contrast equalization (truncation threshold of 10 and compressive component 0.1 is used in the paper)
I use CvPow
for gamma correction, CvSmooth
for DoG and Threshold()
with truncate (I don't know how to specify the compression component) but I didn't get the exact image. I used histogram equalization for contrast equalization.
If someone has done it before or has any idea??
Link to the paper: http://lear.inrialpes.fr/pubs/2007/TT07/Tan-amfg07a.pdf
The code is below: (Python code of Peb Aryan converted to JAVACV)
public static IplImage preprocessImg(IplImage img)
{
IplImage gf = cvCreateImage(cvSize(img.width(),img.height()),IPL_DEPTH_32F, 1 );
IplImage gr = IplImage.create(img.width(),img.height(), IPL_DEPTH_8U, 1);
IplImage tr = IplImage.create(img.width(),img.height(), IPL_DEPTH_8U, 1);
IplImage b1 = IplImage.create(img.width(),img.height(),IPL_DEPTH_32F, 1 );
IplImage b2 = IplImage.create(img.width(),img.height(),IPL_DEPTH_32F, 1 );
IplImage b3 = IplImage.create(img.width(),img.height(),IPL_DEPTH_32F, 1 );
CvArr mask = IplImage.create(0,0,IPL_DEPTH_8U, 1 );
cvCvtColor(img, gr, CV_BGR2GRAY);
gamma(gr,gr,gf);
cvSmooth(gf,b1,CV_GAUSSIAN, 1);
cvSmooth(gf,b2,CV_GAUSSIAN,23);
cvSub(b1,b2,b2,mask);
cvConvertScale(b2,gr,127,127);
cvEqualizeHist(gr, gr);
//cvThreshold(gr,tr,255,0,CV_THRESH_TRUNC);
return gr;
}
public static void gamma(IplImage src,IplImage dst, IplImage temp)
{
cvConvertScale(src,temp, 1.0/255,0);
cvPow(temp, temp, 0.2);
cvConvertScale(temp, dst, 255,0);
}
Here is the result of my attempt:
And the reference from the paper:
Don't know if it's too late for you.
In the original paper, DoG was performed by a given sigma, here your radius(23) it too big. Try radius = 7 and radius = 1. About the equalization step, it's different from the paper. you need implement one by yourself.
BTW: some basic functions like cvSmooth was not implemented right for your application. You probably need to implement by yourself to get a better result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With