diff --git a/Code/FeatureExtraction/otbFineCorrelationImageFilter.h b/Code/FeatureExtraction/otbFineCorrelationImageFilter.h index 1343192d78ea4daf582ebbfb6d46472632e1db2a..b11d8ca6ad238474f329a91777fcfa056021bd14 100644 --- a/Code/FeatureExtraction/otbFineCorrelationImageFilter.h +++ b/Code/FeatureExtraction/otbFineCorrelationImageFilter.h @@ -204,6 +204,8 @@ private: /** Precision used in subpixel mode */ unsigned int m_SubPixelPrecision; + double m_Epsilon; + }; } // end namespace otb diff --git a/Code/FeatureExtraction/otbFineCorrelationImageFilter.txx b/Code/FeatureExtraction/otbFineCorrelationImageFilter.txx index 373dc5fcb7f1d88dd2485b1a5feb4d78f7bead5f..e6f805356fe394047583cc04599e1cfc4d7a4731 100644 --- a/Code/FeatureExtraction/otbFineCorrelationImageFilter.txx +++ b/Code/FeatureExtraction/otbFineCorrelationImageFilter.txx @@ -29,7 +29,6 @@ namespace otb { - /** * Constructor */ @@ -47,6 +46,9 @@ FineCorrelationImageFilter<TInputImage,T0utputCorrelation,TOutputDeformationFiel // Default interpolator m_Interpolator = itk::LinearInterpolateImageFunction<TInputImage,double>::New(); + + // Epsilon in correlation formula set to e-10 + m_Epsilon = 0.0000000001; } template <class TInputImage, class T0utputCorrelation, class TOutputDeformationField> @@ -216,12 +218,14 @@ FineCorrelationImageFilter<TInputImage,TOutputCorrelation,TOutputDeformationFiel } double res = 0; - if( fSquareSum == 0. || mSquareSum == 0. ) + double denom = fSquareSum*mSquareSum; + + if( denom < m_Epsilon) { - res = itk::NumericTraits<double>::max(); + res = 0; } else - res = crossProductSum/vcl_sqrt(fSquareSum*mSquareSum); + res = crossProductSum/vcl_sqrt(denom); return res; }