Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
qdImgZncc.hpp
00001 #ifndef QD_IMGZNCC_HPP
00002 #define QD_IMGZNCC_HPP
00003 
00004 #include <iostream>
00005 #include <fstream>
00006 #include <sstream>
00007 #include <string>
00008 #include <vector>
00009 
00010 #include <math.h>
00011 
00012 #include "kernel/jafarMacro.hpp"
00013 #include "jmath/jblas.hpp"
00014 #include "image/Image.hpp"
00015 
00016 
00017 namespace jafar {
00018 
00019   namespace quasidense {
00020 
00029     struct imgDataZncc {
00030            
00032       jblas::mat iNorm;
00033 
00035       boost::numeric::ublas::matrix<bool> vMask;
00036       
00038       jblas::mat iMean;
00039       
00041       jblas::mat isqMean;
00042       
00043     private :
00044       
00045       // Function used to produce 
00046       // image of intensity mean
00047       //
00048       //========================== 
00049       void lineprocess (jblas::mat &mat_in, unsigned int radius, jblas::mat &mat_out);            
00050       
00051     public :
00052       
00056       imgDataZncc (jafar::image::Image &img , unsigned int rZncc=2, unsigned int rExclu=2, double cmThreshold=0.01) :
00057   iNorm(img.height(),img.width()),
00058   vMask(img.height(),img.width()),
00059   iMean(img.height(),img.width()),
00060   isqMean(img.height(),img.width())
00061       {
00062   JFR_PRECOND( img.depth()==8, "quasidense::imgdata::imgdata : image depth must be equal to 8 ");
00063   
00064   unsigned int nbcol = img.width();
00065   unsigned int nbrow = img.height();
00066 
00067   double cstnormal = 1.0/255.0;
00068   double vmax1,vmax2;
00069 
00070   jblas::mat diffv(nbrow,nbcol);
00071   jblas::mat diffh(nbrow,nbcol);
00072   jblas::mat squaredintensity(nbrow,nbcol);
00073   jblas::mat mattmp(nbcol,nbrow);
00074     
00075   // Normalization, some initializations and confidence measure calculation
00076   //
00077   // 4 Steps : upper left corner / first row / first line / the rest
00078   
00079         iNorm(0,0) = cstnormal*double(img.getPixelValue<unsigned char>(0,0));
00080   vMask(0,0) = false;
00081   iMean(0,0) = 0.0;
00082   isqMean(0,0) = 0.0;
00083   diffv(0,0) = 0.0;
00084   diffh(0,0) = 0.0;
00085 
00086   for (unsigned int cptr=1; cptr<nbrow;cptr++)
00087     {  
00088       iNorm(cptr,0) = cstnormal*double(img.getPixelValue<unsigned char>(0,cptr));
00089       vMask(cptr,0) = false;
00090       iMean(cptr,0) = 0.0;
00091       isqMean(cptr,0) = 0.0;
00092       diffv(cptr,0) = fabs(iNorm(cptr,0)-iNorm(cptr-1,0));
00093       diffh(cptr,0) = 0.0;
00094     }
00095   
00096   for (unsigned int cptc=1; cptc<nbcol;cptc++)
00097     {  
00098       iNorm(0,cptc) = cstnormal*double(img.getPixelValue<unsigned char>(cptc,0));
00099       vMask(0,cptc) = false;
00100       iMean(0,cptc) = 0.0;
00101       isqMean(0,cptc) = 0.0;      
00102       diffv(0,cptc) = 0.0;
00103       diffh(0,cptc) = fabs(iNorm(0,cptc)-iNorm(0,cptc-1));
00104     }
00105   
00106   for (unsigned int cptr = 1; cptr<nbrow; ++cptr)
00107     for (unsigned int cptc = 1; cptc<nbcol; ++cptc)
00108       {
00109         iNorm(cptr,cptc) = cstnormal*double(img.getPixelValue<unsigned char>(cptc,cptr));
00110         vMask(cptr,cptc) = false;
00111         iMean(cptr,cptc) = 0.0;
00112         isqMean(cptr,cptc) = 0.0;
00113         diffv(cptr,cptc) = fabs(iNorm(cptr,cptc)-iNorm(cptr-1,cptc));
00114         diffh(cptr,cptc) = fabs(iNorm(cptr,cptc)-iNorm(cptr,cptc-1));
00115       }
00116   
00117         // Mask update
00118   // We exclude points too near of image sides
00119   for (unsigned int cptr=rExclu;cptr<(nbrow-rExclu);++cptr)
00120     for (unsigned int cptc=rExclu;cptc<(nbcol-rExclu);++cptc)
00121       {
00122         vmax1 = (diffv(cptr,cptc)<diffh(cptr,cptc))?diffh(cptr,cptc):diffv(cptr,cptc);
00123         vmax2 = (diffv(cptr+1,cptc)<diffh(cptr,cptc+1))?diffh(cptr,cptc+1):diffv(cptr+1,cptc);
00124         if ((vmax1>=cmThreshold)||(vmax2>=cmThreshold))
00125     vMask(cptr,cptc) = true;
00126         
00127       } 
00128   
00129   // Radiometry accumulation (mean of intensity)
00130   lineprocess(iNorm,rZncc,mattmp);
00131   lineprocess(mattmp,rZncc,iMean);
00132   
00133   // Radiometry accumulation (mean of squared intensity)
00134   squaredintensity = element_prod(iNorm,iNorm);
00135   lineprocess(squaredintensity,rZncc,mattmp);
00136   lineprocess(mattmp,rZncc,isqMean);
00137 
00138       };
00139       
00140     }; // end of struct imgDataZncc
00141 
00142 
00143  
00153       class imgPairZncc {
00154   
00155       imgDataZncc img1;
00156       
00157       imgDataZncc img2;
00158       
00159       unsigned int rZncc;
00160       
00161       unsigned int winwidth;
00162       
00163       double invNbPix;
00164       
00165     public :
00166 
00171       imgPairZncc (jafar::image::Image &img1_, jafar::image::Image &img2_, unsigned int rZncc_=2, 
00172        unsigned int rExclu_=2, double cmThreshold_=0.01) : 
00173   img1(img1_, rZncc_, rExclu_, cmThreshold_),
00174   img2(img2_, rZncc_, rExclu_, cmThreshold_),
00175   rZncc(rZncc_),        
00176   winwidth(2*rZncc+1),
00177   invNbPix(1.0/pow((double)winwidth,2.0))
00178       {  };      
00179       
00183       bool isPointValidinIma1 (int u, int v);
00184       bool isPointValidinIma2 (int u, int v);
00185 
00189       bool isMatchValid (int u1, int v1, int u2, int v2, unsigned int radius);
00190       bool isMatchValid (int u1, int v1, int u2, int v2);
00191 
00195       double matchEval (int u1, int v1, int u2, int v2, unsigned int radius);
00196       double matchEval (int u1, int v1, int u2, int v2);
00197 
00201       void confirmedMatch (int u1, int v1, int u2, int v2)
00202       {
00203   img1.vMask(v1,u1) = false;
00204   img2.vMask(v2,u2) = false;
00205       };
00206       
00207     }; // end of class imgPairZncc
00208             
00209   } // end namespace quasidense
00210 
00211 }// end namespace jafar
00212 
00213 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:25 for Jafar by doxygen 1.7.6.1
LAAS-CNRS