Commit 69303258 authored by atinfinity's avatar atinfinity

Added test case of cv::threshold(CV_64F)

parent e4f207c4
...@@ -56,8 +56,8 @@ protected: ...@@ -56,8 +56,8 @@ protected:
void prepare_to_validation( int ); void prepare_to_validation( int );
int thresh_type; int thresh_type;
float thresh_val; double thresh_val;
float max_val; double max_val;
}; };
...@@ -120,7 +120,7 @@ void CV_ThreshTest::run_func() ...@@ -120,7 +120,7 @@ void CV_ThreshTest::run_func()
static void test_threshold( const Mat& _src, Mat& _dst, static void test_threshold( const Mat& _src, Mat& _dst,
float thresh, float maxval, int thresh_type ) double thresh, double maxval, int thresh_type )
{ {
int i, j; int i, j;
int depth = _src.depth(), cn = _src.channels(); int depth = _src.depth(), cn = _src.channels();
...@@ -144,7 +144,7 @@ static void test_threshold( const Mat& _src, Mat& _dst, ...@@ -144,7 +144,7 @@ static void test_threshold( const Mat& _src, Mat& _dst,
imaxval = cvRound(maxval); imaxval = cvRound(maxval);
} }
assert( depth == CV_8U || depth == CV_16S || depth == CV_32F ); assert( depth == CV_8U || depth == CV_16S || depth == CV_32F || depth == CV_64F );
switch( thresh_type ) switch( thresh_type )
{ {
...@@ -165,13 +165,20 @@ static void test_threshold( const Mat& _src, Mat& _dst, ...@@ -165,13 +165,20 @@ static void test_threshold( const Mat& _src, Mat& _dst,
for( j = 0; j < width_n; j++ ) for( j = 0; j < width_n; j++ )
dst[j] = (short)(src[j] > ithresh ? imaxval : 0); dst[j] = (short)(src[j] > ithresh ? imaxval : 0);
} }
else else if( depth == CV_32F )
{ {
const float* src = _src.ptr<float>(i); const float* src = _src.ptr<float>(i);
float* dst = _dst.ptr<float>(i); float* dst = _dst.ptr<float>(i);
for( j = 0; j < width_n; j++ ) for( j = 0; j < width_n; j++ )
dst[j] = src[j] > thresh ? maxval : 0.f; dst[j] = src[j] > thresh ? maxval : 0.f;
} }
else
{
const double* src = _src.ptr<double>(i);
double* dst = _dst.ptr<double>(i);
for( j = 0; j < width_n; j++ )
dst[j] = src[j] > thresh ? maxval : 0.0;
}
} }
break; break;
case CV_THRESH_BINARY_INV: case CV_THRESH_BINARY_INV:
...@@ -191,13 +198,20 @@ static void test_threshold( const Mat& _src, Mat& _dst, ...@@ -191,13 +198,20 @@ static void test_threshold( const Mat& _src, Mat& _dst,
for( j = 0; j < width_n; j++ ) for( j = 0; j < width_n; j++ )
dst[j] = (short)(src[j] > ithresh ? 0 : imaxval); dst[j] = (short)(src[j] > ithresh ? 0 : imaxval);
} }
else else if( depth == CV_32F )
{ {
const float* src = _src.ptr<float>(i); const float* src = _src.ptr<float>(i);
float* dst = _dst.ptr<float>(i); float* dst = _dst.ptr<float>(i);
for( j = 0; j < width_n; j++ ) for( j = 0; j < width_n; j++ )
dst[j] = src[j] > thresh ? 0.f : maxval; dst[j] = src[j] > thresh ? 0.f : maxval;
} }
else
{
const double* src = _src.ptr<double>(i);
double* dst = _dst.ptr<double>(i);
for( j = 0; j < width_n; j++ )
dst[j] = src[j] > thresh ? 0.0 : maxval;
}
} }
break; break;
case CV_THRESH_TRUNC: case CV_THRESH_TRUNC:
...@@ -223,7 +237,7 @@ static void test_threshold( const Mat& _src, Mat& _dst, ...@@ -223,7 +237,7 @@ static void test_threshold( const Mat& _src, Mat& _dst,
dst[j] = (short)(s > ithresh ? ithresh2 : s); dst[j] = (short)(s > ithresh ? ithresh2 : s);
} }
} }
else else if( depth == CV_32F )
{ {
const float* src = _src.ptr<float>(i); const float* src = _src.ptr<float>(i);
float* dst = _dst.ptr<float>(i); float* dst = _dst.ptr<float>(i);
...@@ -233,6 +247,16 @@ static void test_threshold( const Mat& _src, Mat& _dst, ...@@ -233,6 +247,16 @@ static void test_threshold( const Mat& _src, Mat& _dst,
dst[j] = s > thresh ? thresh : s; dst[j] = s > thresh ? thresh : s;
} }
} }
else
{
const double* src = _src.ptr<double>(i);
double* dst = _dst.ptr<double>(i);
for( j = 0; j < width_n; j++ )
{
double s = src[j];
dst[j] = s > thresh ? thresh : s;
}
}
} }
break; break;
case CV_THRESH_TOZERO: case CV_THRESH_TOZERO:
...@@ -258,7 +282,7 @@ static void test_threshold( const Mat& _src, Mat& _dst, ...@@ -258,7 +282,7 @@ static void test_threshold( const Mat& _src, Mat& _dst,
dst[j] = (short)(s > ithresh ? s : 0); dst[j] = (short)(s > ithresh ? s : 0);
} }
} }
else else if( depth == CV_32F )
{ {
const float* src = _src.ptr<float>(i); const float* src = _src.ptr<float>(i);
float* dst = _dst.ptr<float>(i); float* dst = _dst.ptr<float>(i);
...@@ -268,6 +292,16 @@ static void test_threshold( const Mat& _src, Mat& _dst, ...@@ -268,6 +292,16 @@ static void test_threshold( const Mat& _src, Mat& _dst,
dst[j] = s > thresh ? s : 0.f; dst[j] = s > thresh ? s : 0.f;
} }
} }
else
{
const double* src = _src.ptr<double>(i);
double* dst = _dst.ptr<double>(i);
for( j = 0; j < width_n; j++ )
{
double s = src[j];
dst[j] = s > thresh ? s : 0.0;
}
}
} }
break; break;
case CV_THRESH_TOZERO_INV: case CV_THRESH_TOZERO_INV:
...@@ -293,7 +327,7 @@ static void test_threshold( const Mat& _src, Mat& _dst, ...@@ -293,7 +327,7 @@ static void test_threshold( const Mat& _src, Mat& _dst,
dst[j] = (short)(s > ithresh ? 0 : s); dst[j] = (short)(s > ithresh ? 0 : s);
} }
} }
else else if (depth == CV_32F)
{ {
const float* src = _src.ptr<float>(i); const float* src = _src.ptr<float>(i);
float* dst = _dst.ptr<float>(i); float* dst = _dst.ptr<float>(i);
...@@ -303,6 +337,16 @@ static void test_threshold( const Mat& _src, Mat& _dst, ...@@ -303,6 +337,16 @@ static void test_threshold( const Mat& _src, Mat& _dst,
dst[j] = s > thresh ? 0.f : s; dst[j] = s > thresh ? 0.f : s;
} }
} }
else
{
const double* src = _src.ptr<double>(i);
double* dst = _dst.ptr<double>(i);
for( j = 0; j < width_n; j++ )
{
double s = src[j];
dst[j] = s > thresh ? 0.0 : s;
}
}
} }
break; break;
default: default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment