title: Illumination normalization in OpenCV
body: <p>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. </p>
  
  <p>1- gamma correction with gamma = 0.2<br>
  2- Difference of Gaussian (DOG) filtering with (sigma0 = 1, sigma1 =2)<br>
  3- contrast equalization (truncation threshold of 10 and compressive component 0.1 is used in the paper)</p>
  
  <p>I use <code>CvPow</code> for gamma correction, <code>CvSmooth</code> for DoG and <code>Threshold()</code> 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.</p>
  
  <p>If someone has done it before or has any idea??</p>
  
  <p>Link to the paper: <a href="http://lear.inrialpes.fr/pubs/2007/TT07/Tan-amfg07a.pdf" rel="noreferrer">http://lear.inrialpes.fr/pubs/2007/TT07/Tan-amfg07a.pdf</a></p>
  
  <p>The code is below: (Python code of Peb Aryan converted to JAVACV)</p>
  
  <pre><code>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);
  }
  </code></pre>
  
  <p>Here is the result of my attempt:</p>
  
  <p><img src="https://i.stack.imgur.com/IFH3x.jpg" alt="My attempt"></p>
  
  <p>And the reference from the paper:</p>
  
  <p><img src="https://i.stack.imgur.com/sWAZi.jpg" alt="enter image description here"></p>