Commit 2ce3606e authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #108 from ludv1x/master

Adaptive manifold filter improvements
parents 38bdd6f3 b1b36cd2
...@@ -64,8 +64,6 @@ public: ...@@ -64,8 +64,6 @@ public:
CV_WRAP virtual void filter(InputArray src, OutputArray dst, int dDepth = -1) = 0; CV_WRAP virtual void filter(InputArray src, OutputArray dst, int dDepth = -1) = 0;
}; };
typedef Ptr<DTFilter> DTFilterPtr;
/*Fabric function for DT filters*/ /*Fabric function for DT filters*/
CV_EXPORTS_W CV_EXPORTS_W
Ptr<DTFilter> createDTFilter(InputArray guide, double sigmaSpatial, double sigmaColor, int mode = DTF_NC, int numIters = 3); Ptr<DTFilter> createDTFilter(InputArray guide, double sigmaSpatial, double sigmaColor, int mode = DTF_NC, int numIters = 3);
......
...@@ -54,19 +54,21 @@ static string getOpenCVExtraDir() ...@@ -54,19 +54,21 @@ static string getOpenCVExtraDir()
return cvtest::TS::ptr()->get_data_path(); return cvtest::TS::ptr()->get_data_path();
} }
static void checkSimilarity(InputArray res, InputArray ref) static void checkSimilarity(InputArray res, InputArray ref, double maxNormInf = 1, double maxNormL2 = 1.0 / 64)
{ {
double normInf = cvtest::norm(res, ref, NORM_INF); double normInf = cvtest::norm(res, ref, NORM_INF);
double normL2 = cvtest::norm(res, ref, NORM_L2) / res.total(); double normL2 = cvtest::norm(res, ref, NORM_L2) / res.total();
EXPECT_LE(normInf, 1); if (maxNormInf >= 0) EXPECT_LE(normInf, maxNormInf);
EXPECT_LE(normL2, 1.0 / 64); if (maxNormL2 >= 0) EXPECT_LE(normL2, maxNormL2);
} }
TEST(AdaptiveManifoldTest, SplatSurfaceAccuracy) TEST(AdaptiveManifoldTest, SplatSurfaceAccuracy)
{ {
RNG rnd(0); RNG rnd(0);
cv::setNumThreads(cv::getNumberOfCPUs());
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
Size sz(rnd.uniform(512, 1024), rnd.uniform(512, 1024)); Size sz(rnd.uniform(512, 1024), rnd.uniform(512, 1024));
...@@ -126,6 +128,8 @@ TEST(AdaptiveManifoldTest, AuthorsReferenceAccuracy) ...@@ -126,6 +128,8 @@ TEST(AdaptiveManifoldTest, AuthorsReferenceAccuracy)
Mat srcImg = imread(getOpenCVExtraDir() + srcImgPath); Mat srcImg = imread(getOpenCVExtraDir() + srcImgPath);
ASSERT_TRUE(!srcImg.empty()); ASSERT_TRUE(!srcImg.empty());
cv::setNumThreads(cv::getNumberOfCPUs());
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
Mat refRes = imread(getOpenCVExtraDir() + refPaths[i]); Mat refRes = imread(getOpenCVExtraDir() + refPaths[i]);
...@@ -190,14 +194,19 @@ TEST_P(AdaptiveManifoldRefImplTest, RefImplAccuracy) ...@@ -190,14 +194,19 @@ TEST_P(AdaptiveManifoldRefImplTest, RefImplAccuracy)
double sigma_r = rnd.uniform(0.1, 0.9); double sigma_r = rnd.uniform(0.1, 0.9);
bool adjust_outliers = (iter % 2 == 0); bool adjust_outliers = (iter % 2 == 0);
cv::setNumThreads(cv::getNumberOfCPUs());
Mat res; Mat res;
amFilter(guide, src, res, sigma_s, sigma_r, adjust_outliers); amFilter(guide, src, res, sigma_s, sigma_r, adjust_outliers);
cv::setNumThreads(1);
Mat resRef; Mat resRef;
Ptr<AdaptiveManifoldFilter> amf = createAMFilterRefImpl(sigma_s, sigma_r, adjust_outliers); Ptr<AdaptiveManifoldFilter> amf = createAMFilterRefImpl(sigma_s, sigma_r, adjust_outliers);
amf->filter(src, resRef, guide); amf->filter(src, resRef, guide);
checkSimilarity(res, resRef); //results of reference implementation may differ on small sigma_s into small isolated region
//due to low single-precision floating point numbers accuracy
//therefore the threshold of inf norm was increased
checkSimilarity(res, resRef, 25);
} }
} }
......
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