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