added special function to patch NaN's in image. call this function from bilateralfilt...
authorVadim Pisarevsky <no@email>
Tue, 24 Apr 2012 15:16:21 +0000 (15:16 +0000)
committerVadim Pisarevsky <no@email>
Tue, 24 Apr 2012 15:16:21 +0000 (15:16 +0000)
modules/core/include/opencv2/core/core.hpp
modules/core/src/mathfuncs.cpp
modules/imgproc/src/smooth.cpp

index 12e64a3..f284ac7 100644 (file)
@@ -2214,6 +2214,9 @@ CV_EXPORTS_W void magnitude(InputArray x, InputArray y, OutputArray magnitude);
 //! checks that each matrix element is within the specified range.
 CV_EXPORTS_W bool checkRange(InputArray a, bool quiet=true, CV_OUT Point* pos=0,
                             double minVal=-DBL_MAX, double maxVal=DBL_MAX);
+//! converts NaN's to the given number
+CV_EXPORTS_W void patchNaNs(InputOutputArray a, double val=0);
+    
 //! implements generalized matrix product algorithm GEMM from BLAS
 CV_EXPORTS_W void gemm(InputArray src1, InputArray src2, double alpha,
                        InputArray src3, double gamma, OutputArray dst, int flags=0);
index 0ac641a..9a95019 100644 (file)
@@ -2186,6 +2186,28 @@ bool checkRange(InputArray _src, bool quiet, Point* pt, double minVal, double ma
 }
 
     
+void patchNaNs( InputOutputArray _a, double _val )
+{
+    Mat a = _a.getMat();
+    CV_Assert( a.depth() == CV_32F );
+    
+    const Mat* arrays[] = {&a, 0};
+    int* ptrs[1];
+    NAryMatIterator it(arrays, (uchar**)ptrs);
+    size_t len = it.size*a.channels();
+    Cv32suf val;
+    val.f = (float)_val;
+    
+    for( size_t i = 0; i < it.nplanes; i++, ++it )
+    {
+        int* tptr = ptrs[0];
+        for( size_t j = 0; j < len; j++ )
+            if( (tptr[j] & 0x7fffffff) > 0x7f800000 )
+                tptr[j] = val.i;
+    }
+}
+
+    
 void exp(const float* src, float* dst, int n)
 {
     Exp_32f(src, dst, n);
index 41dda25..e18f3bd 100644 (file)
@@ -1439,6 +1439,7 @@ bilateralFilter_32f( const Mat& src, Mat& dst, int d,
     // temporary copy of the image with borders for easy processing
     Mat temp;
     copyMakeBorder( src, temp, radius, radius, radius, radius, borderType );
+    patchNaNs(temp);
 
     // allocate lookup tables
     vector<float> _space_weight(d*d);