Ocean
TestAdvancedZeroMeanSumSquareDifferences.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_ZERO_MEAN_SUM_SQUARE_DIFFERENCES_H
9 #define META_OCEAN_TEST_TESTCV_TESTADVANCED_TEST_ADVANCED_ZERO_MEAN_SUM_SQUARE_DIFFERENCES_H
10 
12 
13 #include "ocean/base/Frame.h"
14 #include "ocean/base/Worker.h"
15 
16 #include "ocean/cv/PixelPosition.h"
17 
18 #include "ocean/math/Vector2.h"
19 
20 namespace Ocean
21 {
22 
23 namespace Test
24 {
25 
26 namespace TestCV
27 {
28 
29 namespace TestAdvanced
30 {
31 
32 /**
33  * This class implements an advanced zero-mean sum square differences test.
34  * @ingroup testcvadvanced
35  */
36 class OCEAN_TEST_CV_ADVANCED_EXPORT TestAdvancedZeroMeanSumSquareDifferences
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  * Tests all advanced zero-mean sum square differences 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 an 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  private:
102 
103  /**
104  * Tests the sum square differences function for two sub-pixel accurate patches in two images.
105  * @param width The width of the test image, in pixel, with range [tSize, infinity)
106  * @param height The height of the test image, in pixel, with range [tSize, infinity)
107  * @param testDuration Number of seconds for each test, with range (0, infinity)
108  * @return True, if succeeded
109  * @tparam tChannels The number of frame channels, with range [1, infinity)
110  * @tparam tPatchSize The size of the patch, with range [1, infinity)
111  */
112  template <unsigned int tChannels, unsigned int tPatchSize>
113  static bool testTwoSubPixelPatch8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration);
114 
115  /**
116  * Tests the sum square differences function for one sub-pixel accurate patch and one pixel-accurate patch in two images.
117  * @param width The width of the test image, in pixel, with range [tSize, infinity)
118  * @param height The height of the test image, in pixel, with range [tSize, infinity)
119  * @param testDuration Number of seconds for each test, with range (0, infinity)
120  * @return True, if succeeded
121  * @tparam tChannels The number of frame channels, with range [1, infinity)
122  * @tparam tPatchSize The size of the patch, with range [1, infinity)
123  */
124  template <unsigned int tChannels, unsigned int tPatchSize>
125  static bool testOneSubPixelPatch8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration);
126 
127  /**
128  * Tests the sum square differences function between an image patch and a buffer.
129  * @param width The width of the test image, in pixel, with range [tSize, infinity)
130  * @param height The height of the test image, in pixel, with range [tSize, infinity)
131  * @param testDuration Number of seconds for each test, with range (0, infinity)
132  * @return True, if succeeded
133  * @tparam tChannels The number of frame channels, with range [1, infinity)
134  * @tparam tPatchSize The size of the patch, with range [1, infinity)
135  */
136  template <unsigned int tChannels, unsigned int tPatchSize>
137  static bool testPatchBuffer8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration);
138 
139  /**
140  * Tests the sum square differences function between an image patch (mirrored at the image border) and a buffer.
141  * @param width The width of the test image, in pixel, with range [tSize, infinity)
142  * @param height The height of the test image, in pixel, with range [tSize, infinity)
143  * @param testDuration Number of seconds for each test, with range (0, infinity)
144  * @return True, if succeeded
145  * @tparam tChannels The number of frame channels, with range [1, infinity)
146  * @tparam tPatchSize The size of the patch, with range [1, infinity)
147  */
148  template <unsigned int tChannels, unsigned int tPatchSize>
149  static bool testPatchMirroredBorderBuffer8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration);
150 
151  /**
152  * Tests the sum square differences function for two pixel accurate patches in combination with a mask.
153  * @param width The width of the test image, in pixel, with range [tSize, infinity)
154  * @param height The height of the test image, in pixel, with range [tSize, infinity)
155  * @param testDuration Number of seconds for each test, with range (0, infinity)
156  * @return True, if succeeded
157  * @tparam tChannels The number of frame channels, with range [1, infinity)
158  * @tparam tPatchSize The size of the patch, with range [1, infinity)
159  */
160  template <unsigned int tChannels, unsigned int tPatchSize>
161  static bool testTwoPixelPatchWithMask8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration);
162 
163  /**
164  * CCalculates the ssd value between two sub-pixel patches.
165  * @param frame0 First frame to be used, must be valid, must be valid
166  * @param frame1 Second frame to be used, must be valid, must be valid
167  * @param center0 Center position in the first frame, with range [patchSize/2, width0 - patchSize/2 - 1)x[patchSize/2, height0 - patchSize/2 - 1)
168  * @param center1 Center position in the second frame, with range [patchSize/2, width1 - patchSize/2 - 1)x[patchSize/2, height1 - patchSize/2 - 1)
169  * @param patchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
170  * @return The resulting ssd
171  */
172  static uint32_t calculate8BitPerChannel(const Frame& frame0, const Frame& frame1, const Vector2& center0, const Vector2& center1, const unsigned int patchSize);
173 
174  /**
175  * Calculates the ssd value between one sub-pixel patch and one pixel-accurate patch.
176  * @param frame0 First frame to be used, must be valid, must be valid
177  * @param frame1 Second frame to be used, must be valid, must be valid
178  * @param center0 Center position in the first frame, with range [patchSize/2, width0 - tSize/2)x[patchSize/2, height0 - patchSize/2)
179  * @param center1 Center position in the second frame, with range [patchSize/2, width1 - patchSize/2 - 1)x[patchSize/2, height1 - patchSize/2 - 1)
180  * @param patchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
181  * @return The resulting ssd
182  */
183  static uint32_t calculate8BitPerChannel(const Frame& frame0, const Frame& frame1, const CV::PixelPosition& center0, const Vector2& center1, const unsigned int patchSize);
184 
185  /**
186  * Calculates the ssd value between one sub-pixel patch and a buffer.
187  * @param frame0 First frame to be used, must be valid, must be valid
188  * @param center0 Center position in the first frame, with range [patchSize/2, width0 - patchSize/2 - 1)x[patchSize/2, height0 - patchSize/2 - 1)
189  * @param buffer1 The pointer to the buffer, must be valid
190  * @param patchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
191  * @return The resulting ssd
192  */
193  static uint32_t calculate8BitPerChannel(const Frame& frame0, const Vector2& center0, const uint8_t* buffer1, const unsigned int patchSize);
194 
195  /**
196  * Calculates the ssd value between one sub-pixel patch (mirrored at the image border) and a buffer.
197  * @param frame0 First frame to be used, must be valid, must be valid
198  * @param center0 Center position in the first frame, with range [patchSize/2, width0 - patchSize/2 - 1)x[patchSize/2, height0 - patchSize/2 - 1)
199  * @param buffer1 The pointer to the buffer, must be valid
200  * @param patchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
201  * @return The resulting ssd
202  */
203  static uint32_t calculateMirroredBorder8BitPerChannel(const Frame& frame0, const Vector2& center0, const uint8_t* buffer1, const unsigned int patchSize);
204 
205  /**
206  * Calculates the sum of squared differences value between two patches with associated masks.
207  * @param frame0 First frame to be used, must be valid, must be valid
208  * @param frame1 Second frame to be used, must be valid, must be valid
209  * @param mask0 First mask to be used, must be valid, must be valid
210  * @param mask1 Second mask to be used, must be valid, must be valid
211  * @param center0 Center position in the first frame, with range [patchSize/2, width0 - tSize/2)x[patchSize/2, height0 - patchSize/2)
212  * @param center1 Center position in the second frame, with range [patchSize/2, width1 - tSize/2 - 1)x[patchSize/2, height1 - patchSize/2 - 1)
213  * @param patchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
214  * @param maskValue The pixel value for mask pixels which will be excluded from SSD calculation
215  * @return The resulting ssd
216  */
217  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);
218 };
219 
220 }
221 
222 }
223 
224 }
225 
226 }
227 
228 #endif // META_OCEAN_TEST_TESTCV_TESTADVANCED_TEST_ADVANCED_ZERO_MEAN_SUM_SQUARE_DIFFERENCES_H
This class implements Ocean's image class.
Definition: Frame.h:1760
This class implements an advanced zero-mean sum square differences test.
Definition: TestAdvancedZeroMeanSumSquareDifferences.h:37
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)
CCalculates the ssd value between two sub-pixel patches.
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 testPatchMirroredBorderBuffer8BitPerChannel(const double testDuration)
Tests the sum square differences function between a sub-pixel image patch and a buffer.
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 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 testPatchBuffer8BitPerChannel(const double testDuration)
Tests the sum square differences function between an image patch and a buffer.
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 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...
ImplementationType
Definition of individual types of implementation.
Definition: TestAdvancedZeroMeanSumSquareDifferences.h:44
@ IT_TEMPLATE
The template-based implementation.
Definition: TestAdvancedZeroMeanSumSquareDifferences.h:48
@ IT_NEON
The NEON-based implementation.
Definition: TestAdvancedZeroMeanSumSquareDifferences.h:52
@ IT_SSE
The SSE-based implementation.
Definition: TestAdvancedZeroMeanSumSquareDifferences.h:50
@ IT_NAIVE
The naive implementation.
Definition: TestAdvancedZeroMeanSumSquareDifferences.h:46
static bool test(const double testDuration)
Tests all advanced zero-mean sum square differences functions.
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 testTwoSubPixelPatch8BitPerChannel(const double testDuration)
Tests the sum square differences function for two sub-pixel accurate patches in two images.
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 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 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.
std::pair< Index32, Index32 > IndexPair32
Definition of a pair holding 32 bit indices.
Definition: Base.h:138
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15