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