test_imgproc.cpp
Go to the documentation of this file.
1 /*
2 * ECVL - European Computer Vision Library
3 * Version: 0.3.4
4 * copyright (c) 2021, Università degli Studi di Modena e Reggio Emilia (UNIMORE), AImageLab
5 * Authors:
6 * Costantino Grana (costantino.grana@unimore.it)
7 * Federico Bolelli (federico.bolelli@unimore.it)
8 * Michele Cancilla (michele.cancilla@unimore.it)
9 * Laura Canalini (laura.canalini@unimore.it)
10 * Stefano Allegretti (stefano.allegretti@unimore.it)
11 * All rights reserved.
12 */
13 
14 #include <vector>
15 
16 #include <gmock/gmock.h>
17 #include <gtest/gtest.h>
18 
19 #include "ecvl/core.h"
20 
21 using namespace ecvl;
22 
23 namespace
24 {
25 class TCore : public ::testing::Test
26 {
27 protected:
28  Image out;
29 
30 #define ECVL_TUPLE(type, ...) \
31  Image g1_##type = Image({ 1, 1, 1 }, DataType::type, "xyc", ColorType::GRAY); \
32  View<DataType::type> g1_##type##_v; \
33  Image g2_##type = Image({ 2, 2, 1 }, DataType::type, "xyc", ColorType::GRAY); \
34  View<DataType::type> g2_##type##_v; \
35  Image rgb2_##type = Image({ 2, 2, 3 }, DataType::type, "xyc", ColorType::RGB); \
36  View<DataType::type> rgb2_##type##_v; \
37 
39 #undef ECVL_TUPLE
40 
41  void SetUp() override
42  {
43  out = Image();
44 
45  #define ECVL_TUPLE(type, ...) \
46  g1_##type##_v = g1_##type; \
47  g1_##type##_v({ 0,0,0 }) = 50; \
48  \
49  g2_##type##_v = g2_##type; \
50  g2_##type##_v({ 0,0,0 }) = 50; g2_##type##_v({ 1,0,0 }) = 32; \
51  g2_##type##_v({ 0,1,0 }) = 14; g2_##type##_v({ 1,1,0 }) = 60; \
52  \
53  rgb2_##type##_v = rgb2_##type; \
54  rgb2_##type##_v({ 0,0,0 }) = 50; rgb2_##type##_v({ 1,0,0 }) = 32; \
55  rgb2_##type##_v({ 0,1,0 }) = 14; rgb2_##type##_v({ 1,1,0 }) = 60; \
56  rgb2_##type##_v({ 0,0,1 }) = 50; rgb2_##type##_v({ 1,0,1 }) = 32; \
57  rgb2_##type##_v({ 0,1,1 }) = 14; rgb2_##type##_v({ 1,1,1 }) = 60; \
58  rgb2_##type##_v({ 0,0,2 }) = 50; rgb2_##type##_v({ 1,0,2 }) = 32; \
59  rgb2_##type##_v({ 0,1,2 }) = 14; rgb2_##type##_v({ 1,1,2 }) = 60; \
60 
62  #undef ECVL_TUPLE
63  }
64 };
65 
66 using Imgproc = TCore;
67 
68 #define ECVL_TUPLE(type, ...) \
69 TEST_F(Imgproc, ResizeDim##type) \
70 { \
71  if (DataType::type != DataType::int64) { \
72  ResizeDim(g1_##type, out, {1, 1}, InterpolationType::nearest); \
73  View<DataType::type> out_v(out); \
74  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
75  EXPECT_THAT(out.dims_, testing::ElementsAre(1, 1, 1)); \
76  \
77  ResizeDim(g2_##type, out, {2, 1}, InterpolationType::nearest); \
78  out_v = out; \
79  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) == 32); \
80  EXPECT_THAT(out.dims_, testing::ElementsAre(2, 1, 1)); \
81  \
82  ResizeDim(rgb2_##type, out, {2, 1}, InterpolationType::nearest); \
83  out_v = out; \
84  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) == 32); \
85  EXPECT_TRUE(out_v({ 0,0,1 }) == 50); EXPECT_TRUE(out_v({ 1,0,1 }) == 32); \
86  EXPECT_TRUE(out_v({ 0,0,2 }) == 50); EXPECT_TRUE(out_v({ 1,0,2 }) == 32); \
87  EXPECT_THAT(out.dims_, testing::ElementsAre(2, 1, 3)); \
88  } \
89  else { \
90  EXPECT_THROW(ResizeDim(g1_##type, out, {1, 1}, InterpolationType::nearest), std::runtime_error); \
91  } \
92 } \
93 \
94 TEST_F(Imgproc, ResizeDimSameDst##type) \
95 { \
96  if (DataType::type != DataType::int64) { \
97  ResizeDim(g1_##type, g1_##type, {1, 1}, InterpolationType::nearest); \
98  View<DataType::type> out_v(g1_##type); \
99  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
100  EXPECT_THAT(out_v.dims_, testing::ElementsAre(1, 1, 1)); \
101  \
102  ResizeDim(g2_##type, g2_##type, {2, 1}, InterpolationType::nearest); \
103  out_v = g2_##type; \
104  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) == 32); \
105  EXPECT_THAT(out_v.dims_, testing::ElementsAre(2, 1, 1)); \
106  \
107  ResizeDim(rgb2_##type, rgb2_##type, {2, 1}, InterpolationType::nearest); \
108  out_v = rgb2_##type; \
109  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) == 32); \
110  EXPECT_TRUE(out_v({ 0,0,1 }) == 50); EXPECT_TRUE(out_v({ 1,0,1 }) == 32); \
111  EXPECT_TRUE(out_v({ 0,0,2 }) == 50); EXPECT_TRUE(out_v({ 1,0,2 }) == 32); \
112  EXPECT_THAT(out_v.dims_, testing::ElementsAre(2, 1, 3)); \
113  } \
114  else { \
115  EXPECT_THROW(ResizeDim(g1_##type, g1_##type, {1, 1}, InterpolationType::nearest), std::runtime_error); \
116  } \
117 } \
118 \
119 TEST_F(Imgproc, ResizeScale##type) \
120 { \
121  if (DataType::type != DataType::int64) { \
122  ResizeScale(g1_##type, out, {1, 1}, InterpolationType::nearest); \
123  View<DataType::type> out_v(out); \
124  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
125  EXPECT_THAT(out.dims_, testing::ElementsAre(1, 1, 1)); \
126  \
127  ResizeScale(g2_##type, out, {1, 0.5}, InterpolationType::nearest); \
128  out_v = out; \
129  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) == 32); \
130  EXPECT_THAT(out.dims_, testing::ElementsAre(2, 1, 1)); \
131  \
132  ResizeScale(rgb2_##type, out, {1, 0.5}, InterpolationType::nearest); \
133  out_v = out; \
134  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) == 32); \
135  EXPECT_TRUE(out_v({ 0,0,1 }) == 50); EXPECT_TRUE(out_v({ 1,0,1 }) == 32); \
136  EXPECT_TRUE(out_v({ 0,0,2 }) == 50); EXPECT_TRUE(out_v({ 1,0,2 }) == 32); \
137  EXPECT_THAT(out.dims_, testing::ElementsAre(2, 1, 3)); \
138  } \
139  else { \
140  EXPECT_THROW(ResizeScale(g1_##type, out, {1, 1}, InterpolationType::nearest), std::runtime_error); \
141  } \
142 } \
143 \
144 TEST_F(Imgproc, ResizeScaleSameDst##type) \
145 { \
146  if (DataType::type != DataType::int64) { \
147  ResizeScale(g1_##type, g1_##type, {1, 1}, InterpolationType::nearest); \
148  View<DataType::type> out_v(g1_##type); \
149  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
150  EXPECT_THAT(out_v.dims_, testing::ElementsAre(1, 1, 1)); \
151  \
152  ResizeScale(g2_##type, g2_##type, {1, 0.5}, InterpolationType::nearest); \
153  out_v = g2_##type; \
154  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) == 32); \
155  EXPECT_THAT(out_v.dims_, testing::ElementsAre(2, 1, 1)); \
156  \
157  ResizeScale(rgb2_##type, rgb2_##type, {1, 0.5}, InterpolationType::nearest); \
158  out_v = rgb2_##type; \
159  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) == 32); \
160  EXPECT_TRUE(out_v({ 0,0,1 }) == 50); EXPECT_TRUE(out_v({ 1,0,1 }) == 32); \
161  EXPECT_TRUE(out_v({ 0,0,2 }) == 50); EXPECT_TRUE(out_v({ 1,0,2 }) == 32); \
162  EXPECT_THAT(out_v.dims_, testing::ElementsAre(2, 1, 3)); \
163  } \
164  else { \
165  EXPECT_THROW(ResizeScale(g1_##type, g1_##type, {1, 1}, InterpolationType::nearest), std::runtime_error); \
166  } \
167 } \
168 \
169 TEST_F(Imgproc, Flip2D##type) \
170 { \
171  Flip2D(g1_##type, out); \
172  View<DataType::type> out_v(out); \
173  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
174  \
175  Flip2D(g2_##type, out); \
176  out_v = out; \
177  EXPECT_TRUE(out_v({ 0,0,0 }) == 14); EXPECT_TRUE(out_v({ 1,0,0 }) == 60); \
178  EXPECT_TRUE(out_v({ 0,1,0 }) == 50); EXPECT_TRUE(out_v({ 1,1,0 }) == 32); \
179  \
180  Flip2D(rgb2_##type, out); \
181  out_v = out; \
182  EXPECT_TRUE(out_v({ 0,0,0 }) == 14); EXPECT_TRUE(out_v({ 1,0,0 }) == 60); \
183  EXPECT_TRUE(out_v({ 0,1,0 }) == 50); EXPECT_TRUE(out_v({ 1,1,0 }) == 32); \
184  EXPECT_TRUE(out_v({ 0,0,1 }) == 14); EXPECT_TRUE(out_v({ 1,0,1 }) == 60); \
185  EXPECT_TRUE(out_v({ 0,1,1 }) == 50); EXPECT_TRUE(out_v({ 1,1,1 }) == 32); \
186  EXPECT_TRUE(out_v({ 0,0,2 }) == 14); EXPECT_TRUE(out_v({ 1,0,2 }) == 60); \
187  EXPECT_TRUE(out_v({ 0,1,2 }) == 50); EXPECT_TRUE(out_v({ 1,1,2 }) == 32); \
188 } \
189 \
190 TEST_F(Imgproc, Flip2DSameDst##type) \
191 { \
192  Flip2D(g1_##type, g1_##type); \
193  View<DataType::type> out_v(g1_##type); \
194  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
195  \
196  Flip2D(g2_##type, g2_##type); \
197  out_v = g2_##type; \
198  EXPECT_TRUE(out_v({ 0,0,0 }) == 14); EXPECT_TRUE(out_v({ 1,0,0 }) == 60); \
199  EXPECT_TRUE(out_v({ 0,1,0 }) == 50); EXPECT_TRUE(out_v({ 1,1,0 }) == 32); \
200  \
201  Flip2D(rgb2_##type, rgb2_##type); \
202  out_v = rgb2_##type; \
203  EXPECT_TRUE(out_v({ 0,0,0 }) == 14); EXPECT_TRUE(out_v({ 1,0,0 }) == 60); \
204  EXPECT_TRUE(out_v({ 0,1,0 }) == 50); EXPECT_TRUE(out_v({ 1,1,0 }) == 32); \
205  EXPECT_TRUE(out_v({ 0,0,1 }) == 14); EXPECT_TRUE(out_v({ 1,0,1 }) == 60); \
206  EXPECT_TRUE(out_v({ 0,1,1 }) == 50); EXPECT_TRUE(out_v({ 1,1,1 }) == 32); \
207  EXPECT_TRUE(out_v({ 0,0,2 }) == 14); EXPECT_TRUE(out_v({ 1,0,2 }) == 60); \
208  EXPECT_TRUE(out_v({ 0,1,2 }) == 50); EXPECT_TRUE(out_v({ 1,1,2 }) == 32); \
209 } \
210 \
211 TEST_F(Imgproc, Mirror2D##type) \
212 { \
213  Mirror2D(g1_##type, out); \
214  View<DataType::type> out_v(out); \
215  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
216  \
217  Mirror2D(g2_##type, out); \
218  out_v = out; \
219  EXPECT_TRUE(out_v({ 0,0,0 }) == 32); EXPECT_TRUE(out_v({ 1,0,0 }) == 50); \
220  EXPECT_TRUE(out_v({ 0,1,0 }) == 60); EXPECT_TRUE(out_v({ 1,1,0 }) == 14); \
221  \
222  Mirror2D(rgb2_##type, out); \
223  out_v = out; \
224  EXPECT_TRUE(out_v({ 0,0,0 }) == 32); EXPECT_TRUE(out_v({ 1,0,0 }) == 50); \
225  EXPECT_TRUE(out_v({ 0,1,0 }) == 60); EXPECT_TRUE(out_v({ 1,1,0 }) == 14); \
226  EXPECT_TRUE(out_v({ 0,0,1 }) == 32); EXPECT_TRUE(out_v({ 1,0,1 }) == 50); \
227  EXPECT_TRUE(out_v({ 0,1,1 }) == 60); EXPECT_TRUE(out_v({ 1,1,1 }) == 14); \
228  EXPECT_TRUE(out_v({ 0,0,2 }) == 32); EXPECT_TRUE(out_v({ 1,0,2 }) == 50); \
229  EXPECT_TRUE(out_v({ 0,1,2 }) == 60); EXPECT_TRUE(out_v({ 1,1,2 }) == 14); \
230 } \
231 \
232 TEST_F(Imgproc, Mirror2DSameDst##type) \
233 { \
234  Mirror2D(g1_##type, g1_##type); \
235  View<DataType::type> out_v(g1_##type); \
236  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
237  \
238  Mirror2D(g2_##type, g2_##type); \
239  out_v = g2_##type; \
240  EXPECT_TRUE(out_v({ 0,0,0 }) == 32); EXPECT_TRUE(out_v({ 1,0,0 }) == 50); \
241  EXPECT_TRUE(out_v({ 0,1,0 }) == 60); EXPECT_TRUE(out_v({ 1,1,0 }) == 14); \
242  \
243  Mirror2D(rgb2_##type, rgb2_##type); \
244  out_v = rgb2_##type; \
245  EXPECT_TRUE(out_v({ 0,0,0 }) == 32); EXPECT_TRUE(out_v({ 1,0,0 }) == 50); \
246  EXPECT_TRUE(out_v({ 0,1,0 }) == 60); EXPECT_TRUE(out_v({ 1,1,0 }) == 14); \
247  EXPECT_TRUE(out_v({ 0,0,1 }) == 32); EXPECT_TRUE(out_v({ 1,0,1 }) == 50); \
248  EXPECT_TRUE(out_v({ 0,1,1 }) == 60); EXPECT_TRUE(out_v({ 1,1,1 }) == 14); \
249  EXPECT_TRUE(out_v({ 0,0,2 }) == 32); EXPECT_TRUE(out_v({ 1,0,2 }) == 50); \
250  EXPECT_TRUE(out_v({ 0,1,2 }) == 60); EXPECT_TRUE(out_v({ 1,1,2 }) == 14); \
251 } \
252 \
253 TEST_F(Imgproc, Threshold##type) \
254 { \
255  Threshold(g1_##type, out, 35, 127, ThresholdingType::BINARY); \
256  View<DataType::type> out_v(out); \
257  EXPECT_TRUE(out_v({ 0,0,0 }) == 127); \
258  \
259  Threshold(g1_##type, out, 35, 127, ThresholdingType::BINARY_INV); \
260  out_v = out; \
261  EXPECT_TRUE(out_v({ 0,0,0 }) == 0); \
262  \
263  Threshold(g2_##type, out, 35, 127, ThresholdingType::BINARY); \
264  out_v = out; \
265  EXPECT_TRUE(out_v({ 0,0,0 }) == 127); EXPECT_TRUE(out_v({ 1,0,0 }) == 0); \
266  EXPECT_TRUE(out_v({ 0,1,0 }) == 0); EXPECT_TRUE(out_v({ 1,1,0 }) == 127); \
267  \
268  Threshold(g2_##type, out, 35, 127, ThresholdingType::BINARY_INV); \
269  out_v = out; \
270  EXPECT_TRUE(out_v({ 0,0,0 }) == 0); EXPECT_TRUE(out_v({ 1,0,0 }) == 127); \
271  EXPECT_TRUE(out_v({ 0,1,0 }) == 127); EXPECT_TRUE(out_v({ 1,1,0 }) == 0); \
272  \
273  Threshold(rgb2_##type, out, 35, 127, ThresholdingType::BINARY); \
274  out_v = out; \
275  EXPECT_TRUE(out_v({ 0,0,0 }) == 127); EXPECT_TRUE(out_v({ 1,0,0 }) == 0); \
276  EXPECT_TRUE(out_v({ 0,1,0 }) == 0); EXPECT_TRUE(out_v({ 1,1,0 }) == 127); \
277  EXPECT_TRUE(out_v({ 0,0,1 }) == 127); EXPECT_TRUE(out_v({ 1,0,1 }) == 0); \
278  EXPECT_TRUE(out_v({ 0,1,1 }) == 0); EXPECT_TRUE(out_v({ 1,1,1 }) == 127); \
279  EXPECT_TRUE(out_v({ 0,0,2 }) == 127); EXPECT_TRUE(out_v({ 1,0,2 }) == 0); \
280  EXPECT_TRUE(out_v({ 0,1,2 }) == 0); EXPECT_TRUE(out_v({ 1,1,2 }) == 127); \
281  \
282  Threshold(rgb2_##type, out, 35, 127, ThresholdingType::BINARY_INV); \
283  out_v = out; \
284  EXPECT_TRUE(out_v({ 0,0,0 }) == 0); EXPECT_TRUE(out_v({ 1,0,0 }) == 127); \
285  EXPECT_TRUE(out_v({ 0,1,0 }) == 127); EXPECT_TRUE(out_v({ 1,1,0 }) == 0); \
286  EXPECT_TRUE(out_v({ 0,0,1 }) == 0); EXPECT_TRUE(out_v({ 1,0,1 }) == 127); \
287  EXPECT_TRUE(out_v({ 0,1,1 }) == 127); EXPECT_TRUE(out_v({ 1,1,1 }) == 0); \
288  EXPECT_TRUE(out_v({ 0,0,2 }) == 0); EXPECT_TRUE(out_v({ 1,0,2 }) == 127); \
289  EXPECT_TRUE(out_v({ 0,1,2 }) == 127); EXPECT_TRUE(out_v({ 1,1,2 }) == 0); \
290 } \
291 \
292 TEST_F(Imgproc, ThresholdSameDst##type) \
293 { \
294  Threshold(g1_##type, g1_##type, 35, 127, ThresholdingType::BINARY); \
295  View<DataType::type> out_v(g1_##type); \
296  EXPECT_TRUE(out_v({ 0,0,0 }) == 127); \
297  \
298  Threshold(g1_##type, g1_##type, 35, 127, ThresholdingType::BINARY_INV); \
299  out_v = g1_##type; \
300  EXPECT_TRUE(out_v({ 0,0,0 }) == 0); \
301  \
302  Threshold(g2_##type, g2_##type, 35, 127, ThresholdingType::BINARY); \
303  out_v = g2_##type; \
304  EXPECT_TRUE(out_v({ 0,0,0 }) == 127); EXPECT_TRUE(out_v({ 1,0,0 }) == 0); \
305  EXPECT_TRUE(out_v({ 0,1,0 }) == 0); EXPECT_TRUE(out_v({ 1,1,0 }) == 127); \
306  \
307  Threshold(g2_##type, g2_##type, 35, 127, ThresholdingType::BINARY_INV); \
308  out_v = g2_##type; \
309  EXPECT_TRUE(out_v({ 0,0,0 }) == 0); EXPECT_TRUE(out_v({ 1,0,0 }) == 127); \
310  EXPECT_TRUE(out_v({ 0,1,0 }) == 127); EXPECT_TRUE(out_v({ 1,1,0 }) == 0); \
311  \
312  Threshold(rgb2_##type, rgb2_##type, 35, 127, ThresholdingType::BINARY); \
313  out_v = rgb2_##type; \
314  EXPECT_TRUE(out_v({ 0,0,0 }) == 127); EXPECT_TRUE(out_v({ 1,0,0 }) == 0); \
315  EXPECT_TRUE(out_v({ 0,1,0 }) == 0); EXPECT_TRUE(out_v({ 1,1,0 }) == 127); \
316  EXPECT_TRUE(out_v({ 0,0,1 }) == 127); EXPECT_TRUE(out_v({ 1,0,1 }) == 0); \
317  EXPECT_TRUE(out_v({ 0,1,1 }) == 0); EXPECT_TRUE(out_v({ 1,1,1 }) == 127); \
318  EXPECT_TRUE(out_v({ 0,0,2 }) == 127); EXPECT_TRUE(out_v({ 1,0,2 }) == 0); \
319  EXPECT_TRUE(out_v({ 0,1,2 }) == 0); EXPECT_TRUE(out_v({ 1,1,2 }) == 127); \
320  \
321  Threshold(rgb2_##type, rgb2_##type, 35, 127, ThresholdingType::BINARY_INV); \
322  out_v = rgb2_##type; \
323  EXPECT_TRUE(out_v({ 0,0,0 }) == 0); EXPECT_TRUE(out_v({ 1,0,0 }) == 127); \
324  EXPECT_TRUE(out_v({ 0,1,0 }) == 127); EXPECT_TRUE(out_v({ 1,1,0 }) == 0); \
325  EXPECT_TRUE(out_v({ 0,0,1 }) == 0); EXPECT_TRUE(out_v({ 1,0,1 }) == 127); \
326  EXPECT_TRUE(out_v({ 0,1,1 }) == 127); EXPECT_TRUE(out_v({ 1,1,1 }) == 0); \
327  EXPECT_TRUE(out_v({ 0,0,2 }) == 0); EXPECT_TRUE(out_v({ 1,0,2 }) == 127); \
328  EXPECT_TRUE(out_v({ 0,1,2 }) == 127); EXPECT_TRUE(out_v({ 1,1,2 }) == 0); \
329 } \
330 \
331 TEST_F(Imgproc, HConcat##type) \
332 { \
333  HConcat({ g1_##type, g1_##type }, out); \
334  View<DataType::type> out_v(out); \
335  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) == 50); \
336  \
337  HConcat({ g2_##type, g2_##type }, out); \
338  out_v = out; \
339  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) = 32); EXPECT_TRUE(out_v({ 2,0,0 }) == 50); EXPECT_TRUE(out_v({ 3,0,0 }) = 32); \
340  EXPECT_TRUE(out_v({ 0,1,0 }) == 14); EXPECT_TRUE(out_v({ 1,1,0 }) = 60); EXPECT_TRUE(out_v({ 2,1,0 }) == 14); EXPECT_TRUE(out_v({ 3,1,0 }) = 60); \
341  \
342  HConcat({ rgb2_##type, rgb2_##type }, out); \
343  out_v = out; \
344  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) = 32); EXPECT_TRUE(out_v({ 2,0,0 }) == 50); EXPECT_TRUE(out_v({ 3,0,0 }) = 32); \
345  EXPECT_TRUE(out_v({ 0,1,0 }) == 14); EXPECT_TRUE(out_v({ 1,1,0 }) = 60); EXPECT_TRUE(out_v({ 2,1,0 }) == 14); EXPECT_TRUE(out_v({ 3,1,0 }) = 60); \
346  EXPECT_TRUE(out_v({ 0,0,1 }) == 50); EXPECT_TRUE(out_v({ 1,0,1 }) = 32); EXPECT_TRUE(out_v({ 2,0,1 }) == 50); EXPECT_TRUE(out_v({ 3,0,1 }) = 32); \
347  EXPECT_TRUE(out_v({ 0,1,1 }) == 14); EXPECT_TRUE(out_v({ 1,1,1 }) = 60); EXPECT_TRUE(out_v({ 2,1,1 }) == 14); EXPECT_TRUE(out_v({ 3,1,1 }) = 60); \
348  EXPECT_TRUE(out_v({ 0,0,2 }) == 50); EXPECT_TRUE(out_v({ 1,0,2 }) = 32); EXPECT_TRUE(out_v({ 2,0,2 }) == 50); EXPECT_TRUE(out_v({ 3,0,2 }) = 32); \
349  EXPECT_TRUE(out_v({ 0,1,2 }) == 14); EXPECT_TRUE(out_v({ 1,1,2 }) = 60); EXPECT_TRUE(out_v({ 2,1,2 }) == 14); EXPECT_TRUE(out_v({ 3,1,2 }) = 60); \
350 } \
351 \
352 TEST_F(Imgproc, HConcatSameDst##type) \
353 { \
354  HConcat({ g1_##type, g1_##type }, g1_##type); \
355  View<DataType::type> out_v(g1_##type); \
356  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) == 50); \
357  \
358  HConcat({ g2_##type, g2_##type }, g2_##type); \
359  out_v = g2_##type; \
360  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) = 32); EXPECT_TRUE(out_v({ 2,0,0 }) == 50); EXPECT_TRUE(out_v({ 3,0,0 }) = 32); \
361  EXPECT_TRUE(out_v({ 0,1,0 }) == 14); EXPECT_TRUE(out_v({ 1,1,0 }) = 60); EXPECT_TRUE(out_v({ 2,1,0 }) == 14); EXPECT_TRUE(out_v({ 3,1,0 }) = 60); \
362  \
363  HConcat({ rgb2_##type, rgb2_##type }, rgb2_##type); \
364  out_v = rgb2_##type; \
365  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) = 32); EXPECT_TRUE(out_v({ 2,0,0 }) == 50); EXPECT_TRUE(out_v({ 3,0,0 }) = 32); \
366  EXPECT_TRUE(out_v({ 0,1,0 }) == 14); EXPECT_TRUE(out_v({ 1,1,0 }) = 60); EXPECT_TRUE(out_v({ 2,1,0 }) == 14); EXPECT_TRUE(out_v({ 3,1,0 }) = 60); \
367  EXPECT_TRUE(out_v({ 0,0,1 }) == 50); EXPECT_TRUE(out_v({ 1,0,1 }) = 32); EXPECT_TRUE(out_v({ 2,0,1 }) == 50); EXPECT_TRUE(out_v({ 3,0,1 }) = 32); \
368  EXPECT_TRUE(out_v({ 0,1,1 }) == 14); EXPECT_TRUE(out_v({ 1,1,1 }) = 60); EXPECT_TRUE(out_v({ 2,1,1 }) == 14); EXPECT_TRUE(out_v({ 3,1,1 }) = 60); \
369  EXPECT_TRUE(out_v({ 0,0,2 }) == 50); EXPECT_TRUE(out_v({ 1,0,2 }) = 32); EXPECT_TRUE(out_v({ 2,0,2 }) == 50); EXPECT_TRUE(out_v({ 3,0,2 }) = 32); \
370  EXPECT_TRUE(out_v({ 0,1,2 }) == 14); EXPECT_TRUE(out_v({ 1,1,2 }) = 60); EXPECT_TRUE(out_v({ 2,1,2 }) == 14); EXPECT_TRUE(out_v({ 3,1,2 }) = 60); \
371 } \
372 \
373 TEST_F(Imgproc, VConcat##type) \
374 { \
375  VConcat({ g1_##type, g1_##type }, out); \
376  View<DataType::type> out_v(out); \
377  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
378  EXPECT_TRUE(out_v({ 0,1,0 }) == 50); \
379  \
380  VConcat({ g2_##type, g2_##type }, out); \
381  out_v = out; \
382  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) = 32); \
383  EXPECT_TRUE(out_v({ 0,1,0 }) == 14); EXPECT_TRUE(out_v({ 1,1,0 }) = 60); \
384  EXPECT_TRUE(out_v({ 0,2,0 }) == 50); EXPECT_TRUE(out_v({ 1,2,0 }) = 32); \
385  EXPECT_TRUE(out_v({ 0,3,0 }) == 14); EXPECT_TRUE(out_v({ 1,3,0 }) = 60); \
386  \
387  VConcat({ rgb2_##type, rgb2_##type }, out); \
388  out_v = out; \
389  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) = 32); \
390  EXPECT_TRUE(out_v({ 0,1,0 }) == 14); EXPECT_TRUE(out_v({ 1,1,0 }) = 60); \
391  EXPECT_TRUE(out_v({ 0,2,0 }) == 50); EXPECT_TRUE(out_v({ 1,2,0 }) = 32); \
392  EXPECT_TRUE(out_v({ 0,3,0 }) == 14); EXPECT_TRUE(out_v({ 1,3,0 }) = 60); \
393  EXPECT_TRUE(out_v({ 0,0,1 }) == 50); EXPECT_TRUE(out_v({ 1,0,1 }) = 32); \
394  EXPECT_TRUE(out_v({ 0,1,1 }) == 14); EXPECT_TRUE(out_v({ 1,1,1 }) = 60); \
395  EXPECT_TRUE(out_v({ 0,2,1 }) == 50); EXPECT_TRUE(out_v({ 1,2,1 }) = 32); \
396  EXPECT_TRUE(out_v({ 0,3,1 }) == 14); EXPECT_TRUE(out_v({ 1,3,1 }) = 60); \
397  EXPECT_TRUE(out_v({ 0,0,2 }) == 50); EXPECT_TRUE(out_v({ 1,0,2 }) = 32); \
398  EXPECT_TRUE(out_v({ 0,1,2 }) == 14); EXPECT_TRUE(out_v({ 1,1,2 }) = 60); \
399  EXPECT_TRUE(out_v({ 0,2,2 }) == 50); EXPECT_TRUE(out_v({ 1,2,2 }) = 32); \
400  EXPECT_TRUE(out_v({ 0,3,2 }) == 14); EXPECT_TRUE(out_v({ 1,3,2 }) = 60); \
401 } \
402 \
403 TEST_F(Imgproc, VConcatSameDst##type) \
404 { \
405  VConcat({ g1_##type, g1_##type }, g1_##type); \
406  View<DataType::type> out_v(g1_##type); \
407  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
408  EXPECT_TRUE(out_v({ 0,1,0 }) == 50); \
409  \
410  VConcat({ g2_##type, g2_##type }, g2_##type); \
411  out_v = g2_##type; \
412  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) = 32); \
413  EXPECT_TRUE(out_v({ 0,1,0 }) == 14); EXPECT_TRUE(out_v({ 1,1,0 }) = 60); \
414  EXPECT_TRUE(out_v({ 0,2,0 }) == 50); EXPECT_TRUE(out_v({ 1,2,0 }) = 32); \
415  EXPECT_TRUE(out_v({ 0,3,0 }) == 14); EXPECT_TRUE(out_v({ 1,3,0 }) = 60); \
416  \
417  VConcat({ rgb2_##type, rgb2_##type }, rgb2_##type); \
418  out_v = rgb2_##type; \
419  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) = 32); \
420  EXPECT_TRUE(out_v({ 0,1,0 }) == 14); EXPECT_TRUE(out_v({ 1,1,0 }) = 60); \
421  EXPECT_TRUE(out_v({ 0,2,0 }) == 50); EXPECT_TRUE(out_v({ 1,2,0 }) = 32); \
422  EXPECT_TRUE(out_v({ 0,3,0 }) == 14); EXPECT_TRUE(out_v({ 1,3,0 }) = 60); \
423  EXPECT_TRUE(out_v({ 0,0,1 }) == 50); EXPECT_TRUE(out_v({ 1,0,1 }) = 32); \
424  EXPECT_TRUE(out_v({ 0,1,1 }) == 14); EXPECT_TRUE(out_v({ 1,1,1 }) = 60); \
425  EXPECT_TRUE(out_v({ 0,2,1 }) == 50); EXPECT_TRUE(out_v({ 1,2,1 }) = 32); \
426  EXPECT_TRUE(out_v({ 0,3,1 }) == 14); EXPECT_TRUE(out_v({ 1,3,1 }) = 60); \
427  EXPECT_TRUE(out_v({ 0,0,2 }) == 50); EXPECT_TRUE(out_v({ 1,0,2 }) = 32); \
428  EXPECT_TRUE(out_v({ 0,1,2 }) == 14); EXPECT_TRUE(out_v({ 1,1,2 }) = 60); \
429  EXPECT_TRUE(out_v({ 0,2,2 }) == 50); EXPECT_TRUE(out_v({ 1,2,2 }) = 32); \
430  EXPECT_TRUE(out_v({ 0,3,2 }) == 14); EXPECT_TRUE(out_v({ 1,3,2 }) = 60); \
431 } \
432 \
433 TEST_F(Imgproc, Transpose##type) \
434 { \
435  Transpose(g1_##type, out); \
436  View<DataType::type> out_v(out); \
437  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
438  \
439  Transpose(g2_##type, out); \
440  out_v = out; \
441  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) == 14); \
442  EXPECT_TRUE(out_v({ 0,1,0 }) == 32); EXPECT_TRUE(out_v({ 1,1,0 }) == 60); \
443  \
444  Transpose(rgb2_##type, out); \
445  out_v = out; \
446  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) == 14); \
447  EXPECT_TRUE(out_v({ 0,1,0 }) == 32); EXPECT_TRUE(out_v({ 1,1,0 }) == 60); \
448  EXPECT_TRUE(out_v({ 0,0,1 }) == 50); EXPECT_TRUE(out_v({ 1,0,1 }) == 14); \
449  EXPECT_TRUE(out_v({ 0,1,1 }) == 32); EXPECT_TRUE(out_v({ 1,1,1 }) == 60); \
450  EXPECT_TRUE(out_v({ 0,0,2 }) == 50); EXPECT_TRUE(out_v({ 1,0,2 }) == 14); \
451  EXPECT_TRUE(out_v({ 0,1,2 }) == 32); EXPECT_TRUE(out_v({ 1,1,2 }) == 60); \
452 } \
453 \
454 TEST_F(Imgproc, TransposeSameDst##type) \
455 { \
456  Transpose(g1_##type, g1_##type); \
457  View<DataType::type> out_v(g1_##type); \
458  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
459  \
460  Transpose(g2_##type, g2_##type); \
461  out_v = g2_##type; \
462  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) == 14); \
463  EXPECT_TRUE(out_v({ 0,1,0 }) == 32); EXPECT_TRUE(out_v({ 1,1,0 }) == 60); \
464  \
465  Transpose(rgb2_##type, rgb2_##type); \
466  out_v = rgb2_##type; \
467  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) == 14); \
468  EXPECT_TRUE(out_v({ 0,1,0 }) == 32); EXPECT_TRUE(out_v({ 1,1,0 }) == 60); \
469  EXPECT_TRUE(out_v({ 0,0,1 }) == 50); EXPECT_TRUE(out_v({ 1,0,1 }) == 14); \
470  EXPECT_TRUE(out_v({ 0,1,1 }) == 32); EXPECT_TRUE(out_v({ 1,1,1 }) == 60); \
471  EXPECT_TRUE(out_v({ 0,0,2 }) == 50); EXPECT_TRUE(out_v({ 1,0,2 }) == 14); \
472  EXPECT_TRUE(out_v({ 0,1,2 }) == 32); EXPECT_TRUE(out_v({ 1,1,2 }) == 60); \
473 } \
474 \
475 TEST_F(Imgproc, GridDistortion##type) \
476 { \
477  if (DataType::type != DataType::int64) { \
478  GridDistortion(g1_##type, out); \
479  View<DataType::type> out_v(out); \
480  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
481  \
482  GridDistortion(g2_##type, out); \
483  out_v = out; \
484  EXPECT_EQ(g2_##type.dims_, out_v.dims_); \
485  EXPECT_EQ(g2_##type.colortype_, out_v.colortype_); \
486  EXPECT_EQ(g2_##type.elemtype_, out_v.elemtype_); \
487  EXPECT_EQ(g2_##type.channels_, out_v.channels_); \
488  \
489  GridDistortion(rgb2_##type, out); \
490  out_v = out; \
491  EXPECT_EQ(rgb2_##type.dims_, out_v.dims_); \
492  EXPECT_EQ(rgb2_##type.colortype_, out_v.colortype_); \
493  EXPECT_EQ(rgb2_##type.elemtype_, out_v.elemtype_); \
494  EXPECT_EQ(rgb2_##type.channels_, out_v.channels_); \
495  } \
496  else { \
497  EXPECT_THROW(GridDistortion(g1_##type, out), std::runtime_error); \
498  } \
499 } \
500 \
501 TEST_F(Imgproc, GridDistortionSameDst##type) \
502 { \
503  if (DataType::type != DataType::int64) { \
504  GridDistortion(g1_##type, g1_##type); \
505  View<DataType::type> out_v(g1_##type); \
506  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
507  \
508  GridDistortion(g2_##type, g2_##type); \
509  out_v = g2_##type; \
510  EXPECT_EQ(g2_##type.dims_, out_v.dims_); \
511  EXPECT_EQ(g2_##type.colortype_, out_v.colortype_); \
512  EXPECT_EQ(g2_##type.elemtype_, out_v.elemtype_); \
513  EXPECT_EQ(g2_##type.channels_, out_v.channels_); \
514  \
515  GridDistortion(rgb2_##type, rgb2_##type); \
516  out_v = rgb2_##type; \
517  EXPECT_EQ(rgb2_##type.dims_, out_v.dims_); \
518  EXPECT_EQ(rgb2_##type.colortype_, out_v.colortype_); \
519  EXPECT_EQ(rgb2_##type.elemtype_, out_v.elemtype_); \
520  EXPECT_EQ(rgb2_##type.channels_, out_v.channels_); \
521  } \
522  else { \
523  EXPECT_THROW(GridDistortion(g1_##type, g1_##type), std::runtime_error); \
524  } \
525 } \
526 \
527 TEST_F(Imgproc, ElasticTransform##type) \
528 { \
529  if (DataType::type != DataType::int64) { \
530  ElasticTransform(g1_##type, out); \
531  View<DataType::type> out_v(out); \
532  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
533  \
534  ElasticTransform(g2_##type, out); \
535  out_v = out; \
536  EXPECT_EQ(g2_##type.dims_, out_v.dims_); \
537  EXPECT_EQ(g2_##type.colortype_, out_v.colortype_); \
538  EXPECT_EQ(g2_##type.elemtype_, out_v.elemtype_); \
539  EXPECT_EQ(g2_##type.channels_, out_v.channels_); \
540  \
541  ElasticTransform(rgb2_##type, out); \
542  out_v = out; \
543  EXPECT_EQ(rgb2_##type.dims_, out_v.dims_); \
544  EXPECT_EQ(rgb2_##type.colortype_, out_v.colortype_); \
545  EXPECT_EQ(rgb2_##type.elemtype_, out_v.elemtype_); \
546  EXPECT_EQ(rgb2_##type.channels_, out_v.channels_); \
547  } \
548  else { \
549  EXPECT_THROW(ElasticTransform(g1_##type, out), std::runtime_error); \
550  } \
551 } \
552 \
553 TEST_F(Imgproc, ElasticTransformSameDst##type) \
554 { \
555  if (DataType::type != DataType::int64) { \
556  ElasticTransform(g1_##type, g1_##type); \
557  View<DataType::type> out_v(g1_##type); \
558  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
559  \
560  ElasticTransform(g2_##type, g2_##type); \
561  out_v = g2_##type; \
562  EXPECT_EQ(g2_##type.dims_, out_v.dims_); \
563  EXPECT_EQ(g2_##type.colortype_, out_v.colortype_); \
564  EXPECT_EQ(g2_##type.elemtype_, out_v.elemtype_); \
565  EXPECT_EQ(g2_##type.channels_, out_v.channels_); \
566  \
567  ElasticTransform(rgb2_##type, rgb2_##type); \
568  out_v = rgb2_##type; \
569  EXPECT_EQ(rgb2_##type.dims_, out_v.dims_); \
570  EXPECT_EQ(rgb2_##type.colortype_, out_v.colortype_); \
571  EXPECT_EQ(rgb2_##type.elemtype_, out_v.elemtype_); \
572  EXPECT_EQ(rgb2_##type.channels_, out_v.channels_); \
573  } \
574  else { \
575  EXPECT_THROW(ElasticTransform(g1_##type, g1_##type), std::runtime_error); \
576  } \
577 } \
578 \
579 TEST_F(Imgproc, OpticalDistortion##type) \
580 { \
581  if (DataType::type != DataType::int64) { \
582  OpticalDistortion(g1_##type, out); \
583  View<DataType::type> out_v(out); \
584  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
585  \
586  OpticalDistortion(g2_##type, out); \
587  out_v = out; \
588  EXPECT_EQ(g2_##type.dims_, out_v.dims_); \
589  EXPECT_EQ(g2_##type.colortype_, out_v.colortype_); \
590  EXPECT_EQ(g2_##type.elemtype_, out_v.elemtype_); \
591  EXPECT_EQ(g2_##type.channels_, out_v.channels_); \
592  \
593  OpticalDistortion(rgb2_##type, out); \
594  out_v = out; \
595  EXPECT_EQ(rgb2_##type.dims_, out_v.dims_); \
596  EXPECT_EQ(rgb2_##type.colortype_, out_v.colortype_); \
597  EXPECT_EQ(rgb2_##type.elemtype_, out_v.elemtype_); \
598  EXPECT_EQ(rgb2_##type.channels_, out_v.channels_); \
599  } \
600  else { \
601  EXPECT_THROW(OpticalDistortion(g1_##type, out), std::runtime_error); \
602  } \
603 } \
604 \
605 TEST_F(Imgproc, OpticalDistortionSameDst##type) \
606 { \
607  if (DataType::type != DataType::int64) { \
608  OpticalDistortion(g1_##type, g1_##type); \
609  View<DataType::type> out_v(g1_##type); \
610  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
611  \
612  OpticalDistortion(g2_##type, g2_##type); \
613  out_v = g2_##type; \
614  EXPECT_EQ(g2_##type.dims_, out_v.dims_); \
615  EXPECT_EQ(g2_##type.colortype_, out_v.colortype_); \
616  EXPECT_EQ(g2_##type.elemtype_, out_v.elemtype_); \
617  EXPECT_EQ(g2_##type.channels_, out_v.channels_); \
618  \
619  OpticalDistortion(rgb2_##type, rgb2_##type); \
620  out_v = rgb2_##type; \
621  EXPECT_EQ(rgb2_##type.dims_, out_v.dims_); \
622  EXPECT_EQ(rgb2_##type.colortype_, out_v.colortype_); \
623  EXPECT_EQ(rgb2_##type.elemtype_, out_v.elemtype_); \
624  EXPECT_EQ(rgb2_##type.channels_, out_v.channels_); \
625  } \
626  else { \
627  EXPECT_THROW(OpticalDistortion(g1_##type, g1_##type), std::runtime_error); \
628  } \
629 }\
630 TEST_F(Imgproc, Salt##type) \
631 { \
632  Salt(g1_##type, out, 0.5, false, 0); \
633  View<DataType::type> out_v(out); \
634  EXPECT_EQ(g1_##type.dims_, out_v.dims_); \
635  EXPECT_EQ(g1_##type.colortype_, out_v.colortype_); \
636  EXPECT_EQ(g1_##type.elemtype_, out_v.elemtype_); \
637  EXPECT_EQ(g1_##type.channels_, out_v.channels_); \
638  \
639  Salt(g2_##type, out, 0.5, false, 0); \
640  out_v = out; \
641  EXPECT_EQ(g2_##type.dims_, out_v.dims_); \
642  EXPECT_EQ(g2_##type.colortype_, out_v.colortype_); \
643  EXPECT_EQ(g2_##type.elemtype_, out_v.elemtype_); \
644  EXPECT_EQ(g2_##type.channels_, out_v.channels_); \
645  \
646  Salt(rgb2_##type, out, 0.5, false, 0); \
647  out_v = out; \
648  EXPECT_EQ(rgb2_##type.dims_, out_v.dims_); \
649  EXPECT_EQ(rgb2_##type.colortype_, out_v.colortype_); \
650  EXPECT_EQ(rgb2_##type.elemtype_, out_v.elemtype_); \
651  EXPECT_EQ(rgb2_##type.channels_, out_v.channels_); \
652 } \
653 \
654 TEST_F(Imgproc, SaltSameDst##type) \
655 { \
656  Salt(g1_##type, g1_##type, 0.5, false, 0); \
657  View<DataType::type> out_v(g1_##type); \
658  EXPECT_EQ(g1_##type.dims_, out_v.dims_); \
659  EXPECT_EQ(g1_##type.colortype_, out_v.colortype_); \
660  EXPECT_EQ(g1_##type.elemtype_, out_v.elemtype_); \
661  EXPECT_EQ(g1_##type.channels_, out_v.channels_); \
662  \
663  Salt(g2_##type, g2_##type, 0.5, false, 0); \
664  out_v = g2_##type; \
665  EXPECT_EQ(g2_##type.dims_, out_v.dims_); \
666  EXPECT_EQ(g2_##type.colortype_, out_v.colortype_); \
667  EXPECT_EQ(g2_##type.elemtype_, out_v.elemtype_); \
668  EXPECT_EQ(g2_##type.channels_, out_v.channels_); \
669  \
670  Salt(rgb2_##type, rgb2_##type, 0.5, false, 0); \
671  out_v = rgb2_##type; \
672  EXPECT_EQ(rgb2_##type.dims_, out_v.dims_); \
673  EXPECT_EQ(rgb2_##type.colortype_, out_v.colortype_); \
674  EXPECT_EQ(rgb2_##type.elemtype_, out_v.elemtype_); \
675  EXPECT_EQ(rgb2_##type.channels_, out_v.channels_); \
676 } \
677 \
678 TEST_F(Imgproc, CCLSameDst##type) \
679 { \
680  if (DataType::type == DataType::uint8) { \
681  Threshold(g1_##type, g1_##type, 35, 255, ThresholdingType::BINARY); \
682  ConnectedComponentsLabeling(g1_##type, g1_##type); \
683  View<DataType::int32> out_v(g1_##type); /* CCL output image is fixed to int32 */ \
684  EXPECT_EQ(g1_##type.dims_, out_v.dims_); \
685  EXPECT_EQ(g1_##type.colortype_, out_v.colortype_); \
686  /*EXPECT_EQ(g1_##type.elemtype_, out_v.elemtype_);*/ \
687  EXPECT_EQ(g1_##type.channels_, out_v.channels_); \
688  EXPECT_TRUE(out_v({ 0,0,0 }) == 1); \
689  \
690  Threshold(g2_##type, g2_##type, 35, 255, ThresholdingType::BINARY); \
691  ConnectedComponentsLabeling(g2_##type, g2_##type); \
692  out_v = g2_##type; \
693  EXPECT_EQ(g2_##type.dims_, out_v.dims_); \
694  EXPECT_EQ(g2_##type.colortype_, out_v.colortype_); \
695  /*EXPECT_EQ(g2_##type.elemtype_, out_v.elemtype_);*/ \
696  EXPECT_EQ(g2_##type.channels_, out_v.channels_); \
697  EXPECT_TRUE(out_v({ 0,0,0 }) == 1); EXPECT_TRUE(out_v({ 1,0,0 }) == 0); \
698  EXPECT_TRUE(out_v({ 0,1,0 }) == 0); EXPECT_TRUE(out_v({ 1,1,0 }) == 1); \
699  } \
700  else { \
701  EXPECT_THROW(ConnectedComponentsLabeling(g1_##type, g1_##type), std::runtime_error); \
702  } \
703 } \
704 \
705 TEST_F(Imgproc, Normalize##type) \
706 { \
707  constexpr double mean = 39.0; \
708  constexpr double std = 17.5783958312469; \
709  Normalize(g1_##type, out, mean, std); \
710  View<DataType::type> out_v(out); \
711  EXPECT_TRUE(out_v({ 0,0,0 }) == saturate_cast<TypeInfo_t<DataType::type>>((g1_##type##_v({ 0,0,0 }) - mean) / std)); \
712  \
713  Normalize(g2_##type, out, mean, std); \
714  out_v = out; \
715  EXPECT_TRUE(out_v({ 0,0,0 }) == saturate_cast<TypeInfo_t<DataType::type>>((g2_##type##_v({ 0,0,0 }) - mean) / std)); \
716  EXPECT_TRUE(out_v({ 1,0,0 }) == saturate_cast<TypeInfo_t<DataType::type>>((g2_##type##_v({ 1,0,0 }) - mean) / std)); \
717  EXPECT_TRUE(out_v({ 0,1,0 }) == saturate_cast<TypeInfo_t<DataType::type>>((g2_##type##_v({ 0,1,0 }) - mean) / std)); \
718  EXPECT_TRUE(out_v({ 1,1,0 }) == saturate_cast<TypeInfo_t<DataType::type>>((g2_##type##_v({ 1,1,0 }) - mean) / std)); \
719  \
720  Normalize(rgb2_##type, out, mean, std); \
721  out_v = out; \
722  EXPECT_TRUE(out_v({ 0,0,0 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 0,0,0 }) - mean) / std)); \
723  EXPECT_TRUE(out_v({ 1,0,0 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 1,0,0 }) - mean) / std)); \
724  EXPECT_TRUE(out_v({ 0,1,0 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 0,1,0 }) - mean) / std)); \
725  EXPECT_TRUE(out_v({ 1,1,0 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 1,1,0 }) - mean) / std)); \
726  EXPECT_TRUE(out_v({ 0,0,1 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 0,0,1 }) - mean) / std)); \
727  EXPECT_TRUE(out_v({ 1,0,1 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 1,0,1 }) - mean) / std)); \
728  EXPECT_TRUE(out_v({ 0,1,1 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 0,1,1 }) - mean) / std)); \
729  EXPECT_TRUE(out_v({ 1,1,1 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 1,1,1 }) - mean) / std)); \
730  EXPECT_TRUE(out_v({ 0,0,2 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 0,0,2 }) - mean) / std)); \
731  EXPECT_TRUE(out_v({ 1,0,2 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 1,0,2 }) - mean) / std)); \
732  EXPECT_TRUE(out_v({ 0,1,2 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 0,1,2 }) - mean) / std)); \
733  EXPECT_TRUE(out_v({ 1,1,2 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 1,1,2 }) - mean) / std)); \
734 } \
735 TEST_F(Imgproc, NormalizeChannels##type) \
736 { \
737  const std::vector<double> mean = { 39.0, 38.0, 33.0 }; \
738  const std::vector<double> std = { 17.5783958312469, 14.5783958312469, 23.5783958312469 }; \
739  Normalize(rgb2_##type, out, mean, std); \
740  View<DataType::type> out_v(out); \
741  EXPECT_TRUE(out_v({ 0,0,0 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 0,0,0 }) - mean[0]) / std[0])); \
742  EXPECT_TRUE(out_v({ 1,0,0 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 1,0,0 }) - mean[0]) / std[0])); \
743  EXPECT_TRUE(out_v({ 0,1,0 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 0,1,0 }) - mean[0]) / std[0])); \
744  EXPECT_TRUE(out_v({ 1,1,0 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 1,1,0 }) - mean[0]) / std[0])); \
745  EXPECT_TRUE(out_v({ 0,0,1 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 0,0,1 }) - mean[1]) / std[1])); \
746  EXPECT_TRUE(out_v({ 1,0,1 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 1,0,1 }) - mean[1]) / std[1])); \
747  EXPECT_TRUE(out_v({ 0,1,1 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 0,1,1 }) - mean[1]) / std[1])); \
748  EXPECT_TRUE(out_v({ 1,1,1 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 1,1,1 }) - mean[1]) / std[1])); \
749  EXPECT_TRUE(out_v({ 0,0,2 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 0,0,2 }) - mean[2]) / std[2])); \
750  EXPECT_TRUE(out_v({ 1,0,2 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 1,0,2 }) - mean[2]) / std[2])); \
751  EXPECT_TRUE(out_v({ 0,1,2 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 0,1,2 }) - mean[2]) / std[2])); \
752  EXPECT_TRUE(out_v({ 1,1,2 }) == saturate_cast<TypeInfo_t<DataType::type>>((rgb2_##type##_v({ 1,1,2 }) - mean[2]) / std[2])); \
753 } \
754 \
755 TEST_F(Imgproc, CenterCrop##type) \
756 { \
757  std::vector<int> size { 1,1 }; \
758  CenterCrop(g1_##type, out, size); \
759  View<DataType::type> out_v(out); \
760  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
761  EXPECT_THAT(out.dims_, testing::ElementsAre(1, 1, 1)); \
762  \
763  CenterCrop(g2_##type, out, size); \
764  out_v = out; \
765  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
766  EXPECT_THAT(out.dims_, testing::ElementsAre(1, 1, 1)); \
767  \
768  CenterCrop(rgb2_##type, out, size); \
769  out_v = out; \
770  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); \
771  EXPECT_TRUE(out_v({ 0,0,1 }) == 50); \
772  EXPECT_TRUE(out_v({ 0,0,2 }) == 50); \
773  EXPECT_THAT(out.dims_, testing::ElementsAre(1, 1, 3)); \
774 } \
775 \
776 TEST_F(Imgproc, ScaleTo_##type) \
777 { \
778  ScaleTo(g2_##type, out, 14, 60); \
779  View<DataType::type> out_v(out); \
780  EXPECT_TRUE(out_v({ 0,0,0 }) == 50); EXPECT_TRUE(out_v({ 1,0,0 }) == 32); \
781  EXPECT_TRUE(out_v({ 0,1,0 }) == 14); EXPECT_TRUE(out_v({ 1,1,0 }) == 60); \
782  ScaleTo(g2_##type, out, 0, 1); \
783  out_v = out; \
784  EXPECT_TRUE(out_v({ 0,0,0 }) == static_cast<TypeInfo_t<DataType::type>>((g2_##type##_v({ 0,0,0 }) * (1 / 46.) + (1 - ((1 / 46.) * 60))))); \
785  EXPECT_TRUE(out_v({ 1,0,0 }) == static_cast<TypeInfo_t<DataType::type>>((g2_##type##_v({ 1,0,0 }) * (1 / 46.) + (1 - ((1 / 46.) * 60))))); \
786  EXPECT_TRUE(out_v({ 0,1,0 }) == static_cast<TypeInfo_t<DataType::type>>((g2_##type##_v({ 0,1,0 }) * (1 / 46.) + (1 - ((1 / 46.) * 60))))); \
787  EXPECT_TRUE(out_v({ 1,1,0 }) == static_cast<TypeInfo_t<DataType::type>>((g2_##type##_v({ 1,1,0 }) * (1 / 46.) + (1 - ((1 / 46.) * 60))))); \
788 }
789 
791 #undef ECVL_TUPLE
792 } // namespace
Image class.
Definition: image.h:72