Ocean
TestOptimizerF1.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_F_1_H
9 #define META_OCEAN_TEST_TESTCV_TESTSYNTHESIS_TEST_OPTIMIZER_F_1_H
10 
12 
13 #include "ocean/base/Frame.h"
15 
17 
18 namespace Ocean
19 {
20 
21 namespace Test
22 {
23 
24 namespace TestCV
25 {
26 
27 namespace TestSynthesis
28 {
29 
30 /**
31  * This class implements a test for optimizers with one frame.
32  * @ingroup testcvsynthesis
33  */
34 class OCEAN_TEST_CV_SYNTHESIS_EXPORT TestOptimizerF1
35 {
36  public:
37 
38  /**
39  * Invokes all test functions.
40  * @param width The width of the source frame in pixel, with range [1, infinity)
41  * @param height The height of the source frame in pixel, with range [1, infinity)
42  * @param testDuration Number of seconds for each test, with range (0, infinity)
43  * @param worker The worker object to distribute the CPU load
44  * @return True, if succeeded
45  */
46  static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
47 
48  /**
49  * Tests the 4-neighborhood high performance optimizer.
50  * @param width The width of the source frame in pixel, with range [1, infinity)
51  * @param height The height of the source frame in pixel, with range [1, infinity)
52  * @param testDuration Number of seconds for each test, with range (0, infinity)
53  * @param worker The worker object to distribute the CPU load
54  * @return True, if succeeded
55  */
56  static bool testHighPerformance4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
57 
58  /**
59  * Tests the 4-neighborhood high performance optimizer.
60  * @param width The width of the source frame in pixel, with range [1, infinity)
61  * @param height The height of the source frame in pixel, with range [1, infinity)
62  * @param channels The number of frame channels which will be used during the test, with range [1, infinity)
63  * @param testDuration Number of seconds for each test, with range (0, infinity)
64  * @param worker The worker object to distribute the CPU load
65  * @return True, if succeeded
66  */
67  static bool testHighPerformance4Neighborhood(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
68 
69  /**
70  * Tests the 4-neighborhood optimizer with a reference frame.
71  * @param width The width of the source frame in pixel, with range [1, infinity)
72  * @param height The height of the source frame in pixel, with range [1, infinity)
73  * @param testDuration Number of seconds for each test, with range (0, infinity)
74  * @param worker The worker object to distribute the CPU load
75  * @return True, if succeeded
76  */
77  static bool testReferenceFrame4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
78 
79  /**
80  * Tests the 4-neighborhood optimizer with a reference frame.
81  * @param width The width of the source frame in pixel, with range [1, infinity)
82  * @param height The height of the source frame in pixel, with range [1, infinity)
83  * @param channels The number of frame channels which will be used during the test, with range [1, infinity)
84  * @param testDuration Number of seconds for each test, with range (0, infinity)
85  * @param worker The worker object to distribute the CPU load
86  * @return True, if succeeded
87  */
88  static bool testReferenceFrame4Neighborhood(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
89 
90  protected:
91 
92  /**
93  * Invokes a high performance optimization with a 4-neighborhood.
94  * @param frame The frame to be used, must be valid
95  * @param mask The mask to be used, must be valid
96  * @param mapping The mapping to be used, must be valid
97  * @param randomGenerator The random generator to be used
98  * @param applyInitialMapping True, to apply the initial mapping; False, to skip the initial mapping
99  * @param radii The number of search radii, with range [1, infinity)
100  * @param iterations The number of optimization iterations, with range [1, infinity)
101  * @param weightFactor The weight factor to be applied, with range [1, infinity)
102  * @param maxSpatialCost The maximal spatial cost to be used, with range [0, infinity)
103  * @return True, if succeeded
104  * @tparam tBorderFactor The border factor to be used, with range [1, infinity)
105  */
106  template <unsigned int tBorderFactor>
107  static bool optimize4Neighborhood(Frame& frame, const Frame& mask, CV::Synthesis::MappingF1& mapping, RandomGenerator& randomGenerator, const bool applyInitialMapping, const unsigned int radii, const unsigned int iterations, const unsigned int weightFactor, const unsigned int maxSpatialCost);
108 
109  /**
110  * Invokes an optimization with a 4-neighborhood and a reference frame.
111  * @param frame The frame to be used, must be valid
112  * @param mask The mask to be used, must be valid
113  * @param reference The reference frame to be used, must be valid
114  * @param mapping The mapping to be used, must be valid
115  * @param randomGenerator The random generator to be used
116  * @param applyInitialMapping True, to apply the initial mapping; False, to skip the initial mapping
117  * @param radii The number of search radii, with range [1, infinity)
118  * @param iterations The number of optimization iterations, with range [1, infinity)
119  * @param weightFactor The weight factor to be applied, with range [1, infinity)
120  * @param maxSpatialCost The maximal spatial cost to be used, with range [0, infinity)
121  * @return True, if succeeded
122  * @tparam tBorderFactor The border factor to be used, with range [1, infinity)
123  */
124  template <unsigned int tBorderFactor>
125  static bool optimizeReference4Neighborhood(Frame& frame, const Frame& mask, const Frame& reference, CV::Synthesis::MappingF1& mapping, RandomGenerator& randomGenerator, const bool applyInitialMapping, const unsigned int radii, const unsigned int iterations, const unsigned int weightFactor, const unsigned int maxSpatialCost);
126 
127  /**
128  * Determines the cost for a given location.
129  * @param frame The frame to be used, must be valid
130  * @param mask The mask to be used, must be valid
131  * @param mapping The mapping to be used, must be valid
132  * @param targetPosition The target position for which the cost will be determined
133  * @param sourcePosition The source position for which the cost will be determined
134  * @param weightFactor The weight factor to be applied
135  * @param maxSpatialCost The maximal spatial cost to be used
136  * @return The resulting cost composed of spatial and appearance cost
137  * @tparam tBorderFactor The border factor to be used
138  */
139  template <unsigned int tBorderFactor>
140  static Scalar determineCost(const Frame& frame, const Frame& mask, const CV::Synthesis::MappingF1& mapping, const CV::PixelPosition& targetPosition, const Vector2& sourcePosition, const unsigned int weightFactor, const unsigned int maxSpatialCost);
141 
142  /**
143  * Determines the cost for a given location.
144  * @param frame The frame to be used, must be valid
145  * @param mask The mask to be used, must be valid
146  * @param reference The reference frame to be used, must be valid
147  * @param mapping The mapping to be used, must be valid
148  * @param targetPosition The target position for which the cost will be determined
149  * @param sourcePosition The source position for which the cost will be determined
150  * @param weightFactor The weight factor to be applied
151  * @param maxSpatialCost The maximal spatial cost to be used
152  * @return The resulting cost composed of spatial and appearance cost
153  * @tparam tBorderFactor The border factor to be used
154  */
155  template <unsigned int tBorderFactor>
156  static Scalar determineCost(const Frame& frame, const Frame& mask, const Frame& reference, const CV::Synthesis::MappingF1& mapping, const CV::PixelPosition& targetPosition, const Vector2& sourcePosition, const unsigned int weightFactor, const unsigned int maxSpatialCost);
157 };
158 
159 }
160 
161 }
162 
163 }
164 
165 }
166 
167 #endif // META_OCEAN_TEST_TESTCV_TESTSYNTHESIS_TEST_OPTIMIZER_F_1_H
Cost function:
Definition: MappingF1.h:52
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: TestOptimizerF1.h:35
static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Invokes all test functions.
static bool optimize4Neighborhood(Frame &frame, const Frame &mask, CV::Synthesis::MappingF1 &mapping, RandomGenerator &randomGenerator, const bool applyInitialMapping, const unsigned int radii, const unsigned int iterations, const unsigned int weightFactor, const unsigned int maxSpatialCost)
Invokes a high performance optimization with a 4-neighborhood.
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 Scalar determineCost(const Frame &frame, const Frame &mask, const Frame &reference, const CV::Synthesis::MappingF1 &mapping, const CV::PixelPosition &targetPosition, const Vector2 &sourcePosition, const unsigned int weightFactor, const unsigned int maxSpatialCost)
Determines the cost for a given location.
static bool testReferenceFrame4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the 4-neighborhood optimizer with a reference frame.
static bool optimizeReference4Neighborhood(Frame &frame, const Frame &mask, const Frame &reference, CV::Synthesis::MappingF1 &mapping, RandomGenerator &randomGenerator, const bool applyInitialMapping, const unsigned int radii, const unsigned int iterations, const unsigned int weightFactor, const unsigned int maxSpatialCost)
Invokes an optimization with a 4-neighborhood and a reference frame.
static bool testReferenceFrame4Neighborhood(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the 4-neighborhood optimizer with a reference frame.
static Scalar determineCost(const Frame &frame, const Frame &mask, const CV::Synthesis::MappingF1 &mapping, const CV::PixelPosition &targetPosition, const Vector2 &sourcePosition, const unsigned int weightFactor, const unsigned int maxSpatialCost)
Determines the cost for a given location.
static bool testHighPerformance4Neighborhood(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the 4-neighborhood high performance optimizer.
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
float Scalar
Definition of a scalar type.
Definition: Math.h:128
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15