Ocean
Loading...
Searching...
No Matches
testsegmentation/TestMaskAnalyzer.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_TESTSEGMENTATION_TEST_MASK_ANALYZER_H
9#define META_OCEAN_TEST_TESTCV_TESTSEGMENTATION_TEST_MASK_ANALYZER_H
10
12
14
16
18
20
21namespace Ocean
22{
23
24namespace Test
25{
26
27namespace TestCV
28{
29
30namespace TestSegmentation
31{
32
33/**
34 * This class implements a mask analyzer test.
35 * @ingroup testcvsegmentation
36 */
37class OCEAN_TEST_CV_SEGMENTATION_EXPORT TestMaskAnalyzer : public CV::Segmentation::MaskAnalyzer
38{
39 protected:
40
41 /// Function pointer for distance transform the functions `CV::Segmentation::MaskAnalyzer::compute{C,L1,L2}DistanceTransform8Bit()`
42 template <typename TDistanceType>
43 using ComputeDistanceTransformFunctionPointer = bool (*) (const uint8_t*, const uint32_t, const uint32_t, TDistanceType*, uint32_t*, const uint8_t, const uint32_t, const uint32_t);
44
45 /**
46 * Definition of an unordered set holding bounding boxes.
47 */
48 using BoundingBoxSet = std::unordered_set<CV::PixelBoundingBox, CV::PixelBoundingBox>;
49
50 /**
51 * Definition of an unordered set holding pixel positions boxes.
52 */
53 using PixelPositionSet = std::unordered_set<CV::PixelPosition, CV::PixelPosition>;
54
55 public:
56
57 /**
58 * Tests all mask analyzer functions.
59 * @param width The width of the test frame in pixel, with range [32, infinity)
60 * @param height The height of the test frame in pixel, with range [32, infinity)
61 * @param testDuration Number of seconds for each test, with range (0, infinity)
62 * @param worker The worker object to distribute the computational load
63 * @param selector The test selector
64 * @return True, if succeeded
65 */
66 static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker, const TestSelector& selector);
67
68 /**
69 * Tests the has mask neighbor-4 function.
70 * @param testDuration Number of seconds for each test, with range (0, infinity)
71 * @return True, if succeeded
72 */
73 static bool testHasMaskNeighbor4(const double testDuration);
74
75 /**
76 * Tests the has mask neighbor-4 center function.
77 * @param testDuration Number of seconds for each test, with range (0, infinity)
78 * @return True, if succeeded
79 */
80 static bool testHasMaskNeighbor4Center(const double testDuration);
81
82 /**
83 * Tests the has mask neighbor-5 function.
84 * @param testDuration Number of seconds for each test, with range (0, infinity)
85 * @return True, if succeeded
86 */
87 static bool testHasMaskNeighbor5(const double testDuration);
88
89 /**
90 * Tests the has mask neighbor-5 center function.
91 * @param testDuration Number of seconds for each test, with range (0, infinity)
92 * @return True, if succeeded
93 */
94 static bool testHasMaskNeighbor5Center(const double testDuration);
95
96 /**
97 * Tests the has mask neighbor-8 function.
98 * @param testDuration Number of seconds for each test, with range (0, infinity)
99 * @return True, if succeeded
100 */
101 static bool testHasMaskNeighbor8(const double testDuration);
102
103 /**
104 * Tests the has mask neighbor-8 center function.
105 * @param testDuration Number of seconds for each test, with range (0, infinity)
106 * @return True, if succeeded
107 */
108 static bool testHasMaskNeighbor8Center(const double testDuration);
109
110 /**
111 * Tests the has mask neighbor-9 function.
112 * @param testDuration Number of seconds for each test, with range (0, infinity)
113 * @return True, if succeeded
114 */
115 static bool testHasMaskNeighbor9(const double testDuration);
116
117 /**
118 * Tests the has mask neighbor-9 center function.
119 * @param testDuration Number of seconds for each test, with range (0, infinity)
120 * @return True, if succeeded
121 */
122 static bool testHasMaskNeighbor9Center(const double testDuration);
123
124 /**
125 * Tests the distance to border function.
126 * @param testDuration Number of seconds for each test, with range (0, infinity)
127 * @param worker The worker object
128 * @return True, if succeeded
129 */
130 static bool testDetermineDistancesToBorder(const double testDuration, Worker& worker);
131
132 /**
133 * Tests the distance to border function.
134 * @param width The width of the test frame in pixel, with range [32, infinity)
135 * @param height The height of the test frame in pixel, with range [32, infinity)
136 * @param testDuration Number of seconds for each test, with range (0, infinity)
137 * @param maximalDistance The maximal distance to be used, with range [1, infinity)
138 * @param worker The worker object
139 * @return True, if succeeded
140 */
141 static bool testDetermineDistancesToBorder(const unsigned int width, const unsigned int height, const double testDuration, const unsigned int maximalDistance, Worker& worker);
142
143 /**
144 * Tests the find border pixels in a 4-neighborhood function.
145 * @param width The width of the test frame in pixel, with range [32, infinity)
146 * @param height The height of the test frame in pixel, with range [32, infinity)
147 * @param testDuration Number of seconds for each test, with range (0, infinity)
148 * @param worker The worker object
149 * @return True, if succeeded
150 */
151 static bool testFindBorderPixels4(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
152
153 /**
154 * Tests the find border pixels in an 8-neighborhood function.
155 * @param width The width of the test frame in pixel, with range [32, infinity)
156 * @param height The height of the test frame in pixel, with range [32, infinity)
157 * @param testDuration Number of seconds for each test, with range (0, infinity)
158 * @param worker The worker object
159 * @return True, if succeeded
160 */
161 static bool testFindBorderPixels8(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
162
163 /**
164 * Tests the non-unique pixels in a 4-neighborhood function.
165 * @param width The width of the test frame in pixel, with range [32, infinity)
166 * @param height The height of the test frame in pixel, with range [32, infinity)
167 * @param testDuration Number of seconds for each test, with range (0, infinity)
168 * @param worker The worker object
169 * @return True, if succeeded
170 */
171 static bool testFindNonUniquePixels4(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
172
173 /**
174 * Tests the non-unique pixels in an 8-neighborhood function.
175 * @param width The width of the test frame in pixel, with range [32, infinity)
176 * @param height The height of the test frame in pixel, with range [32, infinity)
177 * @param testDuration Number of seconds for each test, with range (0, infinity)
178 * @param worker The worker object
179 * @return True, if succeeded
180 */
181 static bool testFindNonUniquePixels8(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
182
183 /**
184 * Tests the outline pixels in a 4-neighborhood function.
185 * @param width The width of the test frame in pixel, with range [32, infinity)
186 * @param height The height of the test frame in pixel, with range [32, infinity)
187 * @param testDuration Number of seconds for each test, with range (0, infinity)
188 * @return True, if succeeded
189 */
190 static bool testFindOutlinePixels4(const unsigned int width, const unsigned int height, const double testDuration);
191
192 /**
193 * Test the distance transformations that uses the chessboard distance
194 * @param width The width of the source frame in pixel, with range [1, infinity)
195 * @param height The height of the source frame in pixel, with range [1, infinity)
196 * @param testDuration Number of seconds for each test, with range (0, infinity)
197 * @return True, if succeeded
198 */
199 static bool testComputeChessboardDistanceTransform8Bit(const uint32_t width, const uint32_t height, const double testDuration);
200
201 /**
202 * Test the distance transformations that uses the L1 distance
203 * @param width The width of the source frame in pixel, with range [1, infinity)
204 * @param height The height of the source frame in pixel, with range [1, infinity)
205 * @param testDuration Number of seconds for each test, with range (0, infinity)
206 * @return True, if succeeded
207 */
208 static bool testComputeL1DistanceTransform8Bit(const uint32_t width, const uint32_t height, const double testDuration);
209
210 /**
211 * Test the distance transformations that uses the approximated L2 distance
212 * @param width The width of the source frame in pixel, with range [1, infinity)
213 * @param height The height of the source frame in pixel, with range [1, infinity)
214 * @param testDuration Number of seconds for each test, with range (0, infinity)
215 * @return True, if succeeded
216 */
217 static bool testComputeL2DistanceTransform8Bit(const uint32_t width, const uint32_t height, const double testDuration);
218
219 /**
220 * Test the determine bounding boxes function.
221 * @param testDuration Number of seconds for each test, with range (0, infinity)
222 * @return True, if succeeded
223 */
224 static bool testDetectBoundingBoxes(const double testDuration);
225
226 /**
227 * Tests the count mask pixels functions.
228 * @param testDuration Number of seconds for each test, with range (0, infinity)
229 * @return True, if succeeded
230 */
231 static bool testCountMaskPixels(const double testDuration);
232
233 /**
234 * Generates test data for the mask analyzer tests
235 * This will generate a white mask frame with a black cross in the center, with 20 pixel width
236 * @param randomGenerator The random generator to be used
237 * @param width The width of the frame that will be generated, range: [1, infinity)
238 * @param height The height of the frame that will be generated, range: [1, infinity)
239 * @param maskValue The value of mask pixels, with range [0, 255]
240 * @param nonMaskValue The value of non-mask pixels, with range [0, 255] without 'maskValue'
241 * @return The generated test frame
242 */
243 static Frame generateTestMask(RandomGenerator& randomGenerator, const unsigned int width, const unsigned int height, const uint8_t maskValue = 0x00u, const uint8_t nonMaskValue = 0xFFu);
244
245 protected:
246
247 /**
248 * Test for distance transform functions
249 * @note The function that can be tested with this function must have an interface as defined by `TestDistanceTransform::ComputeDistanceTransformFunctionPointer`
250 * @param width The width of the images that are used for the performance tests, range: [1, infinity)
251 * @param height The height of the image that are used for the performance tests, range: [1, infinity)
252 * @param computeDistanceTransformPtr A pointer to distance transformation function in `CV::DistanceTransform` that will be tested, must be valid
253 * @param distanceVerticalHorizontal The cost of a vertical/horizontal step; must match the cost of the function that is tested, range: (0, infinity)
254 * @param distanceDiagonal The cost of diagonal step; must match the cost of the function that is tested, range: (0, infinity)
255 * @param testDuration Number of seconds for each test, with range (0, infinity)
256 * @return True if the validation was successful, otherwise false
257 * @tparam TDistanceType The data type of the resulting distance transform, must be integral or floating-point
258 */
259 template <typename TDistanceType>
260 static bool testComputeDistanceTransform8Bit(const uint32_t width, const uint32_t height, ComputeDistanceTransformFunctionPointer<TDistanceType> computeDistanceTransformPtr, const TDistanceType distanceVerticalHorizontal, const TDistanceType distanceDiagonal, const double testDuration);
261
262 /**
263 * Validates the distance to border function.
264 * @param mask The original mask frame, must be valid
265 * @param distance The corresponding distance frame to validate, must be valid
266 * @param maximalDistance Maximal distance to be determined
267 * @param assignFinal True, to assign each mask pixel a minimal distance after the final iteration
268 * @return True, if succeeded
269 */
270 static bool validateDetermineDistancesToBorder(const Frame& mask, const Frame& distance, const unsigned int maximalDistance, const bool assignFinal);
271
272 /**
273 * Validates the find border pixels in a 4-neighborhood function.
274 * @param mask The mask to verify, must be valid
275 * @param boundingBox The bounding box which has been used, invalid to use the entire mask
276 * @param borderPixels The border pixels to verify
277 * @return True, if succeeded
278 */
279 static bool validateFindBorderPixels4(const Frame& mask, const CV::PixelBoundingBox& boundingBox, const CV::PixelPositions& borderPixels);
280
281 /**
282 * Validates the find border pixels in an 8-neighborhood function.
283 * @param mask The mask to verify, must be valid
284 * @param boundingBox The bounding box which has been used, invalid to use the entire mask
285 * @param borderPixels The border pixels to verify
286 * @return True, if succeeded
287 */
288 static bool validateFindBorderPixels8(const Frame& mask, const CV::PixelBoundingBox& boundingBox, const CV::PixelPositions& borderPixels);
289
290 /**
291 * Validates the find non-unique pixels in a 4-neighborhood function.
292 * @param mask The mask to verify, must be valid
293 * @param boundingBox The bounding box which has been used, invalid to use the entire mask
294 * @param nonUniquePixels The on unique pixels to verify
295 * @return True, if succeeded
296 */
297 static bool validateFindNonUniquePixels4(const Frame& mask, const CV::PixelBoundingBox& boundingBox, const CV::PixelPositions& nonUniquePixels);
298
299 /**
300 * Validates the find non-unique pixels in an 8-neighborhood function.
301 * @param mask The mask to verify, must be valid
302 * @param boundingBox The bounding box which has been used, invalid to use the entire mask
303 * @param nonUniquePixels The on unique pixels to verify
304 * @return True, if succeeded
305 */
306 static bool validateFindNonUniquePixels8(const Frame& mask, const CV::PixelBoundingBox& boundingBox, const CV::PixelPositions& nonUniquePixels);
307
308 /**
309 * Validates the find outline pixels in a 4-neighborhood function.
310 * @param mask The mask to verify, must be valid
311 * @param boundingBox The bounding box which has been used, invalid to use the entire mask
312 * @param outlinePixels The outline pixels to verify
313 * @param nonMaskValue The value of non-mask pixels, with range [0, 255] without 'maskValue'
314 * @return True, if succeeded
315 */
316 static bool validateFindOutlinePixels4(const Frame& mask, const CV::PixelBoundingBox& boundingBox, const CV::PixelPositions& outlinePixels, const uint8_t nonMaskValue);
317
318 /**
319 * Validation function for the distance transform function
320 * @param source A pointer to the source frame data, must be valid
321 * @param width The width of the source frame, range: [1, infinity)
322 * @param height The height of the source frame, range: [1, infinity)
323 * @param validationTarget A pointer to the result of a distance transform that will be validated, must be valid and have the same size as the source frame
324 * @param validationTargetStatus The return value of the distance transform function that will be validated
325 * @param distanceVerticalHorizontal e cost of a vertical/horizontal step; must match the cost of the function that is tested, range: (0, infinity)
326 * @param distanceDiagonal The cost of diagonal step; must match the cost of the function that is tested, range: (0, infinity)
327 * @param referenceValue Distance values pixels will be computed to the closest pixel with this reference value, range: [0, 255] and must match that of the distance transform that is validated
328 * @param sourcePaddingElements Optional number of padding elements of the source frame, range: [0, infinity)
329 * @param validationTargetPaddingElements Optional number padding elements of the target frame, range: [0, infinity)
330 * @return True if the validation was successful, otherwise false
331 * @tparam TDistanceType The data type of the distance transform that will be validated, this must be an integral or floating-point type
332 */
333 template <typename TDistanceType>
334 static bool validateComputeDistanceTransform8Bit(const uint8_t* source, const uint32_t width, const uint32_t height, const TDistanceType* validationTarget, const bool validationTargetStatus, const TDistanceType distanceVerticalHorizontal, const TDistanceType distanceDiagonal, const uint8_t referenceValue, const uint32_t sourcePaddingElements = 0u, const uint32_t validationTargetPaddingElements = 0u);
335};
336
337} // namespace TestSegmentation
338
339} // namespace TestCV
340
341} // namespace Test
342
343} // namespace Ocean
344
345#endif // META_OCEAN_TEST_TESTCV_TESTSEGMENTATION_TEST_MASK_ANALYZER_H
This class implements functions analyzing masks, determining specific pixels in relation to masks and...
Definition segmentation/MaskAnalyzer.h:39
This class implements Ocean's image class.
Definition Frame.h:1879
This class implements a generator for random numbers.
Definition RandomGenerator.h:42
This class implements a mask analyzer test.
Definition testsegmentation/TestMaskAnalyzer.h:38
static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker, const TestSelector &selector)
Tests all mask analyzer functions.
static bool validateFindBorderPixels4(const Frame &mask, const CV::PixelBoundingBox &boundingBox, const CV::PixelPositions &borderPixels)
Validates the find border pixels in a 4-neighborhood function.
static bool testFindNonUniquePixels8(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the non-unique pixels in an 8-neighborhood function.
static bool testHasMaskNeighbor9Center(const double testDuration)
Tests the has mask neighbor-9 center function.
static bool testHasMaskNeighbor5Center(const double testDuration)
Tests the has mask neighbor-5 center function.
static bool testFindBorderPixels8(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the find border pixels in an 8-neighborhood function.
static bool validateFindNonUniquePixels4(const Frame &mask, const CV::PixelBoundingBox &boundingBox, const CV::PixelPositions &nonUniquePixels)
Validates the find non-unique pixels in a 4-neighborhood function.
static bool testComputeDistanceTransform8Bit(const uint32_t width, const uint32_t height, ComputeDistanceTransformFunctionPointer< TDistanceType > computeDistanceTransformPtr, const TDistanceType distanceVerticalHorizontal, const TDistanceType distanceDiagonal, const double testDuration)
Test for distance transform functions.
static bool testHasMaskNeighbor8(const double testDuration)
Tests the has mask neighbor-8 function.
static bool testCountMaskPixels(const double testDuration)
Tests the count mask pixels functions.
static bool testFindOutlinePixels4(const unsigned int width, const unsigned int height, const double testDuration)
Tests the outline pixels in a 4-neighborhood function.
static bool validateFindNonUniquePixels8(const Frame &mask, const CV::PixelBoundingBox &boundingBox, const CV::PixelPositions &nonUniquePixels)
Validates the find non-unique pixels in an 8-neighborhood function.
std::unordered_set< CV::PixelPosition, CV::PixelPosition > PixelPositionSet
Definition of an unordered set holding pixel positions boxes.
Definition testsegmentation/TestMaskAnalyzer.h:53
static bool validateComputeDistanceTransform8Bit(const uint8_t *source, const uint32_t width, const uint32_t height, const TDistanceType *validationTarget, const bool validationTargetStatus, const TDistanceType distanceVerticalHorizontal, const TDistanceType distanceDiagonal, const uint8_t referenceValue, const uint32_t sourcePaddingElements=0u, const uint32_t validationTargetPaddingElements=0u)
Validation function for the distance transform function.
static bool testComputeL2DistanceTransform8Bit(const uint32_t width, const uint32_t height, const double testDuration)
Test the distance transformations that uses the approximated L2 distance.
static bool testDetermineDistancesToBorder(const double testDuration, Worker &worker)
Tests the distance to border function.
static bool validateFindBorderPixels8(const Frame &mask, const CV::PixelBoundingBox &boundingBox, const CV::PixelPositions &borderPixels)
Validates the find border pixels in an 8-neighborhood function.
bool(*)(const uint8_t *, const uint32_t, const uint32_t, TDistanceType *, uint32_t *, const uint8_t, const uint32_t, const uint32_t) ComputeDistanceTransformFunctionPointer
Function pointer for distance transform the functions CV::Segmentation::MaskAnalyzer::compute{C,...
Definition testsegmentation/TestMaskAnalyzer.h:43
static bool testComputeChessboardDistanceTransform8Bit(const uint32_t width, const uint32_t height, const double testDuration)
Test the distance transformations that uses the chessboard distance.
std::unordered_set< CV::PixelBoundingBox, CV::PixelBoundingBox > BoundingBoxSet
Definition of an unordered set holding bounding boxes.
Definition testsegmentation/TestMaskAnalyzer.h:48
static bool testHasMaskNeighbor4(const double testDuration)
Tests the has mask neighbor-4 function.
static bool testHasMaskNeighbor4Center(const double testDuration)
Tests the has mask neighbor-4 center function.
static bool validateDetermineDistancesToBorder(const Frame &mask, const Frame &distance, const unsigned int maximalDistance, const bool assignFinal)
Validates the distance to border function.
static bool testHasMaskNeighbor9(const double testDuration)
Tests the has mask neighbor-9 function.
static bool testFindNonUniquePixels4(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the non-unique pixels in a 4-neighborhood function.
static bool testFindBorderPixels4(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the find border pixels in a 4-neighborhood function.
static bool testHasMaskNeighbor5(const double testDuration)
Tests the has mask neighbor-5 function.
static Frame generateTestMask(RandomGenerator &randomGenerator, const unsigned int width, const unsigned int height, const uint8_t maskValue=0x00u, const uint8_t nonMaskValue=0xFFu)
Generates test data for the mask analyzer tests This will generate a white mask frame with a black cr...
static bool testDetectBoundingBoxes(const double testDuration)
Test the determine bounding boxes function.
static bool testHasMaskNeighbor8Center(const double testDuration)
Tests the has mask neighbor-8 center function.
static bool testComputeL1DistanceTransform8Bit(const uint32_t width, const uint32_t height, const double testDuration)
Test the distance transformations that uses the L1 distance.
static bool testDetermineDistancesToBorder(const unsigned int width, const unsigned int height, const double testDuration, const unsigned int maximalDistance, Worker &worker)
Tests the distance to border function.
static bool validateFindOutlinePixels4(const Frame &mask, const CV::PixelBoundingBox &boundingBox, const CV::PixelPositions &outlinePixels, const uint8_t nonMaskValue)
Validates the find outline pixels in a 4-neighborhood function.
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< PixelPosition > PixelPositions
Definition of a vector holding pixel positions (with positive coordinate values).
Definition PixelPosition.h:46
The namespace covering the entire Ocean framework.
Definition Accessor.h:15