/home/sujithkr/Projects/libface/src/sqi.cpp

Go to the documentation of this file.
00001 /*
00002     ** Copyright (C) 2006 Sujith K.R. All rights reserved.
00003     ** Email: sujith.k.raman@gmail.com,sujithkr@au-kbc.org
00004     
00005     ** Redistribution and use in source and binary forms, with or without
00006     ** modification, are permitted provided that the following conditions
00007     ** are met:
00008     ** 1. Redistributions of source code must retain the above copyright
00009     **    notice, this list of conditions and the following disclaimer.
00010     ** 2. Redistributions in binary form must reproduce the above copyright
00011     **    notice, this list of conditions and the following disclaimer in the
00012     **    documentation and/or other materials provided with the distribution.
00013     ** 3. The name of the author may not be used to endorse or promote products
00014     **    derived from this software without specific prior written permission.
00015     **
00016     ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
00017     ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018     ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00019     ** ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
00020     ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021     ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00022     ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00023     ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00024     ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00025     ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00026     ** SUCH DAMAGE. */
00027 
00028 
00029 #include <libface.h>
00030 
00041 IplImage* SQI(IplImage* inp)
00042 {
00043   int num_filters;
00044   int size[3];
00045         IplImage *ttt;
00046   CvMat *filtered_image[3];
00047   CvMat *qi[3];
00048   CvMat *inp_mat;
00049   CvMat *res;
00050   IplImage *res_img;
00051         int i,j,k;
00052         double  tmp1,tmp2,tmp3;
00053         CvMat *g_ker;
00054         
00055   num_filters=3;
00056 
00057   size[0]=3;
00058   size[1]=9;
00059   size[2]=15;
00060         
00061  
00062   
00063   
00064   inp_mat=IplImage2Mat(inp);
00065   
00066 // cvNamedWindow("ttt",1);
00067  
00068  //cvShowImage("ttt",inp);
00069  //cvWaitKey(0);
00070  
00071   for(i=0;i<num_filters;i++)
00072   {
00073           g_ker=Gaussian(size[i]);
00074          filtered_image[i]=Conv_Weighted_Gaussian(inp,g_ker);
00075         
00076         /*  ttt=Mat2IplImage(filtered_image[i],0);
00077           cvShowImage("ttt",ttt);
00078           cvWaitKey(0);
00079           cvReleaseImage(&ttt);
00080 */
00081           cvReleaseMat(&g_ker);
00082           qi[i]=cvCreateMat(inp_mat->rows,inp_mat->cols,CV_64FC1);
00083           for(j=0;j<inp_mat->rows;j++)
00084           {
00085                   for(k=0;k<inp_mat->cols;k++)
00086                   {
00087                           tmp1=cvmGet(inp_mat,j,k);
00088                           tmp2=cvmGet(filtered_image[i],j,k);
00089                           
00090                          //  if(tmp1==0.0 || tmp2==0.0 )
00091                            //{
00092                                  //  tmp3=0.0;
00093                                    //}
00094                                   // else{
00095                           tmp3=log10((tmp1+1.0)/(tmp2+1.0));
00096                            //}
00097                          // printf("%g *",tmp3);
00098                           cvmSet(qi[i],j,k,tmp3);
00099                           
00100                   }
00101           }
00102           cvReleaseMat(&filtered_image[i]);
00103   }
00104   
00105   res=cvCreateMat(inp_mat->rows,inp_mat->cols,CV_64FC1);
00106   cvSetZero(res);
00107   for(i=0;i<num_filters;i++)
00108   {
00109           for(j=0;j<inp_mat->rows;j++)
00110           {
00111                   for(k=0;k<inp_mat->cols;k++)
00112                   {
00113                           tmp1=cvmGet(qi[i],j,k);
00114                           tmp2=cvmGet(res,j,k);
00115         #ifdef DEBUG
00116                 //       printf("%g * ",tmp1+tmp2);
00117         #endif
00118                           cvmSet(res,j,k,tmp1+tmp2);
00119                   }
00120           }
00121           cvReleaseMat(&qi[i]);
00122           
00123   }
00124   
00125   Scale_Mat(res,255);
00126   res_img=Mat2IplImage(res,0);
00127   
00128   
00129   cvReleaseMat(&res);
00130   
00131   return res_img;
00132 }

Generated on Fri Apr 20 09:54:33 2007 for libface by  doxygen 1.4.6