1 /*M///////////////////////////////////////////////////////////////////////////////////////
\r
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
\r
5 // By downloading, copying, installing or using the software you agree to this license.
\r
6 // If you do not agree to this license, do not download, install,
\r
7 // copy or use the software.
\r
10 // Intel License Agreement
\r
11 // For Open Source Computer Vision Library
\r
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
\r
14 // Third party copyrights are property of their respective owners.
\r
16 // Redistribution and use in source and binary forms, with or without modification,
\r
17 // are permitted provided that the following conditions are met:
\r
19 // * Redistribution's of source code must retain the above copyright notice,
\r
20 // this list of conditions and the following disclaimer.
\r
22 // * Redistribution's in binary form must reproduce the above copyright notice,
\r
23 // this list of conditions and the following disclaimer in the documentation
\r
24 // and/or other materials provided with the distribution.
\r
26 // * The name of Intel Corporation may not be used to endorse or promote products
\r
27 // derived from this software without specific prior written permission.
\r
29 // This software is provided by the copyright holders and contributors "as is" and
\r
30 // any express or implied warranties, including, but not limited to, the implied
\r
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
\r
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
\r
33 // indirect, incidental, special, exemplary, or consequential damages
\r
34 // (including, but not limited to, procurement of substitute goods or services;
\r
35 // loss of use, data, or profits; or business interruption) however caused
\r
36 // and on any theory of liability, whether in contract, strict liability,
\r
37 // or tort (including negligence or otherwise) arising in any way out of
\r
38 // the use of this software, even if advised of the possibility of such damage.
\r
42 #include "precomp.hpp"
\r
46 ///////////////////////////////////////////////////////////////////
\r
47 // Gold implementation
\r
51 template <typename T, template <typename> class Interpolator>
\r
52 void resizeImpl(const cv::Mat& src, cv::Mat& dst, double fx, double fy)
\r
54 const int cn = src.channels();
\r
56 cv::Size dsize(cv::saturate_cast<int>(src.cols * fx), cv::saturate_cast<int>(src.rows * fy));
\r
58 dst.create(dsize, src.type());
\r
60 float ifx = static_cast<float>(1.0 / fx);
\r
61 float ify = static_cast<float>(1.0 / fy);
\r
63 for (int y = 0; y < dsize.height; ++y)
\r
65 for (int x = 0; x < dsize.width; ++x)
\r
67 for (int c = 0; c < cn; ++c)
\r
68 dst.at<T>(y, x * cn + c) = Interpolator<T>::getValue(src, y * ify, x * ifx, c, cv::BORDER_REPLICATE);
\r
73 void resizeGold(const cv::Mat& src, cv::Mat& dst, double fx, double fy, int interpolation)
\r
75 typedef void (*func_t)(const cv::Mat& src, cv::Mat& dst, double fx, double fy);
\r
77 static const func_t nearest_funcs[] =
\r
79 resizeImpl<unsigned char, NearestInterpolator>,
\r
80 resizeImpl<signed char, NearestInterpolator>,
\r
81 resizeImpl<unsigned short, NearestInterpolator>,
\r
82 resizeImpl<short, NearestInterpolator>,
\r
83 resizeImpl<int, NearestInterpolator>,
\r
84 resizeImpl<float, NearestInterpolator>
\r
88 static const func_t linear_funcs[] =
\r
90 resizeImpl<unsigned char, LinearInterpolator>,
\r
91 resizeImpl<signed char, LinearInterpolator>,
\r
92 resizeImpl<unsigned short, LinearInterpolator>,
\r
93 resizeImpl<short, LinearInterpolator>,
\r
94 resizeImpl<int, LinearInterpolator>,
\r
95 resizeImpl<float, LinearInterpolator>
\r
98 static const func_t cubic_funcs[] =
\r
100 resizeImpl<unsigned char, CubicInterpolator>,
\r
101 resizeImpl<signed char, CubicInterpolator>,
\r
102 resizeImpl<unsigned short, CubicInterpolator>,
\r
103 resizeImpl<short, CubicInterpolator>,
\r
104 resizeImpl<int, CubicInterpolator>,
\r
105 resizeImpl<float, CubicInterpolator>
\r
108 static const func_t* funcs[] = {nearest_funcs, linear_funcs, cubic_funcs};
\r
110 funcs[interpolation][src.depth()](src, dst, fx, fy);
\r
114 ///////////////////////////////////////////////////////////////////
\r
117 PARAM_TEST_CASE(Resize, cv::gpu::DeviceInfo, cv::Size, MatType, double, Interpolation, UseRoi)
\r
119 cv::gpu::DeviceInfo devInfo;
\r
126 virtual void SetUp()
\r
128 devInfo = GET_PARAM(0);
\r
129 size = GET_PARAM(1);
\r
130 type = GET_PARAM(2);
\r
131 coeff = GET_PARAM(3);
\r
132 interpolation = GET_PARAM(4);
\r
133 useRoi = GET_PARAM(5);
\r
135 cv::gpu::setDevice(devInfo.deviceID());
\r
139 TEST_P(Resize, Accuracy)
\r
141 cv::Mat src = randomMat(size, type);
\r
143 cv::gpu::GpuMat dst = createMat(cv::Size(cv::saturate_cast<int>(src.cols * coeff), cv::saturate_cast<int>(src.rows * coeff)), type, useRoi);
\r
144 cv::gpu::resize(loadMat(src, useRoi), dst, cv::Size(), coeff, coeff, interpolation);
\r
147 resizeGold(src, dst_gold, coeff, coeff, interpolation);
\r
149 EXPECT_MAT_NEAR(dst_gold, dst, src.depth() == CV_32F ? 1e-2 : 1.0);
\r
152 INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Resize, testing::Combine(
\r
155 testing::Values(MatType(CV_8UC3), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
\r
156 testing::Values(0.3, 0.5, 1.5, 2.0),
\r
157 testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC)),
\r
162 PARAM_TEST_CASE(ResizeArea, cv::gpu::DeviceInfo, cv::Size, MatType, double, Interpolation, UseRoi)
\r
164 cv::gpu::DeviceInfo devInfo;
\r
171 virtual void SetUp()
\r
173 devInfo = GET_PARAM(0);
\r
174 size = GET_PARAM(1);
\r
175 type = GET_PARAM(2);
\r
176 coeff = GET_PARAM(3);
\r
177 interpolation = GET_PARAM(4);
\r
178 useRoi = GET_PARAM(5);
\r
180 cv::gpu::setDevice(devInfo.deviceID());
\r
184 TEST_P(ResizeArea, Accuracy)
\r
186 cv::Mat src = randomMat(size, type);
\r
188 cv::gpu::GpuMat dst = createMat(cv::Size(cv::saturate_cast<int>(src.cols * coeff), cv::saturate_cast<int>(src.rows * coeff)), type, useRoi);
\r
189 cv::gpu::resize(loadMat(src, useRoi), dst, cv::Size(), coeff, coeff, interpolation);
\r
192 cv::resize(src, dst_cpu, cv::Size(), coeff, coeff, interpolation);
\r
194 EXPECT_MAT_NEAR(dst_cpu, dst, src.depth() == CV_32F ? 1e-2 : 1.0);
\r
197 INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeArea, testing::Combine(
\r
200 testing::Values(MatType(CV_8UC3), MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)),
\r
201 testing::Values(0.3, 0.5),
\r
202 testing::Values(Interpolation(cv::INTER_AREA)),
\r
205 ///////////////////////////////////////////////////////////////////
\r
208 PARAM_TEST_CASE(ResizeNPP, cv::gpu::DeviceInfo, MatType, double, Interpolation)
\r
210 cv::gpu::DeviceInfo devInfo;
\r
215 virtual void SetUp()
\r
217 devInfo = GET_PARAM(0);
\r
218 type = GET_PARAM(1);
\r
219 coeff = GET_PARAM(2);
\r
220 interpolation = GET_PARAM(3);
\r
222 cv::gpu::setDevice(devInfo.deviceID());
\r
226 TEST_P(ResizeNPP, Accuracy)
\r
228 if (type == CV_8UC1 && interpolation == cv::INTER_CUBIC)
\r
231 cv::Mat src = readImageType("stereobp/aloe-L.png", type);
\r
233 cv::gpu::GpuMat dst;
\r
234 cv::gpu::resize(loadMat(src), dst, cv::Size(), coeff, coeff, interpolation);
\r
237 resizeGold(src, dst_gold, coeff, coeff, interpolation);
\r
239 EXPECT_MAT_SIMILAR(dst_gold, dst, 1e-1);
\r
242 INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeNPP, testing::Combine(
\r
244 testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)),
\r
245 testing::Values(0.3, 0.5, 1.5, 2.0),
\r
246 testing::Values(Interpolation(cv::INTER_NEAREST), Interpolation(cv::INTER_LINEAR), Interpolation(cv::INTER_CUBIC))));
\r
248 #endif // HAVE_CUDA
\r