diff --git a/modules/imgproc/src/imgwarp.cpp b/modules/imgproc/src/imgwarp.cpp index 5822726eee..1b6147c3b5 100644 --- a/modules/imgproc/src/imgwarp.cpp +++ b/modules/imgproc/src/imgwarp.cpp @@ -6500,7 +6500,7 @@ cvLogPolar( const CvArr* srcarr, CvArr* dstarr, double* exp_tab = _exp_tab; for( rho = 0; rho < dst->width; rho++ ) - exp_tab[rho] = std::exp(rho/M); + exp_tab[rho] = std::exp(rho/M) - 1.0; for( phi = 0; phi < dsize.height; phi++ ) { @@ -6632,7 +6632,7 @@ void cvLinearPolar( const CvArr* srcarr, CvArr* dstarr, for( rho = 0; rho < dsize.width; rho++ ) { - double r = maxRadius*(rho+1)/dsize.width; + double r = maxRadius*rho/dsize.width; double x = r*cp + center.x; double y = r*sp + center.y; @@ -6669,9 +6669,6 @@ void cvLinearPolar( const CvArr* srcarr, CvArr* dstarr, cvCartToPolar( &bufx, &bufy, &bufp, &bufa, 0 ); - for( x = 0; x < dsize.width; x++ ) - bufp.data.fl[x] += 1.f; - for( x = 0; x < dsize.width; x++ ) { double rho = bufp.data.fl[x]*pscale; diff --git a/modules/imgproc/test/test_imgwarp.cpp b/modules/imgproc/test/test_imgwarp.cpp index 0568cbce0a..8246754387 100644 --- a/modules/imgproc/test/test_imgwarp.cpp +++ b/modules/imgproc/test/test_imgwarp.cpp @@ -1744,4 +1744,86 @@ TEST(Imgproc_Remap, DISABLED_memleak) } } + +TEST(Imgproc_linearPolar, identity) +{ + const int N = 33; + Mat in(N, N, CV_8UC3, Scalar(255, 0, 0)); + in(cv::Rect(N/3, N/3, N/3, N/3)).setTo(Scalar::all(255)); + cv::blur(in, in, Size(5, 5)); + cv::blur(in, in, Size(5, 5)); + + Mat src = in.clone(); + Mat dst; + + Rect roi = Rect(0, 0, in.cols - ((N+19)/20), in.rows); + + for (int i = 1; i <= 5; i++) + { + linearPolar(src, dst, + Point2f((N-1) * 0.5f, (N-1) * 0.5f), N * 0.5f, + CV_WARP_FILL_OUTLIERS | CV_INTER_LINEAR | CV_WARP_INVERSE_MAP); + + linearPolar(dst, src, + Point2f((N-1) * 0.5f, (N-1) * 0.5f), N * 0.5f, + CV_WARP_FILL_OUTLIERS | CV_INTER_LINEAR); + + double psnr = cvtest::PSNR(in(roi), src(roi)); + EXPECT_LE(25, psnr) << "iteration=" << i; + } + +#if 0 + Mat all(N*2+2,N*2+2, src.type(), Scalar(0,0,255)); + in.copyTo(all(Rect(0,0,N,N))); + src.copyTo(all(Rect(0,N+1,N,N))); + src.copyTo(all(Rect(N+1,0,N,N))); + dst.copyTo(all(Rect(N+1,N+1,N,N))); + imwrite("linearPolar.png", all); + imshow("input", in); imshow("result", dst); imshow("restore", src); imshow("all", all); + cv::waitKey(); +#endif +} + + +TEST(Imgproc_logPolar, identity) +{ + const int N = 33; + Mat in(N, N, CV_8UC3, Scalar(255, 0, 0)); + in(cv::Rect(N/3, N/3, N/3, N/3)).setTo(Scalar::all(255)); + cv::blur(in, in, Size(5, 5)); + cv::blur(in, in, Size(5, 5)); + + Mat src = in.clone(); + Mat dst; + + Rect roi = Rect(0, 0, in.cols - ((N+19)/20), in.rows); + + double M = N/log(N * 0.5f); + for (int i = 1; i <= 5; i++) + { + logPolar(src, dst, + Point2f((N-1) * 0.5f, (N-1) * 0.5f), M, + CV_WARP_FILL_OUTLIERS | CV_INTER_LINEAR | CV_WARP_INVERSE_MAP); + + logPolar(dst, src, + Point2f((N-1) * 0.5f, (N-1) * 0.5f), M, + CV_WARP_FILL_OUTLIERS | CV_INTER_LINEAR); + + double psnr = cvtest::PSNR(in(roi), src(roi)); + EXPECT_LE(25, psnr) << "iteration=" << i; + } + +#if 0 + Mat all(N*2+2,N*2+2, src.type(), Scalar(0,0,255)); + in.copyTo(all(Rect(0,0,N,N))); + src.copyTo(all(Rect(0,N+1,N,N))); + src.copyTo(all(Rect(N+1,0,N,N))); + dst.copyTo(all(Rect(N+1,N+1,N,N))); + imwrite("logPolar.png", all); + imshow("input", in); imshow("result", dst); imshow("restore", src); imshow("all", all); + cv::waitKey(); +#endif +} + + /* End of file. */