Ocean
TestFrameColorAdjustment.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_TESTADVANCED_TEST_FRAME_COLOR_ADJUSTMENT_H
9 #define META_OCEAN_TEST_TESTCV_TESTADVANCED_TEST_FRAME_COLOR_ADJUSTMENT_H
10 
12 
15 #include "ocean/base/Worker.h"
16 
17 #include "ocean/math/Lookup2.h"
18 
19 namespace Ocean
20 {
21 
22 namespace Test
23 {
24 
25 namespace TestCV
26 {
27 
28 namespace TestAdvanced
29 {
30 
31 /**
32  * This class implements a frame color adjustment test.
33  * @ingroup testcvadvanced
34  */
35 class OCEAN_TEST_CV_ADVANCED_EXPORT TestFrameColorAdjustment
36 {
37  public:
38 
39  /**
40  * This class extends the static buffer class by mathematical operators.
41  */
42  template <size_t tCapacity>
43  class Object : public StaticBuffer<Scalar, tCapacity>
44  {
45  public:
46 
47  /**
48  * Element-wise add operator.
49  * @param object The object to be added
50  * @return Sum result
51  */
52  inline Object operator+(const Object& object) const;
53 
54  /**
55  * Element-wise subtract operator.
56  * @param object The object to be subtracted
57  * @return Subtraction result
58  */
59  inline Object operator-(const Object& object) const;
60 
61  /**
62  * Scalar multiplication operator.
63  * @param factor Multiplication factor
64  * @return Multiplication result
65  */
66  inline Object operator*(const Scalar factor) const;
67  };
68 
69  /**
70  * Definition of a lookup table holding objects.
71  */
72  template <unsigned int tChannels>
74 
75  public:
76 
77  /**
78  * Tests all frame color adjustment functions.
79  * @param width The width of the test frame in pixel, with range [1, infinity)
80  * @param height The height of the test frame in pixel, with range [1, infinity)
81  * @param testDuration The number of seconds for each test, with range (0, infinity)
82  * @param worker The worker object to distribute the computation
83  * @return True, if succeeded
84  */
85  static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
86 
87  /**
88  * Tests the default adjustment function without mask pixels.
89  * @param width The width of the test frame in pixel, with range [1, infinity)
90  * @param height The height of the test frame in pixel, with range [1, infinity)
91  * @param testDuration The number of seconds for each test, with range (0, infinity)
92  * @param worker The worker object to distribute the computation
93  * @return True, if succeeded
94  * @tparam tChannels The number of data channels for the frame, with range [1, infinity)
95  */
96  template <unsigned int tChannels>
97  static bool testAdjustmentNoMask(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
98 
99  /**
100  * Tests the adjustment function with mask pixels.
101  * @param width The width of the test frame in pixel, with range [1, infinity)
102  * @param height The height of the test frame in pixel, with range [1, infinity)
103  * @param testDuration The number of seconds for each test, with range (0, infinity)
104  * @param worker The worker object to distribute the computation
105  * @return True, if succeeded
106  * @tparam tChannels The number of data channels for the frame, with range [1, infinity)
107  */
108  template <unsigned int tChannels>
109  static bool testAdjustmentWithMask(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
110 
111  protected:
112 
113  /**
114  * Creates a modification table with given size and maximal offset value.
115  * @param sizeX The horizontal size of the table, with range [1, infinity)
116  * @param sizeY The vertical size of the table, with range [1, infinity)
117  * @param binsX The number of horizontal bins, with range [1, sizeX]
118  * @param binsY The number of vertical bins, with range [1, sizeY]
119  * @param minimalOffset The minimal offset for each channel, with range [-255, 255)
120  * @param maximalOffset The maximal offset for each channel, with range (minimalOffset, 255]
121  * @param randomGenerator The random generator to be used
122  * @return The resulting lookup table
123  * @tparam tChannels The number of data channels, with range [1, infinity)
124  */
125  template <unsigned int tChannels>
126  static ObjectLookupCenter2<tChannels> modificationTable(const unsigned int sizeX, const unsigned int sizeY, const unsigned int binsX, const unsigned int binsY, const Scalar minimalOffset, const Scalar maximalOffset, RandomGenerator& randomGenerator);
127 
128  /**
129  * Modifies a given frame by adding component-wise values from a given lookup table.
130  * @param source The source frame providing the image content, must be valid
131  * @param sourcePaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
132  * @param lookupTable The lookup table providing the offset values which will be added
133  * @param target The target frame receiving the modified source frame, must be valid
134  * @param targetPaddingElements The number of padding elements at the end of each source row, in elements, with range [0, infinity)
135  * @tparam tChannels The number of data channels for the frame, with range [1, infinity)
136  */
137  template <unsigned int tChannels>
138  static void modifyFrame8BitPerChannel(const uint8_t* source, const unsigned int sourcePaddingElements, const ObjectLookupCenter2<tChannels>& lookupTable, uint8_t* target, const unsigned int targetPaddingElements);
139 
140  /**
141  * Returns the average color difference between two frames.
142  * @param frame0 The first frame, must be valid
143  * @param mask0 Optional mask defining valid and invalid pixels in the first frame
144  * @param frame1 The second frame, with same frame type as the first frame, must be valid
145  * @param mask1 Optional mask defining valid and invalid pixels in the second frame
146  * @param maskValue Mask value defining valid pixels, must be valid
147  * @return The average pixel difference, with range [0, infinity)
148  * @tparam tChannels The number of data channels for the frame, with range [1, infinity)
149  */
150  template <unsigned int tChannels>
151  static Scalar averageDifference(const Frame& frame0, const Frame& mask0, const Frame& frame1, const Frame& mask1, const uint8_t maskValue = 0xFFu);
152 
153  /**
154  * Sets random mask values and adds pepper at the same positions in a corresponding frame.
155  * @param frame The frame to which the pepper will be added
156  * @param mask The mask receiving the mask pixels
157  * @param number The number of mask pixels which will be set
158  * @param randomGenerator The random generator to be used
159  * @param value The value which will be set to the mask
160  * @tparam tChannels The number of data channels for the frame, with range [1, infinity)
161  */
162  template <unsigned int tChannels>
163  static void randomMask(Frame& frame, Frame& mask, const unsigned int number, RandomGenerator& randomGenerator, const uint8_t value = 0x00u);
164 };
165 
166 template <size_t tCapacity>
168 {
170 
171  for (size_t n = 0; n < tCapacity; ++n)
172  {
173  result[n] = (*this)[n] + object[n];
174  }
175 
176  return result;
177 }
178 
179 template <size_t tCapacity>
181 {
183 
184  for (size_t n = 0; n < tCapacity; ++n)
185  {
186  result[n] = (*this)[n] - object[n];
187  }
188 
189  return result;
190 }
191 
192 template <size_t tCapacity>
194 {
196 
197  for (size_t n = 0; n < tCapacity; ++n)
198  {
199  result[n] = (*this)[n] * factor;
200  }
201 
202  return result;
203 }
204 
205 }
206 
207 }
208 
209 }
210 
211 }
212 
213 #endif // META_OCEAN_TEST_TESTCV_TESTADVANCED_TEST_FRAME_COLOR_ADJUSTMENT_H
This class implements Ocean's image class.
Definition: Frame.h:1760
This class implements a 2D lookup object with values at the bins' center positions defining the indiv...
Definition: Lookup2.h:198
This class implements a generator for random numbers.
Definition: RandomGenerator.h:42
This class implements a static buffer that has a fixed capacity.
Definition: StaticBuffer.h:24
This class extends the static buffer class by mathematical operators.
Definition: TestFrameColorAdjustment.h:44
Object operator-(const Object &object) const
Element-wise subtract operator.
Definition: TestFrameColorAdjustment.h:180
Object operator*(const Scalar factor) const
Scalar multiplication operator.
Definition: TestFrameColorAdjustment.h:193
Object operator+(const Object &object) const
Element-wise add operator.
Definition: TestFrameColorAdjustment.h:167
This class implements a frame color adjustment test.
Definition: TestFrameColorAdjustment.h:36
static Scalar averageDifference(const Frame &frame0, const Frame &mask0, const Frame &frame1, const Frame &mask1, const uint8_t maskValue=0xFFu)
Returns the average color difference between two frames.
static ObjectLookupCenter2< tChannels > modificationTable(const unsigned int sizeX, const unsigned int sizeY, const unsigned int binsX, const unsigned int binsY, const Scalar minimalOffset, const Scalar maximalOffset, RandomGenerator &randomGenerator)
Creates a modification table with given size and maximal offset value.
static void randomMask(Frame &frame, Frame &mask, const unsigned int number, RandomGenerator &randomGenerator, const uint8_t value=0x00u)
Sets random mask values and adds pepper at the same positions in a corresponding frame.
static void modifyFrame8BitPerChannel(const uint8_t *source, const unsigned int sourcePaddingElements, const ObjectLookupCenter2< tChannels > &lookupTable, uint8_t *target, const unsigned int targetPaddingElements)
Modifies a given frame by adding component-wise values from a given lookup table.
static bool testAdjustmentNoMask(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the default adjustment function without mask pixels.
static bool testAdjustmentWithMask(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the adjustment function with mask pixels.
static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests all frame color adjustment functions.
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
AutomaticDifferentiationT< T1, TNumeric1 > operator-(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition: AutomaticDifferentiation.h:484
AutomaticDifferentiationT< T1, TNumeric1 > operator*(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition: AutomaticDifferentiation.h:524
AutomaticDifferentiationT< T1, TNumeric1 > operator+(const T2 &left, const AutomaticDifferentiationT< T1, TNumeric1 > &right)
Definition: AutomaticDifferentiation.h:418