CLAHE Python bindings
[profile/ivi/opencv.git] / modules / imgproc / src / pyramids.cpp
index 5ec5732..e7d315c 100644 (file)
@@ -72,7 +72,7 @@ struct PyrDownVec_32s8u
     {
         if( !checkHardwareSupport(CV_CPU_SSE2) )
             return 0;
-        
+
         int x = 0;
         const int *row0 = src[0], *row1 = src[1], *row2 = src[2], *row3 = src[3], *row4 = src[4];
         __m128i delta = _mm_set1_epi16(128);
@@ -139,7 +139,7 @@ struct PyrDownVec_32f
     {
         if( !checkHardwareSupport(CV_CPU_SSE) )
             return 0;
-        
+
         int x = 0;
         const float *row0 = src[0], *row1 = src[1], *row2 = src[2], *row3 = src[3], *row4 = src[4];
         __m128 _4 = _mm_set1_ps(4.f), _scale = _mm_set1_ps(1.f/256);
@@ -185,7 +185,7 @@ typedef NoVec<float, float> PyrDownVec_32f;
 #endif
 
 template<class CastOp, class VecOp> void
-pyrDown_( const Mat& _src, Mat& _dst )
+pyrDown_( const Mat& _src, Mat& _dst, int borderType )
 {
     const int PD_SZ = 5;
     typedef typename CastOp::type1 WT;
@@ -209,15 +209,15 @@ pyrDown_( const Mat& _src, Mat& _dst )
 
     for( x = 0; x <= PD_SZ+1; x++ )
     {
-        int sx0 = borderInterpolate(x - PD_SZ/2, ssize.width, BORDER_REFLECT_101)*cn;
-        int sx1 = borderInterpolate(x + width0*2 - PD_SZ/2, ssize.width, BORDER_REFLECT_101)*cn;
+        int sx0 = borderInterpolate(x - PD_SZ/2, ssize.width, borderType)*cn;
+        int sx1 = borderInterpolate(x + width0*2 - PD_SZ/2, ssize.width, borderType)*cn;
         for( k = 0; k < cn; k++ )
         {
             tabL[x*cn + k] = sx0 + k;
             tabR[x*cn + k] = sx1 + k;
         }
     }
-    
+
     ssize.width *= cn;
     dsize.width *= cn;
     width0 *= cn;
@@ -234,7 +234,7 @@ pyrDown_( const Mat& _src, Mat& _dst )
         for( ; sy <= y*2 + 2; sy++ )
         {
             WT* row = buf + ((sy - sy0) % PD_SZ)*bufstep;
-            int _sy = borderInterpolate(sy, ssize.height, BORDER_REFLECT_101);
+            int _sy = borderInterpolate(sy, ssize.height, borderType);
             const T* src = (const T*)(_src.data + _src.step*_sy);
             int limit = cn;
             const int* tab = tabL;
@@ -308,7 +308,7 @@ pyrDown_( const Mat& _src, Mat& _dst )
 
 
 template<class CastOp, class VecOp> void
-pyrUp_( const Mat& _src, Mat& _dst )
+pyrUp_( const Mat& _src, Mat& _dst, int)
 {
     const int PU_SZ = 3;
     typedef typename CastOp::type1 WT;
@@ -327,11 +327,10 @@ pyrUp_( const Mat& _src, Mat& _dst )
 
     CV_Assert( std::abs(dsize.width - ssize.width*2) == dsize.width % 2 &&
                std::abs(dsize.height - ssize.height*2) == dsize.height % 2);
-    int k, x, sy0 = -PU_SZ/2, sy = sy0, width0 = ssize.width - 1;
+    int k, x, sy0 = -PU_SZ/2, sy = sy0;
 
     ssize.width *= cn;
     dsize.width *= cn;
-    width0 *= cn;
 
     for( x = 0; x < ssize.width; x++ )
         dtab[x] = (x/cn)*2*cn + x % cn;
@@ -349,7 +348,7 @@ pyrUp_( const Mat& _src, Mat& _dst )
         for( ; sy <= y + 1; sy++ )
         {
             WT* row = buf + ((sy - sy0) % PU_SZ)*bufstep;
-            int _sy = borderInterpolate(sy, ssize.height, BORDER_REFLECT_101);
+            int _sy = borderInterpolate(sy*2, dsize.height, BORDER_REFLECT_101)/2;
             const T* src = (const T*)(_src.data + _src.step*_sy);
 
             if( ssize.width == cn )
@@ -397,16 +396,22 @@ pyrUp_( const Mat& _src, Mat& _dst )
     }
 }
 
-typedef void (*PyrFunc)(const Mat&, Mat&);
+typedef void (*PyrFunc)(const Mat&, Mat&, int);
 
 }
-    
-void cv::pyrDown( const InputArray& _src, OutputArray _dst, const Size& _dsz )
+
+void cv::pyrDown( InputArray _src, OutputArray _dst, const Size& _dsz, int borderType )
 {
     Mat src = _src.getMat();
     Size dsz = _dsz == Size() ? Size((src.cols + 1)/2, (src.rows + 1)/2) : _dsz;
     _dst.create( dsz, src.type() );
     Mat dst = _dst.getMat();
+
+#ifdef HAVE_TEGRA_OPTIMIZATION
+    if(borderType == BORDER_DEFAULT && tegra::pyrDown(src, dst))
+        return;
+#endif
+
     int depth = src.depth();
     PyrFunc func = 0;
     if( depth == CV_8U )
@@ -422,15 +427,21 @@ void cv::pyrDown( const InputArray& _src, OutputArray _dst, const Size& _dsz )
     else
         CV_Error( CV_StsUnsupportedFormat, "" );
 
-    func( src, dst );
+    func( src, dst, borderType );
 }
 
-void cv::pyrUp( const InputArray& _src, OutputArray _dst, const Size& _dsz )
+void cv::pyrUp( InputArray _src, OutputArray _dst, const Size& _dsz, int borderType )
 {
     Mat src = _src.getMat();
     Size dsz = _dsz == Size() ? Size(src.cols*2, src.rows*2) : _dsz;
     _dst.create( dsz, src.type() );
     Mat dst = _dst.getMat();
+
+#ifdef HAVE_TEGRA_OPTIMIZATION
+    if(borderType == BORDER_DEFAULT && tegra::pyrUp(src, dst))
+        return;
+#endif
+
     int depth = src.depth();
     PyrFunc func = 0;
     if( depth == CV_8U )
@@ -446,16 +457,16 @@ void cv::pyrUp( const InputArray& _src, OutputArray _dst, const Size& _dsz )
     else
         CV_Error( CV_StsUnsupportedFormat, "" );
 
-    func( src, dst );
+    func( src, dst, borderType );
 }
 
-void cv::buildPyramid( const InputArray& _src, OutputArrayOfArrays _dst, int maxlevel )
+void cv::buildPyramid( InputArray _src, OutputArrayOfArrays _dst, int maxlevel, int borderType )
 {
     Mat src = _src.getMat();
     _dst.create( maxlevel + 1, 1, 0 );
     _dst.getMatRef(0) = src;
     for( int i = 1; i <= maxlevel; i++ )
-        pyrDown( _dst.getMatRef(i-1), _dst.getMatRef(i) );
+        pyrDown( _dst.getMatRef(i-1), _dst.getMatRef(i), Size(), borderType );
 }
 
 CV_IMPL void cvPyrDown( const void* srcarr, void* dstarr, int _filter )
@@ -480,11 +491,11 @@ cvReleasePyramid( CvMat*** _pyramid, int extra_layers )
 {
     if( !_pyramid )
         CV_Error( CV_StsNullPtr, "" );
-    
+
     if( *_pyramid )
         for( int i = 0; i <= extra_layers; i++ )
             cvReleaseMat( &(*_pyramid)[i] );
-    
+
     cvFree( _pyramid );
 }