Ocean
TestMappingF1.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_TESTSYNTHESIS_TEST_MAPPING_F_1_H
9 #define META_OCEAN_TEST_TESTCV_TESTSYNTHESIS_TEST_MAPPING_F_1_H
10 
12 
13 #include "ocean/base/Frame.h"
14 
16 
17 namespace Ocean
18 {
19 
20 namespace Test
21 {
22 
23 namespace TestCV
24 {
25 
26 namespace TestSynthesis
27 {
28 
29 /**
30  * This class implements a synthesis sub-pixel mapping test.
31  * @ingroup testcvsynthesis
32  */
33 class OCEAN_TEST_CV_SYNTHESIS_EXPORT TestMappingF1 : protected CV::Synthesis::MappingF1
34 {
35  protected:
36 
37  /**
38  * Definition of individual types of implementation.
39  */
40  enum ImplementationType : uint32_t
41  {
42  /// The naive implementation.
44  /// The template-based implementation.
46  /// The SSE-based implementation.
48  /// The NEON-based implementation.
50  /// The default implementation (which is actually used by default).
51  IT_DEFAULT
52  };
53 
54  public:
55 
56  /**
57  * Tests all mapping functions.
58  * @param width The width of the source frame in pixel, with range [1, infinity)
59  * @param height The height of the source frame in pixel, with range [1, infinity)
60  * @param testDuration Number of seconds for each test, with range (0, infinity)
61  * @param worker The worker object to distribute the CPU load
62  * @return True, if succeeded
63  */
64  static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
65 
66  /**
67  * Tests the applyMapping function.
68  * @param width The width of the source frame in pixel, with range [1, infinity)
69  * @param height The height of the source frame in pixel, with range [1, infinity)
70  * @param testDuration Number of seconds for each test, with range (0, infinity)
71  * @param worker The worker object to distribute the CPU load
72  * @return True, if succeeded
73  */
74  static bool testApplyMapping(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
75 
76  /**
77  * Tests the applyMapping function for a specific pixel format.
78  * @param width The width of the source frame in pixel, with range [1, infinity)
79  * @param height The height of the source frame in pixel, with range [1, infinity)
80  * @param channels The number of frame channels to be used, with range [1, infinity)
81  * @param testDuration Number of seconds for each test, with range (0, infinity)
82  * @param worker The worker object to distribute the CPU load
83  * @return True, if succeeded
84  */
85  static bool testApplyMapping(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
86 
87  /**
88  * Tests the sum of squared differences calculation using a mask.
89  * @param width The width of the source frame in pixel, with range [1, infinity)
90  * @param height The height of the source frame in pixel, with range [1, infinity)
91  * @param testDuration Number of seconds for each test, with range (0, infinity)
92  * @return True, if succeeded
93  */
94  static bool testSumSquaredDifference5x5Mask(const unsigned int width, const unsigned int height, const double testDuration);
95 
96  /**
97  * Tests the sum of squared differences calculation using a mask.
98  * @param width The width of the source frame in pixel, with range [1, infinity)
99  * @param height The height of the source frame in pixel, with range [1, infinity)
100  * @param testDuration Number of seconds for each test, with range (0, infinity)
101  * @return True, if succeeded
102  * @tparam tChannels The number of frame channels to be used, with range [1, infinity)
103  */
104  template <unsigned int tChannels>
105  static bool testSumSquaredDifference5x5Mask(const unsigned int width, const unsigned int height, const double testDuration);
106 
107  /**
108  * Tests the 5x5 appearance cost function.
109  * @param width The width of the source frame in pixel, with range [1, infinity)
110  * @param height The height of the source frame in pixel, with range [1, infinity)
111  * @param testDuration Number of seconds for each test, with range (0, infinity)
112  * @return True, if succeeded
113  */
114  static bool testAppearanceCost5x5(const unsigned int width, const unsigned int height, const double testDuration);
115 
116  /**
117  * Tests the 5x5 appearance cost function.
118  * @param width The width of the source frame in pixel, with range [1, infinity)
119  * @param height The height of the source frame in pixel, with range [1, infinity)
120  * @param testDuration Number of seconds for each test, with range (0, infinity)
121  * @return True, if succeeded
122  * @tparam tChannels The number of frame channels to be used, with range [1, infinity)
123  */
124  template <unsigned int tChannels>
125  static bool testAppearanceCost5x5(const unsigned int width, const unsigned int height, const double testDuration);
126 
127  /**
128  * Tests the 5x5 appearance cost function with reference frame.
129  * @param width The width of the source frame in pixel, with range [1, infinity)
130  * @param height The height of the source frame in pixel, with range [1, infinity)
131  * @param testDuration Number of seconds for each test, with range (0, infinity)
132  * @return True, if succeeded
133  */
134  static bool testAppearanceReferenceCost5x5(const unsigned int width, const unsigned int height, const double testDuration);
135 
136  /**
137  * Tests the 5x5 appearance cost function with reference frame.
138  * @param width The width of the source frame in pixel, with range [1, infinity)
139  * @param height The height of the source frame in pixel, with range [1, infinity)
140  * @param testDuration Number of seconds for each test, with range (0, infinity)
141  * @return True, if succeeded
142  * @tparam tChannels The number of frame channels to be used, with range [1, infinity)
143  */
144  template <unsigned int tChannels>
145  static bool testAppearanceReferenceCost5x5(const unsigned int width, const unsigned int height, const double testDuration);
146 
147  /**
148  * Tests the spatial cost with 4-neighborhood.
149  * @param width The width of the source frame in pixel, with range [1, infinity)
150  * @param height The height of the source frame in pixel, with range [1, infinity)
151  * @param testDuration Number of seconds for each test, with range (0, infinity)
152  * @return True, if succeeded
153  */
154  static bool testSpatialCost4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration);
155 
156  /**
157  * Tests the spatial cost with 4-neighborhood.
158  * @param width The width of the source frame in pixel, with range [1, infinity)
159  * @param height The height of the source frame in pixel, with range [1, 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 to be used, with range [1, infinity)
163  */
164  template <unsigned int tChannels>
165  static bool testSpatialCost4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration);
166 
167  /**
168  * Tests the sum square differences function between two pixel accurate image patches and one sub-pixel accurate image patch.
169  * @param testDuration Number of seconds for each test, with range (0, infinity)
170  * @return True, if succeeded
171  */
172  static bool testTwoPixelPatchOneSubPixelPatch8BitPerChannel(const double testDuration);
173 
174  private:
175 
176  /**
177  * Tests the sum square differences function between two pixel accurate image patches and one sub-pixel accurate image patch.
178  * @param width The width of the test image, in pixel, with range [tSize, infinity)
179  * @param height The height of the test image, in pixel, with range [tSize, infinity)
180  * @param testDuration Number of seconds for each test, with range (0, infinity)
181  * @return True, if succeeded
182  * @tparam tChannels The number of frame channels, with range [1, infinity)
183  * @tparam tPatchSize The size of the patch, with range [1, infinity)
184  */
185  template <unsigned int tChannels, unsigned int tPatchSize>
186  static bool testTwoPixelPatchOneSubPixelPatch8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration);
187 
188  /**
189  * Validates the mapping results for a frame and corresponding mapping.
190  * @param frame The result frame, must be valid
191  * @param mask The mask frame, must be valid
192  * @param mapping The mapping which has been used
193  * @param boundingBox The bounding box defining the area of interest, must be valid
194  * @return True, if succeeded
195  */
196  static bool validateMapping(const Frame& frame, const Frame& mask, const CV::Synthesis::MappingF1& mapping, const CV::PixelBoundingBox& boundingBox);
197 
198  /**
199  * Validates the 5x5 sum of squared differences.
200  * @param frame0 The first frame, must be valid
201  * @param frame1 The second frame, must be valid
202  * @param mask0 The mask for the first frame, must be valid
203  * @param positions0 The center position in the first frame
204  * @param positions1 The center position in the second frame
205  * @param results The SSD results to verify, one for each position
206  * @param borderFactor The border factor to be used
207  * @return The number of correct/precise results, with range [0, results.size()]
208  */
209  static size_t validateSumSquaredDifference5x5Mask(const Frame& frame0, const Frame& frame1, const Frame& mask0, const CV::PixelPositions& positions0, const Vectors2& positions1, const Indices32& results, const unsigned int borderFactor);
210 
211  /**
212  * Determines the appearance cost.
213  * @param sourceFrame The source frame for which the cost will be determined, must be valid
214  * @param targetFrame The target frame for which the cost will be determined, must be valid
215  * @param mask The mask associated with the frame, defining valid and invalid frame pixels, must be valid
216  * @param source The source location within the frame, with range [2, frame.width()-3)x[2, frame.height()-3)
217  * @param target The target location within the frame, with range [0, frame.width()-1]x[0, frame.height()-1]
218  * @param patchSize The size of the image patch, in pixels, with range [1, infinity), must be odd
219  * @param borderFactor The factor which will be applied to target pixels outside of the mask, with range [1, infinity)
220  * @param normalizationFactor The normalization factor to be applied, with range [1, infinity)
221  * @return The resulting cost
222  * @tparam tPatchSizeNormalization True, to normalized the cost with the patch size; False, to ignore the patch size
223  */
224  template <bool tPatchSizeNormalization>
225  static uint64_t determineAppearanceCost(const Frame& sourceFrame, const Frame& targetFrame, const Frame& mask, const Vector2& source, const CV::PixelPosition& target, const unsigned int patchSize, const unsigned int borderFactor, const unsigned int normalizationFactor);
226 
227  /**
228  * Determines the appearance cost with a reference frame.
229  * @param frame The frame for which the cost will be determined, must be valid
230  * @param mask The mask associated with the frame, defining valid and invalid frame pixels, must be valid
231  * @param reference The reference frame to be used, must be valid
232  * @param source The source location within the frame, with range [2, frame.width()-3)x[2, frame.height()-3)
233  * @param target The target location within the frame, with range [0, frame.width()-1]x[0, frame.height()-1]
234  * @param patchSize The size of the image patch, in pixels, with range [1, infinity), must be odd
235  * @param borderFactor The factor which will be applied to target pixels outside of the mask, with range [1, infinity)
236  * @param normalizationFactor The normalization factor to be applied, with range [1, infinity)
237  * @return The resulting cost
238  */
239  static uint64_t determineAppearanceReferenceCost(const Frame& frame, const Frame& reference, const Frame& mask, const Vector2& source, const CV::PixelPosition& target, const unsigned int patchSize, const unsigned int borderFactor, const unsigned int normalizationFactor);
240 
241  /**
242  * Determines the spatial cost in a 4-neighborhood.
243  * @param mapping The mapping to be used, must be valid
244  * @param mask The mask associated with the frame, defining valid and invalid frame pixels, must be valid
245  * @param source The source location within the frame, with range [0, frame.width()-1)x[0, frame.height()-1)
246  * @param target The target location within the frame, with range [0, frame.width()-1]x[0, frame.height()-1]
247  * @param maxCost The maximal cost, with range [0, infinity)
248  * @param normalizationFactor The normalization factor to be applied, with range [1, infinity)
249  * @return The resulting cost
250  */
251  static Scalar determineSpatialCost4Neighborhood(const CV::Synthesis::MappingF1& mapping, const Frame& mask, const Vector2& source, const CV::PixelPosition& target, const Scalar maxCost, const unsigned int normalizationFactor);
252 
253  /**
254  * Returns the neighbor pixel with sub-pixel accuracy.
255  * @param position The pixel position for which the neighbor position will be returned
256  * @param pixelDirection The direction in which the neighbor will be located, must be valid
257  * @return The neighbor pixel to the given pixel
258  */
259  static Vector2 neighborPixel(const Vector2& position, const CV::PixelDirection pixelDirection);
260 };
261 
262 }
263 
264 }
265 
266 }
267 
268 }
269 
270 #endif // META_OCEAN_TEST_TESTCV_TESTSYNTHESIS_TEST_MAPPING_F_1_H
Cost function:
Definition: MappingF1.h:52
This class implements Ocean's image class.
Definition: Frame.h:1760
This class implements a synthesis sub-pixel mapping test.
Definition: TestMappingF1.h:34
static bool testTwoPixelPatchOneSubPixelPatch8BitPerChannel(const double testDuration)
Tests the sum square differences function between two pixel accurate image patches and one sub-pixel ...
static bool testApplyMapping(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the applyMapping function for a specific pixel format.
ImplementationType
Definition of individual types of implementation.
Definition: TestMappingF1.h:41
@ IT_NEON
The NEON-based implementation.
Definition: TestMappingF1.h:49
@ IT_SSE
The SSE-based implementation.
Definition: TestMappingF1.h:47
@ IT_TEMPLATE
The template-based implementation.
Definition: TestMappingF1.h:45
@ IT_NAIVE
The naive implementation.
Definition: TestMappingF1.h:43
static uint64_t determineAppearanceCost(const Frame &sourceFrame, const Frame &targetFrame, const Frame &mask, const Vector2 &source, const CV::PixelPosition &target, const unsigned int patchSize, const unsigned int borderFactor, const unsigned int normalizationFactor)
Determines the appearance cost.
static bool testAppearanceReferenceCost5x5(const unsigned int width, const unsigned int height, const double testDuration)
Tests the 5x5 appearance cost function with reference frame.
static bool testAppearanceReferenceCost5x5(const unsigned int width, const unsigned int height, const double testDuration)
Tests the 5x5 appearance cost function with reference frame.
static uint64_t determineAppearanceReferenceCost(const Frame &frame, const Frame &reference, const Frame &mask, const Vector2 &source, const CV::PixelPosition &target, const unsigned int patchSize, const unsigned int borderFactor, const unsigned int normalizationFactor)
Determines the appearance cost with a reference frame.
static bool testApplyMapping(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the applyMapping function.
static bool testTwoPixelPatchOneSubPixelPatch8BitPerChannel(const unsigned int width, const unsigned int height, const double testDuration)
Tests the sum square differences function between two pixel accurate image patches and one sub-pixel ...
static bool testSumSquaredDifference5x5Mask(const unsigned int width, const unsigned int height, const double testDuration)
Tests the sum of squared differences calculation using a mask.
static Vector2 neighborPixel(const Vector2 &position, const CV::PixelDirection pixelDirection)
Returns the neighbor pixel with sub-pixel accuracy.
static bool testAppearanceCost5x5(const unsigned int width, const unsigned int height, const double testDuration)
Tests the 5x5 appearance cost function.
static bool validateMapping(const Frame &frame, const Frame &mask, const CV::Synthesis::MappingF1 &mapping, const CV::PixelBoundingBox &boundingBox)
Validates the mapping results for a frame and corresponding mapping.
static Scalar determineSpatialCost4Neighborhood(const CV::Synthesis::MappingF1 &mapping, const Frame &mask, const Vector2 &source, const CV::PixelPosition &target, const Scalar maxCost, const unsigned int normalizationFactor)
Determines the spatial cost in a 4-neighborhood.
static bool testSpatialCost4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration)
Tests the spatial cost with 4-neighborhood.
static bool testSpatialCost4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration)
Tests the spatial cost with 4-neighborhood.
static bool testAppearanceCost5x5(const unsigned int width, const unsigned int height, const double testDuration)
Tests the 5x5 appearance cost function.
static size_t validateSumSquaredDifference5x5Mask(const Frame &frame0, const Frame &frame1, const Frame &mask0, const CV::PixelPositions &positions0, const Vectors2 &positions1, const Indices32 &results, const unsigned int borderFactor)
Validates the 5x5 sum of squared differences.
static bool testSumSquaredDifference5x5Mask(const unsigned int width, const unsigned int height, const double testDuration)
Tests the sum of squared differences calculation using a mask.
static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests all mapping functions.
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
std::vector< PixelPosition > PixelPositions
Definition of a vector holding pixel positions (with positive coordinate values).
Definition: PixelPosition.h:48
PixelDirection
Definition of individual directions with pixel accuracy.
Definition: CV.h:85
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition: Vector2.h:64
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15