Ocean
Loading...
Searching...
No Matches
TestInitializerI1.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_INITIALIZER_I_1_H
9#define META_OCEAN_TEST_TESTCV_TESTSYNTHESIS_TEST_INITIALIZER_I_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 test for initializers with one frame.
33 * @ingroup testcvsynthesis
34 */
35class OCEAN_TEST_CV_SYNTHESIS_EXPORT TestInitializerI1
36{
37 protected:
38
39 /**
40 * Helper function allowing to keep properties of a pixel to be inpainted.
41 */
42 class OCEAN_TEST_CV_SYNTHESIS_EXPORT InpaintingPixel final : public CV::PixelPosition
43 {
44 public:
45
46 /**
47 * Creates a new pixel.
48 * @param pixelPosition The position of the pixel in the frame, with range [0, mask.width() - 1]x[0, mask.height() - 1]
49 * @param mask The mask identifying valid pixels, must be valid
50 * @param sobel The sobel responses of the frame to be inpainted, must be valid
51 */
52 InpaintingPixel(const CV::PixelPosition& pixelPosition, const Frame& mask, const Frame& sobel);
53
54 /**
55 * Returns the border direction of this pixel.
56 * @return The pixel's border direction
57 */
58 const VectorI2& borderDirection() const;
59
60 /**
61 * Returns whether this pixel has a lower priority of a second pixel.
62 * @param inpaintingPixel The second inpainting pixel to compare
63 * @return True, if so
64 */
65 bool operator<(const InpaintingPixel& inpaintingPixel) const;
66
67 protected:
68
69 /**
70 * Determines the border direction of this pixel.
71 * @param mask The mask identifying valid pixels, must be valid
72 * @return The resulting border direction
73 */
75
76 /**
77 * Determines the image orientation of this pixel.
78 * @param mask The mask identifying valid pixels, must be valid
79 * @param sobel The sobel responses of the frame to be inpainted, must be valid
80 * @return The resulting image orientation
81 */
82 VectorI2 determineImageOrientation(const Frame& mask, const Frame& sobel) const;
83
84 protected:
85
86 /// The pixel's border direction.
87 VectorI2 borderDirection_ = VectorI2(0, 0);
88
89 /// The image orientation.
90 VectorI2 imageOrientation_ = VectorI2(0, 0);
91
92 /// The pixel's priority.
93 unsigned int priority_ = 0u;
94 };
95
96 /**
97 * Definition of a vector holding inpainting pixels.
98 */
99 using InpaintingPixels = std::vector<InpaintingPixel>;
100
101 public:
102
103 /**
104 * Invokes all test functions.
105 * @param width The width of the source frame in pixel, with range [1, infinity)
106 * @param height The height of the source frame in pixel, with range [1, infinity)
107 * @param testDuration Number of seconds for each test, with range (0, infinity)
108 * @param worker The worker object to distribute the CPU load
109 * @param selector The test selector
110 * @return True, if succeeded
111 */
112 static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker, const TestSelector& selector);
113
114 /**
115 * Tests the area constrained appearance mapping initializer.
116 * @param width The width of the source frame in pixel, with range [1, infinity)
117 * @param height The height of the source frame in pixel, with range [1, infinity)
118 * @param testDuration Number of seconds for each test, with range (0, infinity)
119 * @param worker The worker object to distribute the CPU load
120 * @return True, if succeeded
121 */
122 static bool testAppearanceMappingAreaConstrained(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
123
124 /**
125 * Tests the area constrained appearance mapping initializer.
126 * @param width The width of the source frame in pixel, with range [1, infinity)
127 * @param height The height of the source frame in pixel, with range [1, infinity)
128 * @param channels The number of frame channels which will be used during the test, with range [1, infinity)
129 * @param testDuration Number of seconds for each test, with range (0, infinity)
130 * @param worker The worker object to distribute the CPU load
131 * @return True, if succeeded
132 */
133 static bool testAppearanceMappingAreaConstrained(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
134
135 /**
136 * Tests the appearance mapping initializer.
137 * @param width The width of the source frame in pixel, with range [1, infinity)
138 * @param height The height of the source frame in pixel, with range [1, infinity)
139 * @param testDuration Number of seconds for each test, with range (0, infinity)
140 * @param worker The worker object to distribute the CPU load
141 * @return True, if succeeded
142 */
143 static bool testAppearanceMapping(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
144
145 /**
146 * Tests the appearance mapping initializer.
147 * @param width The width of the source frame in pixel, with range [1, infinity)
148 * @param height The height of the source frame in pixel, with range [1, infinity)
149 * @param channels The number of frame channels which will be used during the test, with range [1, infinity)
150 * @param testDuration Number of seconds for each test, with range (0, infinity)
151 * @param worker The worker object to distribute the CPU load
152 * @return True, if succeeded
153 */
154 static bool testAppearanceMapping(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
155
156 /**
157 * Tests the coarser mapping adaption initializer.
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 * @param worker The worker object to distribute the CPU load
162 * @return True, if succeeded
163 */
164 static bool testCoarserMappingAdaption(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
165
166 /**
167 * Tests the coarser mapping adaption initializer.
168 * @param width The width of the source frame in pixel, with range [1, infinity)
169 * @param height The height of the source frame in pixel, with range [1, infinity)
170 * @param channels The number of frame channels which will be used during the test, with range [1, infinity)
171 * @param testDuration Number of seconds for each test, with range (0, infinity)
172 * @param worker The worker object to distribute the CPU load
173 * @return True, if succeeded
174 */
175 static bool testCoarserMappingAdaption(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
176
177 /**
178 * Tests the area constrained coarser mapping adaption initializer.
179 * @param width The width of the source frame in pixel, with range [1, infinity)
180 * @param height The height of the source frame in pixel, with range [1, infinity)
181 * @param testDuration Number of seconds for each test, with range (0, infinity)
182 * @param worker The worker object to distribute the CPU load
183 * @return True, if succeeded
184 */
185 static bool testCoarserMappingAdaptionAreaConstrained(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
186
187 /**
188 * Tests the area constrained coarser mapping adaption initializer.
189 * @param width The width of the source frame in pixel, with range [1, infinity)
190 * @param height The height of the source frame in pixel, with range [1, infinity)
191 * @param channels The number of frame channels which will be used during the test, with range [1, infinity)
192 * @param testDuration Number of seconds for each test, with range (0, infinity)
193 * @param worker The worker object to distribute the CPU load
194 * @return True, if succeeded
195 */
196 static bool testCoarserMappingAdaptionAreaConstrained(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
197
198 /**
199 * Tests the spatial cost mask coarser mapping adaption initializer.
200 * @param width The width of the source frame in pixel, with range [1, infinity)
201 * @param height The height of the source frame in pixel, with range [1, infinity)
202 * @param testDuration Number of seconds for each test, with range (0, infinity)
203 * @param worker The worker object to distribute the CPU load
204 * @return True, if succeeded
205 */
206 static bool testCoarserMappingAdaptionSpatialCostMask(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
207
208 /**
209 * Tests the spatial cost mask coarser mapping adaption initializer.
210 * @param width The width of the source frame in pixel, with range [1, infinity)
211 * @param height The height of the source frame in pixel, with range [1, infinity)
212 * @param channels The number of frame channels which will be used during the test, with range [1, infinity)
213 * @param testDuration Number of seconds for each test, with range (0, infinity)
214 * @param worker The worker object to distribute the CPU load
215 * @return True, if succeeded
216 */
217 static bool testCoarserMappingAdaptionSpatialCostMask(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
218
219 /**
220 * Tests the random mapping initializer.
221 * @param testDuration Number of seconds for each test, with range (0, infinity)
222 * @param worker The worker object to distribute the CPU load
223 * @return True, if succeeded
224 */
225 static bool testRandomMapping(const double testDuration, Worker& worker);
226
227 /**
228 * Tests the area constrained random mapping initializer.
229 * @param testDuration Number of seconds for each test, with range (0, infinity)
230 * @param worker The worker object to distribute the CPU load
231 * @return True, if succeeded
232 */
233 static bool testRandomMappingAreaConstrained(const double testDuration, Worker& worker);
234
235 /**
236 * Tests the deterministic erosion shrinking initializer.
237 * @param width The width of the source frame in pixel, with range [1, infinity)
238 * @param height The height of the source frame in pixel, with range [1, infinity)
239 * @param testDuration Number of seconds for each test, with range (0, infinity)
240 * @param worker The worker object to distribute the CPU load
241 * @return True, if succeeded
242 */
243 static bool testShrinkingErosion(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
244
245 /**
246 * Tests the deterministic erosion shrinking initializer.
247 * @param width The width of the source frame in pixel, with range [1, infinity)
248 * @param height The height of the source frame in pixel, with range [1, infinity)
249 * @param channels The number of frame channels which will be used during the test, with range [1, infinity)
250 * @param testDuration Number of seconds for each test, with range (0, infinity)
251 * @param worker The worker object to distribute the CPU load
252 * @return True, if succeeded
253 */
254 static bool testShrinkingErosion(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
255
256 /**
257 * Tests the randomized erosion shrinking initializer.
258 * @param width The width of the source frame in pixel, with range [1, infinity)
259 * @param height The height of the source frame in pixel, with range [1, infinity)
260 * @param testDuration Number of seconds for each test, with range (0, infinity)
261 * @param worker The worker object to distribute the CPU load
262 * @return True, if succeeded
263 */
264 static bool testShrinkingErosionRandomized(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
265
266 /**
267 * Tests the randomized erosion shrinking initializer.
268 * @param width The width of the source frame in pixel, with range [1, infinity)
269 * @param height The height of the source frame in pixel, with range [1, infinity)
270 * @param channels The number of frame channels which will be used during the test, with range [1, infinity)
271 * @param testDuration Number of seconds for each test, with range (0, infinity)
272 * @param worker The worker object to distribute the CPU load
273 * @return True, if succeeded
274 */
275 static bool testShrinkingErosionRandomized(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
276
277 /**
278 * Tests the patch matching shrinking initializer.
279 * @param testDuration Number of seconds for each test, with range (0, infinity)
280 * @param worker The worker object to distribute the CPU load
281 * @return True, if succeeded
282 */
283 static bool testShrinkingPatchMatching(const double testDuration, Worker& worker);
284
285 /**
286 * Tests the patch matching shrinking initializer.
287 * @param width The width of the source frame in pixel, with range [1, infinity)
288 * @param height The height of the source frame in pixel, with range [1, infinity)
289 * @param channels The number of frame channels which will be used during the test, with range [1, infinity)
290 * @param testDuration Number of seconds for each test, with range (0, infinity)
291 * @param worker The worker object to distribute the CPU load
292 * @return True, if succeeded
293 */
294 static bool testShrinkingPatchMatching(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
295
296 protected:
297
298 /**
299 * Invokes one shrinking iteration.
300 * @param frame The frame to which the shrinking iteration will be applied, will be modified, must be valid
301 * @param mask The mask identifying valid pixels, will be modified, must be valid if 'useMaskForSSD == true'
302 * @param mapping The current mapping, will be modified
303 * @param useHeuristic True, to use a heuristic during shrinking; False, to skip the heuristic
304 * @param maximalRadius The maximal search radius, in pixels, with range [1, infinity)
305 * @param randomGenerator The random generator to use
306 * @param useMaskForSSD True, to use the mask during SSD calculation
307 * @param worker The worker object to distribute the CPU load
308 * @return True, if succeeded
309 */
310 static bool shrinkPatchMatchingIteration(Frame& frame, Frame& mask, CV::Synthesis::MappingI1& mapping, const bool useHeuristic, const unsigned int maximalRadius, RandomGenerator& randomGenerator, const bool useMaskForSSD, Worker& worker);
311
312 /**
313 * Determines the SSD between two image patches.
314 * @param frame The frame for which the ssd will be determined, must be valid
315 * @param mask The mask identifying valid pixels, must be valid if 'useMaskForSSD == true'
316 * @param patchSize The size of the image patch, with range [1, infinity), must be odd
317 * @param inpaintingPosition The target position which should have an invalid pixel
318 * @param sourcePosition The source position which should have a valid pixel
319 * @param useMaskForSSD True, to use the mask; False, to ignore the mask
320 * @return The resulting SSD, -1 if the SSD could not be determined
321 */
322 static unsigned int determineSSD(const Frame& frame, const Frame& mask, const unsigned int patchSize, const CV::PixelPosition& inpaintingPosition, const CV::PixelPosition& sourcePosition, const bool useMaskForSSD);
323
324 /**
325 * Returns whether all mask pixels in a neighborhood have a specific value.
326 * @param mask The mask to be checked, must be valid
327 * @param x The horizontal center location, with range [0, mask.width() - 1]
328 * @param y The vertical center location, with range [0, mask.height() - 1]
329 * @param value The value to check, with range [0, infinity)
330 * @param neighborhood The size of the neighborhood, either 1 or 9
331 * @return True, if so
332 */
333 static bool allValueSame(const Frame& mask, const unsigned int x, const unsigned int y, const uint8_t value, const unsigned int neighborhood);
334};
335
336}
337
338}
339
340}
341
342}
343
344#endif // META_OCEAN_TEST_TESTCV_TESTSYNTHESIS_TEST_INITIALIZER_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:1879
This class implements a generator for random numbers.
Definition RandomGenerator.h:42
Helper function allowing to keep properties of a pixel to be inpainted.
Definition TestInitializerI1.h:43
VectorI2 determineImageOrientation(const Frame &mask, const Frame &sobel) const
Determines the image orientation of this pixel.
InpaintingPixel(const CV::PixelPosition &pixelPosition, const Frame &mask, const Frame &sobel)
Creates a new pixel.
bool operator<(const InpaintingPixel &inpaintingPixel) const
Returns whether this pixel has a lower priority of a second pixel.
VectorI2 determineBorderDirection(const Frame &mask) const
Determines the border direction of this pixel.
const VectorI2 & borderDirection() const
Returns the border direction of this pixel.
This class implements a test for initializers with one frame.
Definition TestInitializerI1.h:36
static bool testCoarserMappingAdaptionAreaConstrained(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the area constrained coarser mapping adaption initializer.
static bool testCoarserMappingAdaptionSpatialCostMask(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the spatial cost mask coarser mapping adaption initializer.
static bool testShrinkingErosion(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the deterministic erosion shrinking initializer.
static bool testCoarserMappingAdaptionAreaConstrained(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the area constrained coarser mapping adaption initializer.
static bool testCoarserMappingAdaptionSpatialCostMask(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the spatial cost mask coarser mapping adaption initializer.
static bool testCoarserMappingAdaption(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the coarser mapping adaption initializer.
static bool testAppearanceMappingAreaConstrained(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the area constrained appearance mapping initializer.
static bool testAppearanceMappingAreaConstrained(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the area constrained appearance mapping initializer.
static bool testAppearanceMapping(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the appearance mapping initializer.
static bool testRandomMappingAreaConstrained(const double testDuration, Worker &worker)
Tests the area constrained random mapping initializer.
static bool testShrinkingErosion(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the deterministic erosion shrinking initializer.
static bool testShrinkingPatchMatching(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the patch matching shrinking initializer.
static bool testAppearanceMapping(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the appearance mapping initializer.
static bool allValueSame(const Frame &mask, const unsigned int x, const unsigned int y, const uint8_t value, const unsigned int neighborhood)
Returns whether all mask pixels in a neighborhood have a specific value.
static bool testRandomMapping(const double testDuration, Worker &worker)
Tests the random mapping initializer.
std::vector< InpaintingPixel > InpaintingPixels
Definition of a vector holding inpainting pixels.
Definition TestInitializerI1.h:99
static bool shrinkPatchMatchingIteration(Frame &frame, Frame &mask, CV::Synthesis::MappingI1 &mapping, const bool useHeuristic, const unsigned int maximalRadius, RandomGenerator &randomGenerator, const bool useMaskForSSD, Worker &worker)
Invokes one shrinking iteration.
static unsigned int determineSSD(const Frame &frame, const Frame &mask, const unsigned int patchSize, const CV::PixelPosition &inpaintingPosition, const CV::PixelPosition &sourcePosition, const bool useMaskForSSD)
Determines the SSD between two image patches.
static bool testCoarserMappingAdaption(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the coarser mapping adaption initializer.
static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker, const TestSelector &selector)
Invokes all test functions.
static bool testShrinkingErosionRandomized(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the randomized erosion shrinking initializer.
static bool testShrinkingPatchMatching(const double testDuration, Worker &worker)
Tests the patch matching shrinking initializer.
static bool testShrinkingErosionRandomized(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the randomized erosion shrinking initializer.
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
The namespace covering the entire Ocean framework.
Definition Accessor.h:15