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