Ocean
Loading...
Searching...
No Matches
TestAdvancedSumSquareDifferences.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_TEST_TESTCV_TESTADVANCED_TEST_ADVANCED_SUM_SQUARE_DIFFERENCES_H
9#define META_OCEAN_TEST_TESTCV_TESTADVANCED_TEST_ADVANCED_SUM_SQUARE_DIFFERENCES_H
10
12
13#include "ocean/base/Frame.h"
14#include "ocean/base/Worker.h"
15
17
18#include "ocean/math/Vector2.h"
19
21
22namespace Ocean
23{
24
25namespace Test
26{
27
28namespace TestCV
29{
30
31namespace TestAdvanced
32{
33
34/**
35 * This class implements an advanced sum square differences test.
36 * @ingroup testcvadvanced
37 */
38class OCEAN_TEST_CV_ADVANCED_EXPORT TestAdvancedSumSquareDifferences
39{
40 protected:
41
42 /**
43 * Definition of individual types of implementation.
44 */
45 enum ImplementationType : uint32_t
46 {
47 /// The naive implementation.
49 /// The template-based implementation.
51 /// The SSE-based implementation.
53 /// The NEON-based implementation.
55 /// The default implementation (which is actually used by default).
56 IT_DEFAULT
57 };
58
59 public:
60
61 /**
62 * Invokes all test functions.
63 * @param testDuration Number of seconds for each test, with range (0, infinity)
64 * @param selector The test selector to filter tests
65 * @return True, if succeeded
66 */
67 static bool test(const double testDuration, const TestSelector& selector);
68
69 /**
70 * Tests the sum square differences function for two sub-pixel accurate patches in two images.
71 * @param testDuration Number of seconds for each test, with range (0, infinity)
72 * @return True, if succeeded
73 */
74 static bool testTwoSubPixelPatch8BitPerChannel(const double testDuration);
75
76 /**
77 * Tests the sum square differences function for one sub-pixel accurate patch and one pixel-accurate patch in two images.
78 * @param testDuration Number of seconds for each test, with range (0, infinity)
79 * @return True, if succeeded
80 */
81 static bool testOneSubPixelPatch8BitPerChannel(const double testDuration);
82
83 /**
84 * Tests the sum square differences function between a sub-pixel image patch and a buffer.
85 * @param testDuration Number of seconds for each test, with range (0, infinity)
86 * @return True, if succeeded
87 */
88 static bool testPatchBuffer8BitPerChannel(const double testDuration);
89
90 /**
91 * Tests the sum square differences function between a sub-pixel image patch and a buffer.
92 * @param testDuration Number of seconds for each test, with range (0, infinity)
93 * @return True, if succeeded
94 */
95 static bool testPatchMirroredBorderBuffer8BitPerChannel(const double testDuration);
96
97 /**
98 * Tests the sum square differences function for two pixel accurate patches in combination with a mask.
99 * @param testDuration Number of seconds for each test, with range (0, infinity)
100 * @return True, if succeeded
101 */
102 static bool testTwoPixelPatchWithMask8BitPerChannel(const double testDuration);
103
104 /**
105 * Tests the sum square differences function for two sub-pixel accurate patches in combination with a mask.
106 * @param testDuration Number of seconds for each test, with range (0, infinity)
107 * @return True, if succeeded
108 */
109 static bool testTwoSubPixelPatchWithMask8BitPerChannel(const double testDuration);
110
111 /**
112 * Tests the sum square differences function for two pixel accurate patches in combination with a rejecting mask.
113 * @param testDuration Number of seconds for each test, with range (0, infinity)
114 * @return True, if succeeded
115 */
116 static bool testTwoPixelPatchWithRejectingMask8BitPerChannel(const double testDuration);
117
118 private:
119
120 /**
121 * Tests the sum square differences function for two sub-pixel accurate patches in two images.
122 * @param width The width of the test image, in pixel, with range [tSize, infinity)
123 * @param height The height of the test image, in pixel, with range [tSize, infinity)
124 * @param testDuration Number of seconds for each test, with range (0, infinity)
125 * @return True, if succeeded
126 * @tparam tChannels The number of frame channels, with range [1, infinity)
127 * @tparam tPatchSize The size of the patch, with range [1, infinity)
128 */
129 template <unsigned int tChannels, unsigned int tPatchSize>
130 static bool testTwoSubPixelPatch8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration);
131
132 /**
133 * Tests the sum square differences function for one sub-pixel accurate patch and one pixel-accurate patch in two images.
134 * @param width The width of the test image, in pixel, with range [tSize, infinity)
135 * @param height The height of the test image, in pixel, with range [tSize, infinity)
136 * @param testDuration Number of seconds for each test, with range (0, infinity)
137 * @return True, if succeeded
138 * @tparam tChannels The number of frame channels, with range [1, infinity)
139 * @tparam tPatchSize The size of the patch, with range [1, infinity)
140 */
141 template <unsigned int tChannels, unsigned int tPatchSize>
142 static bool testOneSubPixelPatch8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration);
143
144 /**
145 * Tests the sum square differences function between an image patch and a buffer.
146 * @param width The width of the test image, in pixel, with range [tSize, infinity)
147 * @param height The height of the test image, in pixel, with range [tSize, infinity)
148 * @param testDuration Number of seconds for each test, with range (0, infinity)
149 * @return True, if succeeded
150 * @tparam tChannels The number of frame channels, with range [1, infinity)
151 * @tparam tPatchSize The size of the patch, with range [1, infinity)
152 */
153 template <unsigned int tChannels, unsigned int tPatchSize>
154 static bool testPatchBuffer8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration);
155
156 /**
157 * Tests the sum square differences function between an image patch (mirrored at the image border) and a buffer.
158 * @param width The width of the test image, in pixel, with range [tSize, infinity)
159 * @param height The height of the test image, in pixel, with range [tSize, infinity)
160 * @param testDuration Number of seconds for each test, with range (0, infinity)
161 * @return True, if succeeded
162 * @tparam tChannels The number of frame channels, with range [1, infinity)
163 * @tparam tPatchSize The size of the patch, with range [1, infinity)
164 */
165 template <unsigned int tChannels, unsigned int tPatchSize>
166 static bool testPatchMirroredBorderBuffer8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration);
167
168 /**
169 * Tests the sum square differences function for two pixel accurate patches in combination with a mask.
170 * @param width The width of the test image, in pixel, with range [tSize, infinity)
171 * @param height The height of the test image, in pixel, with range [tSize, infinity)
172 * @param testDuration Number of seconds for each test, with range (0, infinity)
173 * @return True, if succeeded
174 * @tparam tChannels The number of frame channels, with range [1, infinity)
175 * @tparam tPatchSize The size of the patch, with range [1, infinity)
176 */
177 template <unsigned int tChannels, unsigned int tPatchSize>
178 static bool testTwoPixelPatchWithMask8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration);
179
180 /**
181 * Tests the sum square differences function for two sub-pixel accurate patches in combination with a mask.
182 * @param width The width of the test image, in pixel, with range [tSize, infinity)
183 * @param height The height of the test image, in pixel, with range [tSize, infinity)
184 * @param testDuration Number of seconds for each test, with range (0, infinity)
185 * @return True, if succeeded
186 * @tparam tChannels The number of frame channels, with range [1, infinity)
187 * @tparam tPatchSize The size of the patch, with range [1, infinity)
188 */
189 template <unsigned int tChannels, unsigned int tPatchSize>
190 static bool testTwoSubPixelPatchWithMask8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration);
191
192 /**
193 * Tests the sum square differences function for two pixel accurate patches in combination with a rejecting mask.
194 * @param width The width of the test image, in pixel, with range [tSize, infinity)
195 * @param height The height of the test image, in pixel, with range [tSize, infinity)
196 * @param testDuration Number of seconds for each test, with range (0, infinity)
197 * @return True, if succeeded
198 * @tparam tChannels The number of frame channels, with range [1, infinity)
199 * @tparam tPatchSize The size of the patch, with range [1, infinity)
200 */
201 template <unsigned int tChannels, unsigned int tPatchSize>
202 static bool testTwoPixelPatchWithRejectingMask8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration);
203
204 /**
205 * Calculates the ssd value between two sub-pixel patches.
206 * @param frame0 First frame to be used, must be valid, must be valid
207 * @param frame1 Second frame to be used, must be valid, must be valid
208 * @param center0 Center position in the first frame, with range [patchSize/2, width0 - patchSize/2 - 1)x[patchSize/2, height0 - patchSize/2 - 1)
209 * @param center1 Center position in the second frame, with range [patchSize/2, width1 - patchSize/2 - 1)x[patchSize/2, height1 - patchSize/2 - 1)
210 * @param patchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
211 * @return The resulting ssd
212 */
213 static uint32_t calculate8BitPerChannel(const Frame& frame0, const Frame& frame1, const Vector2& center0, const Vector2& center1, const unsigned int patchSize);
214
215 /**
216 * Calculates the ssd value between one sub-pixel patch and one pixel-accurate patch.
217 * @param frame0 First frame to be used, must be valid, must be valid
218 * @param frame1 Second frame to be used, must be valid, must be valid
219 * @param center0 Center position in the first frame, with range [patchSize/2, width0 - tSize/2)x[patchSize/2, height0 - patchSize/2)
220 * @param center1 Center position in the second frame, with range [patchSize/2, width1 - tSize/2 - 1)x[patchSize/2, height1 - patchSize/2 - 1)
221 * @param patchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
222 * @return The resulting ssd
223 */
224 static uint32_t calculate8BitPerChannel(const Frame& frame0, const Frame& frame1, const CV::PixelPosition& center0, const Vector2& center1, const unsigned int patchSize);
225
226 /**
227 * Calculates the ssd value between one sub-pixel patch and a buffer.
228 * @param frame0 First frame to be used, must be valid, must be valid
229 * @param center0 Center position in the first frame, with range [patchSize/2, width0 - patchSize/2 - 1)x[patchSize/2, height0 - patchSize/2 - 1)
230 * @param buffer1 The pointer to the buffer, must be valid
231 * @param patchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
232 * @return The resulting ssd
233 */
234 static uint32_t calculate8BitPerChannel(const Frame& frame0, const Vector2& center0, const uint8_t* buffer1, const unsigned int patchSize);
235
236 /**
237 * Calculates the ssd value between one sub-pixel patch (mirrored at the image border) and a buffer.
238 * @param frame0 First frame to be used, must be valid, must be valid
239 * @param center0 Center position in the first frame, with range [patchSize/2, width0 - patchSize/2 - 1)x[patchSize/2, height0 - patchSize/2 - 1)
240 * @param buffer1 The pointer to the buffer, must be valid
241 * @param patchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
242 * @return The resulting ssd
243 */
244 static uint32_t calculateMirroredBorder8BitPerChannel(const Frame& frame0, const Vector2& center0, const uint8_t* buffer1, const unsigned int patchSize);
245
246 /**
247 * Calculates the sum of squared differences value between two patches with associated masks.
248 * @param frame0 First frame to be used, must be valid, must be valid
249 * @param frame1 Second frame to be used, must be valid, must be valid
250 * @param mask0 First mask to be used, must be valid, must be valid
251 * @param mask1 Second mask to be used, must be valid, must be valid
252 * @param center0 Center position in the first frame, with range [patchSize/2, width0 - tSize/2)x[patchSize/2, height0 - patchSize/2)
253 * @param center1 Center position in the second frame, with range [patchSize/2, width1 - tSize/2 - 1)x[patchSize/2, height1 - patchSize/2 - 1)
254 * @param patchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
255 * @param maskValue The pixel value for mask pixels which will be excluded from SSD calculation
256 * @return The resulting ssd
257 */
258 static IndexPair32 calculateWithMask8BitPerChannel(const Frame& frame0, const Frame& frame1, const Frame& mask0, const Frame& mask1, const CV::PixelPosition& center0, const CV::PixelPosition& center1, const unsigned int patchSize, const uint8_t maskValue);
259
260 /**
261 * Calculates the sum of squared differences value between two patches with associated masks.
262 * @param frame0 First frame to be used, must be valid, must be valid
263 * @param frame1 Second frame to be used, must be valid, must be valid
264 * @param mask0 First mask to be used, must be valid, must be valid
265 * @param mask1 Second mask to be used, must be valid, must be valid
266 * @param center0 Center position in the first frame, with range (-infinity, infinity)x(-infinity, infinity)
267 * @param center1 Center position in the second frame, with range (-infinity, infinity)x(-infinity, infinity)
268 * @param pixelCenter The pixel center to be used
269 * @param patchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
270 * @param validMaskValue The pixel value for mask pixels which will be included in SSD calculation
271 * @return The resulting ssd
272 */
273 static IndexPair32 calculateWithMask8BitPerChannel(const Frame& frame0, const Frame& frame1, const Frame& mask0, const Frame& mask1, const Vector2& center0, const Vector2& center1, const CV::PixelCenter pixelCenter, const unsigned int patchSize, const uint8_t validMaskValue);
274
275 /**
276 * Calculates the sum of squared differences value between two patches with associated rejecting masks.
277 * @param frame0 First frame to be used, must be valid, must be valid
278 * @param frame1 Second frame to be used, must be valid, must be valid
279 * @param mask0 First mask to be used, must be valid, must be valid
280 * @param mask1 Second mask to be used, must be valid, must be valid
281 * @param center0 Center position in the first frame, with range [patchSize/2, width0 - tSize/2)x[patchSize/2, height0 - patchSize/2)
282 * @param center1 Center position in the second frame, with range [patchSize/2, width1 - tSize/2 - 1)x[patchSize/2, height1 - patchSize/2 - 1)
283 * @param patchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
284 * @param maskValue The pixel value for mask pixels which will be excluded from SSD calculation
285 * @return The resulting ssd
286 */
287 static IndexPair32 calculateWithRejectingMask8BitPerChannel(const Frame& frame0, const Frame& frame1, const Frame& mask0, const Frame& mask1, const CV::PixelPosition& center0, const CV::PixelPosition& center1, const unsigned int patchSize, const uint8_t maskValue);
288};
289
290}
291
292}
293
294}
295
296}
297
298#endif // META_OCEAN_TEST_TESTCV_TESTADVANCED_TEST_ADVANCED_SUM_SQUARE_DIFFERENCES_H
This class implements Ocean's image class.
Definition Frame.h:1879
This class implements an advanced sum square differences test.
Definition TestAdvancedSumSquareDifferences.h:39
static bool testTwoPixelPatchWithMask8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration)
Tests the sum square differences function for two pixel accurate patches in combination with a mask.
static bool testTwoSubPixelPatchWithMask8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration)
Tests the sum square differences function for two sub-pixel accurate patches in combination with a ma...
static bool testTwoPixelPatchWithRejectingMask8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration)
Tests the sum square differences function for two pixel accurate patches in combination with a reject...
static bool testTwoSubPixelPatchWithMask8BitPerChannel(const double testDuration)
Tests the sum square differences function for two sub-pixel accurate patches in combination with a ma...
static uint32_t calculateMirroredBorder8BitPerChannel(const Frame &frame0, const Vector2 &center0, const uint8_t *buffer1, const unsigned int patchSize)
Calculates the ssd value between one sub-pixel patch (mirrored at the image border) and a buffer.
static bool testPatchBuffer8BitPerChannel(const double testDuration)
Tests the sum square differences function between a sub-pixel image patch and a buffer.
ImplementationType
Definition of individual types of implementation.
Definition TestAdvancedSumSquareDifferences.h:46
@ IT_NAIVE
The naive implementation.
Definition TestAdvancedSumSquareDifferences.h:48
@ IT_SSE
The SSE-based implementation.
Definition TestAdvancedSumSquareDifferences.h:52
@ IT_TEMPLATE
The template-based implementation.
Definition TestAdvancedSumSquareDifferences.h:50
@ IT_NEON
The NEON-based implementation.
Definition TestAdvancedSumSquareDifferences.h:54
static bool testPatchBuffer8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration)
Tests the sum square differences function between an image patch and a buffer.
static bool testTwoPixelPatchWithRejectingMask8BitPerChannel(const double testDuration)
Tests the sum square differences function for two pixel accurate patches in combination with a reject...
static bool testTwoSubPixelPatch8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration)
Tests the sum square differences function for two sub-pixel accurate patches in two images.
static bool testTwoSubPixelPatch8BitPerChannel(const double testDuration)
Tests the sum square differences function for two sub-pixel accurate patches in two images.
static uint32_t calculate8BitPerChannel(const Frame &frame0, const Frame &frame1, const CV::PixelPosition &center0, const Vector2 &center1, const unsigned int patchSize)
Calculates the ssd value between one sub-pixel patch and one pixel-accurate patch.
static bool testTwoPixelPatchWithMask8BitPerChannel(const double testDuration)
Tests the sum square differences function for two pixel accurate patches in combination with a mask.
static bool test(const double testDuration, const TestSelector &selector)
Invokes all test functions.
static bool testPatchMirroredBorderBuffer8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration)
Tests the sum square differences function between an image patch (mirrored at the image border) and a...
static IndexPair32 calculateWithMask8BitPerChannel(const Frame &frame0, const Frame &frame1, const Frame &mask0, const Frame &mask1, const Vector2 &center0, const Vector2 &center1, const CV::PixelCenter pixelCenter, const unsigned int patchSize, const uint8_t validMaskValue)
Calculates the sum of squared differences value between two patches with associated masks.
static bool testOneSubPixelPatch8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration)
Tests the sum square differences function for one sub-pixel accurate patch and one pixel-accurate pat...
static IndexPair32 calculateWithRejectingMask8BitPerChannel(const Frame &frame0, const Frame &frame1, const Frame &mask0, const Frame &mask1, const CV::PixelPosition &center0, const CV::PixelPosition &center1, const unsigned int patchSize, const uint8_t maskValue)
Calculates the sum of squared differences value between two patches with associated rejecting masks.
static IndexPair32 calculateWithMask8BitPerChannel(const Frame &frame0, const Frame &frame1, const Frame &mask0, const Frame &mask1, const CV::PixelPosition &center0, const CV::PixelPosition &center1, const unsigned int patchSize, const uint8_t maskValue)
Calculates the sum of squared differences value between two patches with associated masks.
static uint32_t calculate8BitPerChannel(const Frame &frame0, const Vector2 &center0, const uint8_t *buffer1, const unsigned int patchSize)
Calculates the ssd value between one sub-pixel patch and a buffer.
static bool testOneSubPixelPatch8BitPerChannel(const double testDuration)
Tests the sum square differences function for one sub-pixel accurate patch and one pixel-accurate pat...
static uint32_t calculate8BitPerChannel(const Frame &frame0, const Frame &frame1, const Vector2 &center0, const Vector2 &center1, const unsigned int patchSize)
Calculates the ssd value between two sub-pixel patches.
static bool testPatchMirroredBorderBuffer8BitPerChannel(const double testDuration)
Tests the sum square differences function between a sub-pixel image patch and a buffer.
This class implements a test selector that parses test function strings and determines which tests sh...
Definition TestSelector.h:51
std::pair< Index32, Index32 > IndexPair32
Definition of a pair holding 32 bit indices.
Definition Base.h:138
PixelCenter
Definition of individual centers of pixels.
Definition CV.h:117
The namespace covering the entire Ocean framework.
Definition Accessor.h:15