latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*-------------------------------------------------------------------- 00025 * project ....: LTI-Lib: Image Processing and Computer Vision Library 00026 * file .......: ltiCrossCorrelationCoefficient.h 00027 * authors ....: Claudia Goenner 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 26.1.2004 00030 * revisions ..: $Id: ltiCrossCorrelationCoefficient.h,v 1.4 2006/02/07 18:43:10 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_CROSS_CORRELATION_COEFFICIENT_H_ 00034 #define _LTI_CROSS_CORRELATION_COEFFICIENT_H_ 00035 00036 #include "ltiImage.h" 00037 #include "ltiPointList.h" 00038 #include "ltiHomographyEstimatorBase.h" 00039 #include "ltiFeatureExtractor.h" 00040 #include "ltiTransformEstimatorType.h" 00041 00042 namespace lti { 00043 00044 /** 00045 * This class computes the normalized cross correlation coefficient between 00046 * two matrices or vectors. 00047 * 00048 * Some applies allow to transform the points in one source using nearest 00049 * neighbor interpolation prior to computing the cross correlation 00050 * coefficient. This is only done if you specify a homographyEstimatorBase 00051 * in the parameters, though. The transformation is a short cut bypassing 00052 * classes like geometricTransform, which is useful when estimating and 00053 * verifying transformations (coming soon). 00054 * 00055 * CAVEAT: This class could use more iterator arithmetic inside and 00056 * thus is not implemented efficiently everywhere. Some applies 00057 * also are less efficient than they could be because code 00058 * duplication is avoided. 00059 */ 00060 class crossCorrelationCoefficient : public featureExtractor { 00061 public: 00062 /** 00063 * The parameters for the class crossCorrelationCoefficient 00064 */ 00065 class parameters : public featureExtractor::parameters { 00066 00067 //some protected attributes must be accessed by the parent class 00068 friend class crossCorrelationCoefficient; 00069 00070 public: 00071 /** 00072 * Default constructor 00073 */ 00074 parameters(); 00075 00076 /** 00077 * Copy constructor 00078 * @param other the parameters object to be copied 00079 */ 00080 parameters(const parameters& other); 00081 00082 /** 00083 * Destructor 00084 */ 00085 ~parameters(); 00086 00087 /** 00088 * Returns name of this type 00089 */ 00090 const char* getTypeName() const; 00091 00092 /** 00093 * Copy the contents of a parameters object 00094 * @param other the parameters object to be copied 00095 * @return a reference to this parameters object 00096 */ 00097 parameters& copy(const parameters& other); 00098 00099 /** 00100 * Copy the contents of a parameters object 00101 * @param other the parameters object to be copied 00102 * @return a reference to this parameters object 00103 */ 00104 parameters& operator=(const parameters& other); 00105 00106 00107 /** 00108 * Returns a pointer to a clone of the parameters 00109 */ 00110 virtual functor::parameters* clone() const; 00111 00112 /** 00113 * Write the parameters in the given ioHandler 00114 * @param handler the ioHandler to be used 00115 * @param complete if true (the default) the enclosing begin/end will 00116 * be also written, otherwise only the data block will be written. 00117 * @return true if write was successful 00118 */ 00119 virtual bool write(ioHandler& handler,const bool complete=true) const; 00120 00121 /** 00122 * Read the parameters from the given ioHandler 00123 * @param handler the ioHandler to be used 00124 * @param complete if true (the default) the enclosing begin/end will 00125 * be also written, otherwise only the data block will be written. 00126 * @return true if write was successful 00127 */ 00128 virtual bool read(ioHandler& handler,const bool complete=true); 00129 00130 # ifdef _LTI_MSC_6 00131 /** 00132 * This function is required by MSVC only, as a workaround for a 00133 * very awful bug, which exists since MSVC V.4.0, and still by 00134 * V.6.0 with all bugfixes (so called "service packs") remains 00135 * there... This method is also public due to another bug, so please 00136 * NEVER EVER call this method directly: use read() instead 00137 */ 00138 bool readMS(ioHandler& handler,const bool complete=true); 00139 00140 /** 00141 * This function is required by MSVC only, as a workaround for a 00142 * very awful bug, which exists since MSVC V.4.0, and still by 00143 * V.6.0 with all bugfixes (so called "service packs") remains 00144 * there... This method is also public due to another bug, so please 00145 * NEVER EVER call this method directly: use write() instead 00146 */ 00147 bool writeMS(ioHandler& handler,const bool complete=true) const; 00148 # endif 00149 00150 // ------------------------------------------------ 00151 // the parameters 00152 // ------------------------------------------------ 00153 00154 /** 00155 * The size of the window inside which a cross correlation is computed. 00156 * This parameters is only used by applies that utilize control points, 00157 * i.e. do not compute the cross correlation for the entire vector or 00158 * image. Only uneven windows are supported. Event windows are extended 00159 * by one. 00160 * Default: 10. 00161 */ 00162 int window; 00163 00164 /** 00165 * Sets a new transform estimator. The transform estimator is only used 00166 * by applies that pass a transform-vector. If no transform estimator 00167 * is specified then no transform is performed. 00168 * @param name the transform estimator to be used. 00169 */ 00170 void setTransform(eTransformEstimatorType name); 00171 00172 /** 00173 * Sets a new transform estimator. The transform estimator is only used 00174 * by applies that pass a transform-vector. If no transform estimator 00175 * is specified then no transform is performed. 00176 * A copy of the functor will be 00177 * done (so it is useless to change the parameters of the given 00178 * functor instance, because the internal functor will never notice 00179 * the changes done to its "parent"). 00180 * @param method the transform estimator to be used. 00181 */ 00182 void setTransform(const homographyEstimatorBase& method); 00183 00184 /** 00185 * Is a transform estimator allocated ? 00186 * @return true is the transform estimator is allocated 00187 * and false otherwise. 00188 */ 00189 bool existsTransform() const; 00190 00191 /** 00192 * Gets the transform estimator. If no transform estiamtor is allocated 00193 * an exception is thrown. 00194 */ 00195 const homographyEstimatorBase& getTransform() const; 00196 00197 protected: 00198 /** 00199 * The transform estimator. The transform estimator is only used 00200 * by applies that pass a transform-vector. If no transform estimator 00201 * is specified then no transform is performed. 00202 * On default no point set is transformed. 00203 * Default: 0. 00204 */ 00205 homographyEstimatorBase *transform; 00206 }; 00207 00208 /** 00209 * Default constructor 00210 */ 00211 crossCorrelationCoefficient(); 00212 00213 /** 00214 * Construct a functor using the given parameters 00215 */ 00216 crossCorrelationCoefficient(const parameters& par); 00217 00218 /** 00219 * Copy constructor 00220 * @param other the object to be copied 00221 */ 00222 crossCorrelationCoefficient(const crossCorrelationCoefficient& other); 00223 00224 /** 00225 * Destructor 00226 */ 00227 virtual ~crossCorrelationCoefficient(); 00228 00229 /** 00230 * Returns the name of this type ("crossCorrelationCoefficient") 00231 */ 00232 virtual const char* getTypeName() const; 00233 00234 /** 00235 * @name Apply methods with one set of control points 00236 */ 00237 //@{ 00238 00239 /** 00240 * Computes the normalized cross correlation coefficient between two 00241 * channels only considering a window located at each control point. 00242 * This is useful to exlude e.g. homogenous areas. Only positions inside 00243 * both channels are considered. 00244 * If the channels are recorded from different positions it is 00245 * advantageous to supply a transformation vector. Please do no forget 00246 * to define a transformation in the parameters. On default no 00247 * transformation is executed. E.g. the control points and the points 00248 * inside the window have the same coordinates in both channels. 00249 * @param src1 channel8 with the first intensities. 00250 * @param src2 channel8 with the second intensities. 00251 * @param controlPoints pointList with the control points. 00252 * @param transf fvector with the transform by which the 00253 * control points are fit inside the the second image. The 00254 * window in the second image around the control points is 00255 * distorted, too. 00256 * @param dest the computed normalized cross correlation coefficient. 00257 * @return true if apply successful or false otherwise. 00258 */ 00259 bool apply(const matrix<ubyte>& src1, const matrix<ubyte>& src2, 00260 const pointList& controlPoints, 00261 const fvector& transf, float& dest) const; 00262 00263 /** 00264 * Computes the normalized cross correlation coefficient between two 00265 * channels only considering a window located at each control point. 00266 * This is useful to exlude e.g. homogenous areas. Only positions inside 00267 * both channels are considered. 00268 * If the channels are recorded from different positions it is 00269 * advantageous to supply a transformation vector. Please do no forget 00270 * to define a transformation in the parameters. On default no 00271 * transformation is executed. E.g. the control points and the points 00272 * inside the window have the same coordinates in both channels. 00273 * @param src1 channel with the first intensities. 00274 * @param src2 channel with the second intensities. 00275 * @param controlPoints pointList with the control points. 00276 * @param transf fvector with the transform by which the 00277 * control points are fit inside the the second image. The 00278 * window in the second image around the control points is 00279 * distorted, too. 00280 * @param dest the computed normalized cross correlation coefficient. 00281 * @return true if apply successful or false otherwise. 00282 */ 00283 bool apply(const matrix<float>& src1, const matrix<float>& src2, 00284 const pointList& controlPoints, 00285 const fvector& transf, float& dest) const; 00286 00287 /** 00288 * Computes the normalized cross correlation coefficient between two 00289 * channels only considering a window located at each control point. 00290 * This is useful to exlude e.g. homogenous areas. Only positions inside 00291 * both channels are considered. 00292 * If the channels are recorded from different positions it is 00293 * advantageous to supply a transformation vector. Please do no forget 00294 * to define a transformation in the parameters. On default no 00295 * transformation is executed. E.g. the control points and the points 00296 * inside the window have the same coordinates in both channels. 00297 * @param src1 channel8 with the first intensities. 00298 * @param src2 channel8 with the second intensities. 00299 * @param controlPoints pointList with the control points. 00300 * @param transf dvector with the transform by which the 00301 * control points are fit inside the the second image. The 00302 * window in the second image around the control points is 00303 * distorted, too. 00304 * @param dest the computed normalized cross correlation coefficient. 00305 * @return true if apply successful or false otherwise. 00306 */ 00307 bool apply(const matrix<ubyte>& src1, const matrix<ubyte>& src2, 00308 const pointList& controlPoints, 00309 const dvector& transf, double& dest) const; 00310 00311 /** 00312 * Computes the normalized cross correlation coefficient between two 00313 * channels only considering a window located at each control point. 00314 * This is useful to exlude e.g. homogenous areas. Only positions inside 00315 * both channels are considered. 00316 * If the channels are recorded from different positions it is 00317 * advantageous to supply a transformation vector. Please do no forget 00318 * to define a transformation in the parameters. On default no 00319 * transformation is executed. E.g. the control points and the points 00320 * inside the window have the same coordinates in both channels. 00321 * @param src1 channel with the first intensities. 00322 * @param src2 channel with the second intensities. 00323 * @param controlPoints pointList with the control points. 00324 * @param transf dvector with the transform by which the 00325 * control points are fit inside the the second image. The 00326 * window in the second image around the control points is 00327 * distorted, too. 00328 * @param dest the computed normalized cross correlation coefficient. 00329 * @return true if apply successful or false otherwise. 00330 */ 00331 bool apply(const matrix<float>& src1, const matrix<float>& src2, 00332 const pointList& controlPoints, 00333 const dvector& transf, double& dest) const; 00334 00335 //@} 00336 /** 00337 * @name Apply methods with two sets of control points 00338 */ 00339 //@{ 00340 00341 /** 00342 * Computes the normalized cross correlation coefficient between two 00343 * channels only considering a window located at each control point. 00344 * This is useful to exlude e.g. homogenous areas. Only positions inside 00345 * both channels are considered. Please specify the same number of points 00346 * in both point lists. In both channels the same window is used. 00347 * 00348 * @param src1 channel8 with the first intensities. 00349 * @param src2 channel8 with the second intensities. 00350 * @param pts1 pointList with the first control points. 00351 * @param pts2 pointList with the second control points. 00352 * @param dest the computed normalized cross correlation coefficient. 00353 * @return true if apply successful or false otherwise. 00354 */ 00355 bool apply(const matrix<ubyte>& src1, const matrix<ubyte>& src2, 00356 const pointList& pts1, const pointList& pts2, 00357 float& dest) const; 00358 00359 /** 00360 * Computes the normalized cross correlation coefficient between two 00361 * channels only considering a window located at each control point. 00362 * This is useful to exlude e.g. homogenous areas. Only positions inside 00363 * both channels are considered. Please specify the same number of points 00364 * in both point lists. In both channels the same window is used. 00365 * 00366 * @param src1 channel with the first intensities. 00367 * @param src2 channel with the second intensities. 00368 * @param pts1 pointList with the first control points. 00369 * @param pts2 pointList with the second control points. 00370 * @param dest the computed normalized cross correlation coefficient. 00371 * @return true if apply successful or false otherwise. 00372 */ 00373 bool apply(const matrix<float>& src1, const matrix<float>& src2, 00374 const pointList& pts1, const pointList& pts2, 00375 float& dest) const; 00376 00377 /** 00378 * Computes the normalized cross correlation coefficient between two 00379 * channels only considering a window located at each control point. 00380 * This is useful to exlude e.g. homogenous areas. Only positions inside 00381 * both channels are considered. Please specify the same number of points 00382 * in both point lists. In both channels the same window is used. 00383 * 00384 * @param src1 channel8 with the first intensities. 00385 * @param src2 channel8 with the second intensities. 00386 * @param pts1 pointList with the first control points. 00387 * @param pts2 pointList with the second control points. 00388 * @param dest the computed normalized cross correlation coefficient. 00389 * @return true if apply successful or false otherwise. 00390 */ 00391 bool apply(const matrix<ubyte>& src1, const matrix<ubyte>& src2, 00392 const pointList& pts1, const pointList& pts2, 00393 double& dest) const; 00394 00395 /** 00396 * Computes the normalized cross correlation coefficient between two 00397 * channels only considering a window located at each control point. 00398 * This is useful to exlude e.g. homogenous areas. Only positions inside 00399 * both channels are considered. Please specify the same number of points 00400 * in both point lists. In both channels the same window is used. 00401 * 00402 * @param src1 channel with the first intensities. 00403 * @param src2 channel with the second intensities. 00404 * @param pts1 pointList with the first control points. 00405 * @param pts2 pointList with the second control points. 00406 * @param dest the computed normalized cross correlation coefficient. 00407 * @return true if apply successful or false otherwise. 00408 */ 00409 bool apply(const matrix<float>& src1, const matrix<float>& src2, 00410 const pointList& pts1, const pointList& pts2, 00411 double& dest) const; 00412 00413 //@} 00414 /** 00415 * @name Apply methods with two points 00416 */ 00417 //@{ 00418 00419 /** 00420 * Computes the normalized cross correlation coefficient between two 00421 * channels only considering a window located at a single control point. 00422 * Only positions inside both channels are considered. In both channels 00423 * the same window is used. 00424 * 00425 * @param src1 channel8 with the first intensities. 00426 * @param src2 channel8 with the second intensities. 00427 * @param pt1 the first control points. 00428 * @param pt2 the second control points. 00429 * @param dest the computed normalized cross correlation coefficient. 00430 * @return true if apply successful or false otherwise. 00431 */ 00432 bool apply(const matrix<ubyte>& src1, const matrix<ubyte>& src2, 00433 const ipoint& pt1, const ipoint& pt2, 00434 float& dest) const; 00435 00436 /** 00437 * Computes the normalized cross correlation coefficient between two 00438 * channels only considering a window located at a single control point. 00439 * Only positions inside both channels are considered. In both channels 00440 * the same window is used. 00441 * 00442 * @param src1 channel with the first intensities. 00443 * @param src2 channel with the second intensities. 00444 * @param pt1 the first control points. 00445 * @param pt2 the second control points. 00446 * @param dest the computed normalized cross correlation coefficient. 00447 * @return true if apply successful or false otherwise. 00448 */ 00449 bool apply(const matrix<float>& src1, const matrix<float>& src2, 00450 const ipoint& pt1, const ipoint& pt2, 00451 float& dest) const; 00452 00453 /** 00454 * Computes the normalized cross correlation coefficient between two 00455 * channels only considering a window located at a single control point. 00456 * Only positions inside both channels are considered. In both channels 00457 * the same window is used. 00458 * 00459 * @param src1 channel8 with the first intensities. 00460 * @param src2 channel8 with the second intensities. 00461 * @param pt1 the first control points. 00462 * @param pt2 the second control points. 00463 * @param dest the computed normalized cross correlation coefficient. 00464 * @return true if apply successful or false otherwise. 00465 */ 00466 bool apply(const matrix<ubyte>& src1, const matrix<ubyte>& src2, 00467 const ipoint& pt1, const ipoint& pt2, 00468 double& dest) const; 00469 00470 /** 00471 * Computes the normalized cross correlation coefficient between two 00472 * channels only considering a window located at a single control point. 00473 * Only positions inside both channels are considered. In both channels 00474 * the same window is used. 00475 * 00476 * @param src1 channel with the first intensities. 00477 * @param src2 channel with the second intensities. 00478 * @param pt1 the first control points. 00479 * @param pt2 the second control points. 00480 * @param dest the computed normalized cross correlation coefficient. 00481 * @return true if apply successful or false otherwise. 00482 */ 00483 bool apply(const matrix<float>& src1, const matrix<float>& src2, 00484 const ipoint& pt1, const ipoint& pt2, 00485 double& dest) const; 00486 00487 //@} 00488 /** 00489 * @name Apply methods for entire matrices 00490 */ 00491 //@{ 00492 00493 /** 00494 * Computes the normalized cross correlation coefficient between two 00495 * channels only considering all positions inside both channels. 00496 * No window is used. Both channels most have the same size. 00497 * 00498 * @param src1 channel8 with the first intensities. 00499 * @param src2 channel8 with the second intensities. 00500 * @param dest the computed normalized cross correlation coefficient. 00501 * @return true if apply successful or false otherwise. 00502 */ 00503 bool apply(const matrix<ubyte>& src1, const matrix<ubyte>& src2, 00504 float& dest) const; 00505 00506 /** 00507 * Computes the normalized cross correlation coefficient between two 00508 * channels only considering all positions inside both channels. 00509 * No window is used. Both channels most have the same size. 00510 * 00511 * @param src1 channel with the first intensities. 00512 * @param src2 channel with the second intensities. 00513 * @param dest the computed normalized cross correlation coefficient. 00514 * @return true if apply successful or false otherwise. 00515 */ 00516 bool apply(const matrix<float>& src1, const matrix<float>& src2, 00517 float& dest) const; 00518 00519 /** 00520 * Computes the normalized cross correlation coefficient between two 00521 * channels only considering all positions inside both channels. 00522 * No window is used. Both channels most have the same size. 00523 * 00524 * @param src1 channel8 with the first intensities. 00525 * @param src2 channel8 with the second intensities. 00526 * @param dest the computed normalized cross correlation coefficient. 00527 * @return true if apply successful or false otherwise. 00528 */ 00529 bool apply(const matrix<ubyte>& src1, const matrix<ubyte>& src2, 00530 double& dest) const; 00531 00532 /** 00533 * Computes the normalized cross correlation coefficient between two 00534 * channels only considering all positions inside both channels. 00535 * No window is used. Both channels most have the same size. 00536 * 00537 * @param src1 channel with the first intensities. 00538 * @param src2 channel with the second intensities. 00539 * @param dest the computed normalized cross correlation coefficient. 00540 * @return true if apply successful or false otherwise. 00541 */ 00542 bool apply(const matrix<float>& src1, const matrix<float>& src2, 00543 double& dest) const; 00544 00545 //@} 00546 /** 00547 * @name Apply methods for vectors 00548 */ 00549 //@{ 00550 00551 /** 00552 * Computes the normalized cross correlation coefficient between two 00553 * vectors only considering all positions inside both vectors. 00554 * No window is used. Both vectors most have the same size. 00555 * 00556 * @param src1 vector with the first intensities. 00557 * @param src2 vector with the second intensities. 00558 * @param dest the computed normalized cross correlation coefficient. 00559 * @return true if apply successful or false otherwise. 00560 */ 00561 bool apply(const vector<ubyte>& src1, const vector<ubyte>& src2, 00562 float& dest) const; 00563 00564 /** 00565 * Computes the normalized cross correlation coefficient between two 00566 * vectors only considering all positions inside both vectors. 00567 * No window is used. Both vectors most have the same size. 00568 * 00569 * @param src1 vector with the first intensities. 00570 * @param src2 vector with the second intensities. 00571 * @param dest the computed normalized cross correlation coefficient. 00572 * @return true if apply successful or false otherwise. 00573 */ 00574 bool apply(const vector<float>& src1, const vector<float>& src2, 00575 float& dest) const; 00576 00577 /** 00578 * Computes the normalized cross correlation coefficient between two 00579 * vectors only considering all positions inside both vectors. 00580 * No window is used. Both vectors most have the same size. 00581 * 00582 * @param src1 vector with the first intensities. 00583 * @param src2 vector with the second intensities. 00584 * @param dest the computed normalized cross correlation coefficient. 00585 * @return true if apply successful or false otherwise. 00586 */ 00587 bool apply(const vector<ubyte>& src1, const vector<ubyte>& src2, 00588 double& dest) const; 00589 00590 /** 00591 * Computes the normalized cross correlation coefficient between two 00592 * vectors only considering all positions inside both vectors. 00593 * No window is used. Both vectors most have the same size. 00594 * 00595 * @param src1 vector with the first intensities. 00596 * @param src2 vector with the second intensities. 00597 * @param dest the computed normalized cross correlation coefficient. 00598 * @return true if apply successful or false otherwise. 00599 */ 00600 bool apply(const vector<float>& src1, const vector<float>& src2, 00601 double& dest) const; 00602 00603 //@} 00604 00605 /** 00606 * Copy data of "other" functor. 00607 * @param other the functor to be copied 00608 * @return a reference to this functor object 00609 */ 00610 crossCorrelationCoefficient& 00611 copy(const crossCorrelationCoefficient& other); 00612 00613 /** 00614 * Alias for copy member 00615 * @param other the functor to be copied 00616 * @return a reference to this functor object 00617 */ 00618 crossCorrelationCoefficient& 00619 operator=(const crossCorrelationCoefficient& other); 00620 00621 /** 00622 * Returns a pointer to a clone of this functor. 00623 */ 00624 virtual functor* clone() const; 00625 00626 /** 00627 * Returns used parameters 00628 */ 00629 const parameters& getParameters() const; 00630 00631 }; 00632 } 00633 00634 #endif