1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Merge pull request #18053 from Yosshi999:bit-exact-resizeNN

Bit-exact Nearest Neighbor Resizing

* bit exact resizeNN

* change the value of method enum

* add bitexact-nn to ResizeExactTest

* test to compare with non-exact version

* add perf for bit-exact resizenn

* use cvFloor-equivalent

* 1/3 scaling is not stable for floating calculation

* stricter test

* bugfix: broken data in case of 6 or 12bytes elements

* bugfix: broken data in default pix_size

* stricter threshold

* use raw() for floor

* use double instead of int

* follow code reviews

* fewer cases in perf test

* center pixel convention
This commit is contained in:
Yosshi999
2020-08-29 03:20:05 +09:00
committed by GitHub
parent 7ce56b3a47
commit 7495a4722f
6 changed files with 249 additions and 2 deletions
@@ -152,4 +152,89 @@ TEST(Resize_Bitexact, Linear8U)
}
}
PARAM_TEST_CASE(Resize_Bitexact, int)
{
public:
int depth;
virtual void SetUp()
{
depth = GET_PARAM(0);
}
double CountDiff(const Mat& src)
{
Mat dstExact; cv::resize(src, dstExact, Size(), 2, 1, INTER_NEAREST_EXACT);
Mat dstNonExact; cv::resize(src, dstNonExact, Size(), 2, 1, INTER_NEAREST);
return cv::norm(dstExact, dstNonExact, NORM_INF);
}
};
TEST_P(Resize_Bitexact, Nearest8U_vsNonExact)
{
Mat mat_color, mat_gray;
Mat src_color = imread(cvtest::findDataFile("shared/lena.png"));
Mat src_gray; cv::cvtColor(src_color, src_gray, COLOR_BGR2GRAY);
src_color.convertTo(mat_color, depth);
src_gray.convertTo(mat_gray, depth);
EXPECT_EQ(CountDiff(mat_color), 0) << "color, type: " << depth;
EXPECT_EQ(CountDiff(mat_gray), 0) << "gray, type: " << depth;
}
// Now INTER_NEAREST's convention and INTER_NEAREST_EXACT's one are different.
INSTANTIATE_TEST_CASE_P(DISABLED_Imgproc, Resize_Bitexact,
testing::Values(CV_8U, CV_16U, CV_32F, CV_64F)
);
TEST(Resize_Bitexact, Nearest8U)
{
Mat src[6], dst[6];
// 2x decimation
src[0] = (Mat_<uint8_t>(1, 6) << 0, 1, 2, 3, 4, 5);
dst[0] = (Mat_<uint8_t>(1, 3) << 0, 2, 4);
// decimation odd to 1
src[1] = (Mat_<uint8_t>(1, 5) << 0, 1, 2, 3, 4);
dst[1] = (Mat_<uint8_t>(1, 1) << 2);
// decimation n*2-1 to n
src[2] = (Mat_<uint8_t>(1, 5) << 0, 1, 2, 3, 4);
dst[2] = (Mat_<uint8_t>(1, 3) << 0, 2, 4);
// decimation n*2+1 to n
src[3] = (Mat_<uint8_t>(1, 5) << 0, 1, 2, 3, 4);
dst[3] = (Mat_<uint8_t>(1, 2) << 1, 3);
// zoom
src[4] = (Mat_<uint8_t>(3, 5) <<
0, 1, 2, 3, 4,
5, 6, 7, 8, 9,
10, 11, 12, 13, 14);
dst[4] = (Mat_<uint8_t>(5, 7) <<
0, 1, 1, 2, 3, 3, 4,
0, 1, 1, 2, 3, 3, 4,
5, 6, 6, 7, 8, 8, 9,
10, 11, 11, 12, 13, 13, 14,
10, 11, 11, 12, 13, 13, 14);
src[5] = (Mat_<uint8_t>(2, 3) <<
0, 1, 2,
3, 4, 5);
dst[5] = (Mat_<uint8_t>(4, 6) <<
0, 0, 1, 1, 2, 2,
0, 0, 1, 1, 2, 2,
3, 3, 4, 4, 5, 5,
3, 3, 4, 4, 5, 5);
for (int i = 0; i < 6; i++)
{
Mat calc;
resize(src[i], calc, dst[i].size(), 0, 0, INTER_NEAREST_EXACT);
EXPECT_EQ(cvtest::norm(calc, dst[i], cv::NORM_L1), 0);
}
}
}} // namespace