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