Ocean
TestOptimizerI1.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_OPTIMIZER_I_1_H
9 #define META_OCEAN_TEST_TESTCV_TESTSYNTHESIS_TEST_OPTIMIZER_I_1_H
10 
12 
13 #include "ocean/base/Frame.h"
15 
18 
19 namespace Ocean
20 {
21 
22 namespace Test
23 {
24 
25 namespace TestCV
26 {
27 
28 namespace TestSynthesis
29 {
30 
31 /**
32  * This class implements a test for optimizers with one frame.
33  * @ingroup testcvsynthesis
34  */
35 class OCEAN_TEST_CV_SYNTHESIS_EXPORT TestOptimizerI1
36 {
37  public:
38 
39  /**
40  * Invokes all test functions.
41  * @param width The width of the source frame in pixel, with range [1, infinity)
42  * @param height The height of the source frame in pixel, with range [1, infinity)
43  * @param testDuration Number of seconds for each test, with range (0, infinity)
44  * @param worker The worker object to distribute the CPU load
45  * @return True, if succeeded
46  */
47  static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
48 
49  /**
50  * Tests the 4-neighborhood optimizer with constrained area.
51  * @param width The width of the source frame in pixel, with range [1, infinity)
52  * @param height The height of the source frame in pixel, with range [1, infinity)
53  * @param testDuration Number of seconds for each test, with range (0, infinity)
54  * @param worker The worker object to distribute the CPU load
55  * @return True, if succeeded
56  */
57  static bool testAreaConstrained4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
58 
59  /**
60  * Tests the 4-neighborhood optimizer with constrained area.
61  * @param width The width of the source frame in pixel, with range [1, infinity)
62  * @param height The height of the source frame in pixel, with range [1, infinity)
63  * @param channels The number of frame channels which will be used during the test, with range [1, infinity)
64  * @param testDuration Number of seconds for each test, with range (0, infinity)
65  * @param worker The worker object to distribute the CPU load
66  * @return True, if succeeded
67  */
68  static bool testAreaConstrained4Neighborhood(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
69 
70  /**
71  * Tests the 4-neighborhood high performance optimizer.
72  * @param width The width of the source frame in pixel, with range [1, infinity)
73  * @param height The height of the source frame in pixel, with range [1, infinity)
74  * @param testDuration Number of seconds for each test, with range (0, infinity)
75  * @param worker The worker object to distribute the CPU load
76  * @return True, if succeeded
77  */
78  static bool testHighPerformance4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
79 
80  /**
81  * Tests the 4-neighborhood high performance optimizer.
82  * @param width The width of the source frame in pixel, with range [1, infinity)
83  * @param height The height of the source frame in pixel, with range [1, infinity)
84  * @param channels The number of frame channels which will be used during the test, with range [1, infinity)
85  * @param testDuration Number of seconds for each test, with range (0, infinity)
86  * @param worker The worker object to distribute the CPU load
87  * @return True, if succeeded
88  */
89  static bool testHighPerformance4Neighborhood(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
90 
91  /**
92  * Tests the 4-neighborhood high performance optimizer skipping if spatial cost is already optimal.
93  * @param width The width of the source frame in pixel, with range [1, infinity)
94  * @param height The height of the source frame in pixel, with range [1, infinity)
95  * @param testDuration Number of seconds for each test, with range (0, infinity)
96  * @param worker The worker object to distribute the CPU load
97  * @return True, if succeeded
98  */
99  static bool testHighPerformance4NeighborhoodSkipping(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
100 
101  /**
102  * Tests the 4-neighborhood high performance optimizer skipping if spatial cost is already optimal.
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 channels The number of frame channels which will be used during the test, with range [1, infinity)
106  * @param testDuration Number of seconds for each test, with range (0, infinity)
107  * @param worker The worker object to distribute the CPU load
108  * @return True, if succeeded
109  */
110  static bool testHighPerformance4NeighborhoodSkipping(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
111 
112  /**
113  * Tests the 4-neighborhood high performance optimizer with skipping mask.
114  * @param width The width of the source frame in pixel, with range [1, infinity)
115  * @param height The height of the source frame in pixel, with range [1, infinity)
116  * @param testDuration Number of seconds for each test, with range (0, infinity)
117  * @param worker The worker object to distribute the CPU load
118  * @return True, if succeeded
119  */
120  static bool testHighPerformance4NeighborhoodSkippingByCostMask(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
121 
122  /**
123  * Tests the 4-neighborhood high performance optimizer with skipping mask.
124  * @param width The width of the source frame in pixel, with range [1, infinity)
125  * @param height The height of the source frame in pixel, with range [1, infinity)
126  * @param channels The number of frame channels which will be used during the test, with range [1, infinity)
127  * @param testDuration Number of seconds for each test, with range (0, infinity)
128  * @param worker The worker object to distribute the CPU load
129  * @return True, if succeeded
130  */
131  static bool testHighPerformance4NeighborhoodSkippingByCostMask(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
132 
133  /**
134  * Tests the 4-neighborhood optimizer with structural constrains.
135  * @param width The width of the source frame in pixel, with range [1, infinity)
136  * @param height The height of the source frame in pixel, with range [1, infinity)
137  * @param testDuration Number of seconds for each test, with range (0, infinity)
138  * @param worker The worker object to distribute the CPU load
139  * @return True, if succeeded
140  */
141  static bool testStructuralConstrained4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
142 
143  /**
144  * Tests the 4-neighborhood optimizer with structural constrains.
145  * @param width The width of the source frame in pixel, with range [1, infinity)
146  * @param height The height of the source frame in pixel, with range [1, infinity)
147  * @param channels The number of frame channels which will be used during the test, with range [1, infinity)
148  * @param testDuration Number of seconds for each test, with range (0, infinity)
149  * @param worker The worker object to distribute the CPU load
150  * @return True, if succeeded
151  */
152  static bool testStructuralConstrained4Neighborhood(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
153 
154  protected:
155 
156  /**
157  * Invokes a high performance optimization with a 4-neighborhood.
158  * @param frame The frame to be used, must be valid
159  * @param mask The mask to be used, must be valid
160  * @param filterMask Optional filter mask to constrained the optimization; invalid to avoid and additional filter
161  * @param skippingMask Optional mask defining pixels to be skipped; invalid to avoid this additional option
162  * @param constraints Optional constraints to be applied during optimization, nullptr to avoid using constraints
163  * @param mapping The mapping to be used, must be valid
164  * @param randomGenerator The random generator to be used
165  * @param applyInitialMapping True, to apply the initial mapping; False, to skip the initial mapping
166  * @param radii The number of search radii, with range [1, infinity)
167  * @param iterations The number of optimization iterations, with range [1, infinity)
168  * @param weightFactor The weight factor to be applied, with range [1, infinity)
169  * @param maxSpatialCost The maximal spatial cost to be used, with range [0, infinity)
170  * @param spatialSkipping True, to apply spatial skipping
171  * @return True, if succeeded
172  * @tparam tBorderFactor The border factor to be used, with range [1, infinity)
173  */
174  template <unsigned int tBorderFactor>
175  static bool optimize4Neighborhood(Frame& frame, const Frame& mask, const Frame& filterMask, const Frame& skippingMask, const CV::Synthesis::Constraints* constraints, CV::Synthesis::MappingI1& mapping, RandomGenerator& randomGenerator, const bool applyInitialMapping, const unsigned int radii, const unsigned int iterations, const unsigned int weightFactor, const unsigned int maxSpatialCost, const bool spatialSkipping);
176 
177  /**
178  * Determines the cost for a given location.
179  * @param frame The frame to be used, must be valid
180  * @param mask The mask to be used, must be valid
181  * @param mapping The mapping to be used, must be valid
182  * @param targetPosition The target position for which the cost will be determined
183  * @param sourcePosition The source position for which the cost will be determined
184  * @param weightFactor The weight factor to be applied
185  * @param maxSpatialCost The maximal spatial cost to be used
186  * @return The resulting cost composed of spatial and appearance cost
187  * @tparam tBorderFactor The border factor to be used
188  */
189  template <unsigned int tBorderFactor>
190  static uint64_t determineCost(const Frame& frame, const Frame& mask, const CV::Synthesis::MappingI1& mapping, const CV::PixelPosition& targetPosition, const CV::PixelPosition& sourcePosition, const unsigned int weightFactor, const unsigned int maxSpatialCost);
191 };
192 
193 }
194 
195 }
196 
197 }
198 
199 }
200 
201 #endif // META_OCEAN_TEST_TESTCV_TESTSYNTHESIS_TEST_OPTIMIZER_I_1_H
This class implements a container holding constraints.
Definition: Constraint.h:304
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:1792
This class implements a generator for random numbers.
Definition: RandomGenerator.h:42
This class implements a test for optimizers with one frame.
Definition: TestOptimizerI1.h:36
static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Invokes all test functions.
static bool testStructuralConstrained4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the 4-neighborhood optimizer with structural constrains.
static bool testHighPerformance4Neighborhood(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the 4-neighborhood high performance optimizer.
static bool testHighPerformance4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the 4-neighborhood high performance optimizer.
static bool testHighPerformance4NeighborhoodSkipping(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the 4-neighborhood high performance optimizer skipping if spatial cost is already optimal.
static bool testHighPerformance4NeighborhoodSkippingByCostMask(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the 4-neighborhood high performance optimizer with skipping mask.
static bool testStructuralConstrained4Neighborhood(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the 4-neighborhood optimizer with structural constrains.
static bool optimize4Neighborhood(Frame &frame, const Frame &mask, const Frame &filterMask, const Frame &skippingMask, const CV::Synthesis::Constraints *constraints, CV::Synthesis::MappingI1 &mapping, RandomGenerator &randomGenerator, const bool applyInitialMapping, const unsigned int radii, const unsigned int iterations, const unsigned int weightFactor, const unsigned int maxSpatialCost, const bool spatialSkipping)
Invokes a high performance optimization with a 4-neighborhood.
static bool testHighPerformance4NeighborhoodSkipping(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the 4-neighborhood high performance optimizer skipping if spatial cost is already optimal.
static bool testAreaConstrained4Neighborhood(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the 4-neighborhood optimizer with constrained area.
static uint64_t determineCost(const Frame &frame, const Frame &mask, const CV::Synthesis::MappingI1 &mapping, const CV::PixelPosition &targetPosition, const CV::PixelPosition &sourcePosition, const unsigned int weightFactor, const unsigned int maxSpatialCost)
Determines the cost for a given location.
static bool testAreaConstrained4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the 4-neighborhood optimizer with constrained area.
static bool testHighPerformance4NeighborhoodSkippingByCostMask(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the 4-neighborhood high performance optimizer with skipping mask.
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