Ocean
TestMappingI1.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_I_1_H
9 #define META_OCEAN_TEST_TESTCV_TESTSYNTHESIS_TEST_MAPPING_I_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 pixel mapping test.
31  * @ingroup testcvsynthesis
32  */
33 class OCEAN_TEST_CV_SYNTHESIS_EXPORT TestMappingI1 : protected CV::Synthesis::MappingI1
34 {
35  public:
36 
37  /**
38  * Tests all mapping functions.
39  * @param width The width of the source frame in pixel, with range [1, infinity)
40  * @param height The height of the source frame in pixel, with range [1, infinity)
41  * @param testDuration Number of seconds for each test, with range (0, infinity)
42  * @param worker The worker object to distribute the CPU load
43  * @return True, if succeeded
44  */
45  static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
46 
47  /**
48  * Tests the applyMapping function.
49  * @param width The width of the source frame in pixel, with range [1, infinity)
50  * @param height The height of the source frame in pixel, with range [1, infinity)
51  * @param testDuration Number of seconds for each test, with range (0, infinity)
52  * @param worker The worker object to distribute the CPU load
53  * @return True, if succeeded
54  */
55  static bool testApplyMapping(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
56 
57  /**
58  * Tests the applyMapping function for a specific pixel format.
59  * @param width The width of the source frame in pixel, with range [1, infinity)
60  * @param height The height of the source frame in pixel, with range [1, infinity)
61  * @param channels The number of frame channels to be used, 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  * @return True, if succeeded
65  */
66  static bool testApplyMapping(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
67 
68  /**
69  * Tests the sum of squared differences calculation using a mask and skipping the center pixel.
70  * @param width The width of the source frame in pixel, with range [1, infinity)
71  * @param height The height of the source frame in pixel, with range [1, infinity)
72  * @param testDuration Number of seconds for each test, with range (0, infinity)
73  * @return True, if succeeded
74  */
75  static bool testSumSquaredDifference5x5MaskNoCenter(const unsigned int width, const unsigned int height, const double testDuration);
76 
77  /**
78  * Tests the sum of squared differences calculation using a mask and skipping the center pixel.
79  * @param width The width of the source frame in pixel, with range [1, infinity)
80  * @param height The height of the source frame in pixel, with range [1, infinity)
81  * @param testDuration Number of seconds for each test, with range (0, infinity)
82  * @return True, if succeeded
83  * @tparam tChannels The number of frame channels to be used, with range [1, infinity)
84  */
85  template <unsigned int tChannels>
86  static bool testSumSquaredDifference5x5MaskNoCenter(const unsigned int width, const unsigned int height, const double testDuration);
87 
88  /**
89  * Tests the 5x5 appearance cost function.
90  * @param width The width of the source frame in pixel, with range [1, infinity)
91  * @param height The height of the source frame in pixel, with range [1, infinity)
92  * @param testDuration Number of seconds for each test, with range (0, infinity)
93  * @return True, if succeeded
94  */
95  static bool testAppearanceCost5x5(const unsigned int width, const unsigned int height, const double testDuration);
96 
97  /**
98  * Tests the 5x5 appearance cost function.
99  * @param width The width of the source frame in pixel, with range [1, infinity)
100  * @param height The height of the source frame in pixel, with range [1, infinity)
101  * @param testDuration Number of seconds for each test, with range (0, infinity)
102  * @return True, if succeeded
103  * @tparam tChannels The number of frame channels to be used, with range [1, infinity)
104  */
105  template <unsigned int tChannels>
106  static bool testAppearanceCost5x5(const unsigned int width, const unsigned int height, const double testDuration);
107 
108  /**
109  * Tests the spatial cost with 4-neighborhood.
110  * @param width The width of the source frame in pixel, with range [1, infinity)
111  * @param height The height of the source frame in pixel, with range [1, infinity)
112  * @param testDuration Number of seconds for each test, with range (0, infinity)
113  * @return True, if succeeded
114  */
115  static bool testSpatialCost4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration);
116 
117  /**
118  * Tests the spatial cost with 4-neighborhood.
119  * @param width The width of the source frame in pixel, with range [1, infinity)
120  * @param height The height of the source frame in pixel, with range [1, 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 to be used, with range [1, infinity)
124  */
125  template <unsigned int tChannels>
126  static bool testSpatialCost4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration);
127 
128  /**
129  * Tests the spatial cost with 8-neighborhood.
130  * @param width The width of the source frame in pixel, with range [1, infinity)
131  * @param height The height of the source frame in pixel, with range [1, infinity)
132  * @param testDuration Number of seconds for each test, with range (0, infinity)
133  * @return True, if succeeded
134  */
135  static bool testSpatialCost8Neighborhood(const unsigned int width, const unsigned int height, const double testDuration);
136 
137  /**
138  * Tests the spatial cost with 8-neighborhood.
139  * @param width The width of the source frame in pixel, with range [1, infinity)
140  * @param height The height of the source frame in pixel, with range [1, infinity)
141  * @param testDuration Number of seconds for each test, with range (0, infinity)
142  * @return True, if succeeded
143  * @tparam tChannels The number of frame channels to be used, with range [1, infinity)
144  */
145  template <unsigned int tChannels>
146  static bool testSpatialCost8Neighborhood(const unsigned int width, const unsigned int height, const double testDuration);
147 
148  private:
149 
150  /**
151  * Validates the mapping results for a frame and corresponding mapping.
152  * @param frame The result frame, must be valid
153  * @param mask The mask frame, must be valid
154  * @param mapping The mapping which has been used
155  * @param boundingBox The bounding box defining the area of interest, must be valid
156  * @return True, if succeeded
157  */
158  static bool validateMapping(const Frame& frame, const Frame& mask, const CV::Synthesis::MappingI1& mapping, const CV::PixelBoundingBox& boundingBox);
159 
160  /**
161  * Validates the 5x5 sum of squared differences skipping the center pixel.
162  * @param frame0 The first frame, must be valid
163  * @param frame1 The second frame, must be valid
164  * @param mask0 The mask for the first frame, must be valid
165  * @param topLeftPositions0 The top left positions in the first frame
166  * @param topLeftPositions1 The top left positions in the second frame
167  * @param results The SSD results to verify, one for each position
168  * @param borderFactor The border factor to be used
169  * @return True, if succeeded
170  */
171  static bool validateSumSquaredDifference5x5MaskNoCenter(const Frame& frame0, const Frame& frame1, const Frame& mask0, const CV::PixelPositions& topLeftPositions0, const CV::PixelPositions& topLeftPositions1, const Indices32& results, const unsigned int borderFactor);
172 
173  /**
174  * Determines the appearance cost.
175  * @param frame The frame for which the cost will be determined, must be valid
176  * @param mask The mask associated with the frame, defining valid and invalid frame pixels, must be valid
177  * @param source The source location within the frame, with range [0, frame.width()-1]x[0, frame.height()-1]
178  * @param target The target location within the frame, with range [0, frame.width()-1]x[0, frame.height()-1]
179  * @param patchSize The size of the image patch, in pixels, with range [1, infinity), must be odd
180  * @param borderFactor The factor which will be applied to target pixels outside of the mask, with range [1, infinity)
181  * @param normalizationFactor The normalization factor to be applied, with range [1, infinity)
182  * @return The resulting cost
183  */
184  static uint64_t determineAppearanceCost(const Frame& frame, const Frame& mask, const CV::PixelPosition& source, const CV::PixelPosition& target, const unsigned int patchSize, const unsigned int borderFactor, const unsigned int normalizationFactor);
185 
186  /**
187  * Determines the spatial cost in a 4-neighborhood.
188  * @param mapping The mapping to be used, must be valid
189  * @param mask The mask associated with the frame, defining valid and invalid frame pixels, must be valid
190  * @param source The source location within the frame, with range [0, frame.width()-1]x[0, frame.height()-1]
191  * @param target The target location within the frame, with range [0, frame.width()-1]x[0, frame.height()-1]
192  * @param maxCost The maximal cost, with range [0, infinity)
193  * @param normalizationFactor The normalization factor to be applied, with range [1, infinity)
194  * @return The resulting cost
195  */
196  static uint64_t determineSpatialCost4Neighborhood(const CV::Synthesis::MappingI1& mapping, const Frame& mask, const CV::PixelPosition& source, const CV::PixelPosition& target, const uint32_t maxCost, const unsigned int normalizationFactor);
197 
198  /**
199  * Determines the spatial cost in a 8-neighborhood.
200  * @param mapping The mapping to be used, must be valid
201  * @param mask The mask associated with the frame, defining valid and invalid frame pixels, must be valid
202  * @param source The source location within the frame, with range [0, frame.width()-1]x[0, frame.height()-1]
203  * @param target The target location within the frame, with range [0, frame.width()-1]x[0, frame.height()-1]
204  * @param maxCost The maximal cost, with range [0, infinity)
205  * @param normalizationFactor The normalization factor to be applied, with range [1, infinity)
206  * @return The resulting cost
207  */
208  static uint64_t determineSpatialCost8Neighborhood(const CV::Synthesis::MappingI1& mapping, const Frame& mask, const CV::PixelPosition& source, const CV::PixelPosition& target, const uint32_t maxCost, const unsigned int normalizationFactor);
209 };
210 
211 }
212 
213 }
214 
215 }
216 
217 }
218 
219 #endif // META_OCEAN_TEST_TESTCV_TESTSYNTHESIS_TEST_MAPPING_I_1_H
This class implements the pixel mapping between source and target frames.
Definition: MappingI1.h:49
This class implements Ocean's image class.
Definition: Frame.h:1760
This class implements a synthesis pixel mapping test.
Definition: TestMappingI1.h:34
static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
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 uint64_t determineAppearanceCost(const Frame &frame, const Frame &mask, const CV::PixelPosition &source, const CV::PixelPosition &target, const unsigned int patchSize, const unsigned int borderFactor, const unsigned int normalizationFactor)
Determines the appearance cost.
static bool testSpatialCost8Neighborhood(const unsigned int width, const unsigned int height, const double testDuration)
Tests the spatial cost with 8-neighborhood.
static uint64_t determineSpatialCost4Neighborhood(const CV::Synthesis::MappingI1 &mapping, const Frame &mask, const CV::PixelPosition &source, const CV::PixelPosition &target, const uint32_t maxCost, const unsigned int normalizationFactor)
Determines the spatial cost in a 4-neighborhood.
static bool testAppearanceCost5x5(const unsigned int width, const unsigned int height, const double testDuration)
Tests the 5x5 appearance cost function.
static bool testSpatialCost4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration)
Tests the spatial cost with 4-neighborhood.
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.
static bool testSumSquaredDifference5x5MaskNoCenter(const unsigned int width, const unsigned int height, const double testDuration)
Tests the sum of squared differences calculation using a mask and skipping the center pixel.
static bool testSumSquaredDifference5x5MaskNoCenter(const unsigned int width, const unsigned int height, const double testDuration)
Tests the sum of squared differences calculation using a mask and skipping the center pixel.
static bool validateSumSquaredDifference5x5MaskNoCenter(const Frame &frame0, const Frame &frame1, const Frame &mask0, const CV::PixelPositions &topLeftPositions0, const CV::PixelPositions &topLeftPositions1, const Indices32 &results, const unsigned int borderFactor)
Validates the 5x5 sum of squared differences skipping the center pixel.
static bool testAppearanceCost5x5(const unsigned int width, const unsigned int height, const double testDuration)
Tests the 5x5 appearance cost function.
static uint64_t determineSpatialCost8Neighborhood(const CV::Synthesis::MappingI1 &mapping, const Frame &mask, const CV::PixelPosition &source, const CV::PixelPosition &target, const uint32_t maxCost, const unsigned int normalizationFactor)
Determines the spatial cost in a 8-neighborhood.
static bool testSpatialCost8Neighborhood(const unsigned int width, const unsigned int height, const double testDuration)
Tests the spatial cost with 8-neighborhood.
static bool testApplyMapping(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the applyMapping function.
static bool validateMapping(const Frame &frame, const Frame &mask, const CV::Synthesis::MappingI1 &mapping, const CV::PixelBoundingBox &boundingBox)
Validates the mapping results for a frame and corresponding mapping.
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
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15