Basic Image AlgorithmS Library 2.8.0

LineMatcher.cpp

00001 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
00002 
00003    Copyright (C) 2003, 2004    (see file CONTACTS for details)
00004    Multimediale Systeme der Informationsverarbeitung
00005    Institut fuer Informatik
00006    Christian-Albrechts-Universitaet Kiel
00007 
00008 
00009    BIAS is free software; you can redistribute it and/or modify
00010    it under the terms of the GNU Lesser General Public License as published by
00011    the Free Software Foundation; either version 2.1 of the License, or
00012    (at your option) any later version.
00013    
00014    BIAS is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017    GNU Lesser General Public License for more details.
00018    
00019    You should have received a copy of the GNU Lesser General Public License
00020    along with BIAS; if not, write to the Free Software
00021    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
00022 #include "Base/ImageUtils/Scanline.hh"
00023 #include <float.h>
00024 
00025 template <class StorageType> 
00026 int RegionMatcher::
00027 LineMatcherNCC(const unsigned int p1[2], const unsigned int start2[2], 
00028                const unsigned int end2[2], 
00029                const StorageType **ida1, const StorageType **ida2,
00030                const StorageType **grad1, const StorageType **grad2, 
00031                const unsigned int halfwinsize, 
00032                const unsigned int epsilon,
00033                const double gradientscale, 
00034                unsigned int result[2], 
00035                double& correlation) const
00036 {
00037   int res=0;
00038   Scanline scan(start2, end2, epsilon);
00039   unsigned int next[2];
00040   StorageType grad_threshold=
00041     (StorageType)rint((double)grad1[p1[1]][p1[0]]*gradientscale);
00042   double tmpcorr;
00043 
00044   correlation=-1.1;
00045   while (scan.GetNext(next)){
00046     BIASDOUT(D_REGION_MATCHER_LINE, "point ("<<next[0]<<", "<<next[1]<<")");
00047     if (grad2[next[1]][next[0]]>=grad_threshold){
00048       NCC(p1, next, ida1, ida2, halfwinsize, tmpcorr);
00049 //        cerr << "p1 ("<<p1[0]<<", "<<p1[1]<<")\tnext ("<<next[0]<<", "
00050 //         <<next[1]<<")\tcorr: "<<tmpcorr<<endl;
00051       BIASDOUT(D_REGION_MATCHER_LINE, "gradient is big enough "
00052            <<(int)(grad2[next[1]][next[0]])<<" > "<<gradientscale<<" * "
00053            <<(int)(grad1[p1[1]][p1[0]])<<"\tcorrelation: "<<tmpcorr);
00054       if (tmpcorr>correlation){ 
00055     result[0]=next[0];
00056     result[1]=next[1];
00057     correlation=tmpcorr;
00058       }
00059     } else { // if (grad2[next[1]][next[0]]>grad_threshold){
00060       BIASDOUT(D_REGION_MATCHER_LINE, "gradient too small "
00061            <<(int)(grad2[next[1]][next[0]])<<" <= "<<gradientscale<<"*"
00062            <<(int)(grad1[p1[1]][p1[0]])<<" = "<<(int)grad_threshold);
00063     }
00064   } // while
00065   if (correlation<-1.0) res=-1;
00066 
00067   return res;
00068 }
00069 
00070 
00071 template <class StorageType> int 
00072 RegionMatcher::
00073 LineMatcherSAD(const unsigned int p1[2], const unsigned int start2[2], 
00074                const unsigned int end2[2], 
00075                const StorageType **ida1, const StorageType **ida2,
00076                const StorageType **grad1, const StorageType **grad2, 
00077                const unsigned int halfwinsize, const unsigned int epsilon,
00078                const double gradientscale, unsigned int result[2], 
00079                double& sad)const 
00080 {
00081   int res=0;
00082   Scanline scan(start2, end2, epsilon);
00083   unsigned int next[2];
00084   StorageType grad_threshold=
00085     (StorageType)rint((double)grad1[p1[1]][p1[0]]*gradientscale);
00086   double tmpcorr;
00087 
00088   sad=DBL_MAX;
00089   while (scan.GetNext(next)){
00090     BIASDOUT(D_REGION_MATCHER_LINE, "point ("<<next[0]<<", "<<next[1]<<")");
00091     if (grad2[next[1]][next[0]]>=grad_threshold){
00092       SAD(p1, next, ida1, ida2, halfwinsize, tmpcorr);
00093 //        cerr << "p1 ("<<p1[0]<<", "<<p1[1]<<")\tnext ("<<next[0]<<", "
00094 //         <<next[1]<<")\tcorr: "<<tmpcorr<<endl;
00095       BIASDOUT(D_REGION_MATCHER_LINE, "gradient is big enough "
00096            <<(int)(grad2[next[1]][next[0]])<<" > "<<gradientscale<<" * "
00097            <<(int)(grad1[p1[1]][p1[0]])<<"\tsad: "<<tmpcorr);
00098       if (tmpcorr<sad){ 
00099     result[0]=next[0];
00100     result[1]=next[1];
00101     sad=tmpcorr;
00102       }
00103     } else { // if (grad2[next[1]][next[0]]>grad_threshold){
00104       BIASDOUT(D_REGION_MATCHER_LINE, "gradient too small "
00105            <<(int)(grad2[next[1]][next[0]])<<" <= "<<gradientscale<<"*"
00106            <<(int)(grad1[p1[1]][p1[0]])<<" = "<<(int)grad_threshold);
00107     }
00108   } // while
00109   if (sad==DBL_MAX) res=-1;
00110 
00111   return res;
00112 }
00113 
00114 
00115 template <class StorageType> int 
00116 RegionMatcher::
00117 LineMatcherSSD(const unsigned int p1[2], const unsigned int start2[2], 
00118                const unsigned int end2[2], 
00119                const StorageType **ida1, const StorageType **ida2,
00120                const StorageType **grad1, const StorageType **grad2, 
00121                const unsigned int halfwinsize, const unsigned int epsilon,
00122                const double gradientscale, unsigned int result[2], 
00123                double& ssd)const 
00124 {
00125   int res=0;
00126   Scanline scan(start2, end2, epsilon);
00127   unsigned int next[2];
00128   StorageType grad_threshold=
00129     (StorageType)rint((double)grad1[p1[1]][p1[0]]*gradientscale);
00130   double tmpcorr;
00131 
00132   ssd=DBL_MAX;
00133   while (scan.GetNext(next)){
00134     BIASDOUT(D_REGION_MATCHER_LINE, "point ("<<next[0]<<", "<<next[1]<<")");
00135     if (grad2[next[1]][next[0]]>=grad_threshold){
00136       SSD(p1, next, ida1, ida2, halfwinsize, tmpcorr);
00137 //        cerr << "p1 ("<<p1[0]<<", "<<p1[1]<<")\tnext ("<<next[0]<<", "
00138 //         <<next[1]<<")\tcorr: "<<tmpcorr<<endl;
00139       BIASDOUT(D_REGION_MATCHER_LINE, "gradient is big enough "
00140            <<(int)(grad2[next[1]][next[0]])<<" > "<<gradientscale<<" * "
00141            <<(int)(grad1[p1[1]][p1[0]])<<"\tssd: "<<tmpcorr);
00142       if (tmpcorr<ssd){ 
00143     result[0]=next[0];
00144     result[1]=next[1];
00145     ssd=tmpcorr;
00146       }
00147     } else { // if (grad2[next[1]][next[0]]>grad_threshold){
00148       BIASDOUT(D_REGION_MATCHER_LINE, "gradient too small "
00149            <<(int)(grad2[next[1]][next[0]])<<" <= "<<gradientscale<<"*"
00150            <<(int)(grad1[p1[1]][p1[0]])<<" = "<<(int)grad_threshold);
00151     }
00152   } // while
00153   if (ssd==DBL_MAX) res=-1;
00154 
00155   return res;
00156 }
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends