Ocean
TestFrameMean.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 OCEAN_TEST_TESTCV_TEST_FRAME_MEAN_H
9 #define OCEAN_TEST_TESTCV_TEST_FRAME_MEAN_H
10 
12 
13 #include "ocean/base/Worker.h"
14 
15 namespace Ocean
16 {
17 
18 namespace Test
19 {
20 
21 namespace TestCV
22 {
23 
24 /**
25  * This class implements tests for the FrameMean class.
26  * @ingroup testcv
27  */
28 class OCEAN_TEST_CV_EXPORT TestFrameMean
29 {
30  public:
31 
32  /**
33  * Starts all tests of the FrameMean class.
34  * @param testDuration Number of seconds for each test, with range (0, infinity)
35  * @param worker The worker object to distribute the computational load
36  * @return True, if succeeded
37  */
38  static bool test(const double testDuration, Worker& worker);
39 
40  /**
41  * Tests adding individual pixel values of a given source frame to a target frame if the corresponding mask pixels are valid.
42  * @param performanceWidth The image width that should be used to measure performance, range: [1, infinity)
43  * @param performanceHeight The image height that should be used to measure performance, range: [1, infinity)
44  * @param numberChannels The number of channels that the test images will have, range: [1, 4]
45  * @param testDuration The number of seconds for each test, with range (0, infinity)
46  * @param worker The worker object to distribute the computational load
47  */
48  static bool testAddToFrameIndividually(const unsigned int performanceWidth, const unsigned int performanceHeight, const unsigned numberChannels, const double testDuration, Worker& worker);
49 
50  /**
51  * Tests the function determining the mean value for individual pixel formats.
52  * @param testDuration Number of seconds for each test, with range (0, infinity)
53  * @param worker The worker object to distribute the computational load
54  * @return True, if succeeded
55  */
56  static bool testMeanValue(const double testDuration, Worker& worker);
57 
58  /**
59  * Tests the function determining the mean value.
60  * @param width The width of the test frame in pixel, with range [1, infinity)
61  * @param height The height of the test frame in pixel, with range [1, infinity)
62  * @param channels The number of channels of the test frame, with range, 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 computational load
65  * @return True, if succeeded
66  * @tparam T The data type of each pixel channel
67  * @tparam tChannels The number of frame channels
68  * @tparam TIntermediate The explicit data type of the internal sum values
69  */
70  template <typename T, typename TMean, typename TIntermediate>
71  static bool testMeanValue(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
72 
73  protected:
74 
75  /**
76  * Validates adding individual pixel values of a given source frame to a target frame if the corresponding mask pixels are valid.
77  * The validation assumes that `target` and `denominators` had been set to all zeros before the computation of the test results.
78  * @param source The source frame that is used for the validation, must be valid and not have more than 4 channels and 8-bit unsigned int data type
79  * @param mask The mask frame that is used for the validation, must be valid and not have 1 channel and 8-bit unsigned int data type
80  * @param testTarget The target frame that is validated, must be valid and not have more than 4 channels and 32-bit unsigned int data type
81  * @param testDenominators The denominator frame that is validated, must be valid and not have 1 channel and 32-bit unsigned int data type
82  * @param nonMaskValue The value indicating invalid mask pixels, i.e. pixels that should not be processed by this function, all other values will be interpreted as valid, range: [0, 255]
83  * @return True if the validation was successful, otherwise false
84  */
85  static bool validateAddToFrameIndividually(const Frame& source, const Frame& mask, const Frame& testTarget, const Frame& testDenominators, const uint8_t nonMaskValue);
86 
87  /**
88  * Validates the calculation of the mean value.
89  * @param frame The frame providing the data for which the mean must be verified, must be valid
90  * @param width The width of the frame in pixel, with range [1, infinity)
91  * @param height The height of the frame in pixel, with range [1, infinity)
92  * @param channels The number of frame channels, width range [1, infinity)
93  * @param testMeanValues The already determined mean values to be validated, one for each channel, must be valid
94  * @param framePaddingElements The number of padding elements at the end of each frame row, in elements, with range [0, infinity)
95  * @return True, if succeeded
96  * @tparam T The data type of each pixel channel
97  * @tparam TMean The data type of the mean values
98  * @tparam TIntermediate The explicit data type of the internal sum values
99  */
100  template <typename T, typename TMean, typename TIntermediate>
101  static bool validateMeanValue(const T* frame, const unsigned int width, const unsigned int height, const unsigned int channels, const TMean* testMeanValues, const unsigned int framePaddingElements);
102 
103  /**
104  * Determines the mean values based on the sum of all values and the number of values.
105  * Thus, this function mainly returns sum / size, while handling integer and floats slightly different.
106  * @param sum The sum of all values
107  * @param size The number of values
108  * @return The mean value
109  * @tparam T Data type of the sum and mean value
110  */
111  template <typename T>
112  static inline T meanValue(const T& sum, const size_t size);
113 };
114 
115 template <typename T>
116 inline T TestFrameMean::meanValue(const T& sum, const size_t size)
117 {
118  return (sum + T(size) / T(2)) / T(size);
119 }
120 
121 template <>
122 inline float TestFrameMean::meanValue(const float& sum, const size_t size)
123 {
124  return sum / float(size);
125 }
126 
127 template <>
128 inline double TestFrameMean::meanValue(const double& sum, const size_t size)
129 {
130  return sum / double(size);
131 }
132 
133 }
134 
135 }
136 
137 }
138 
139 #endif // OCEAN_TEST_TESTCV_TEST_FRAME_MEAN_H
This class implements Ocean's image class.
Definition: Frame.h:1792
This class implements tests for the FrameMean class.
Definition: TestFrameMean.h:29
static bool validateMeanValue(const T *frame, const unsigned int width, const unsigned int height, const unsigned int channels, const TMean *testMeanValues, const unsigned int framePaddingElements)
Validates the calculation of the mean value.
static bool test(const double testDuration, Worker &worker)
Starts all tests of the FrameMean class.
static bool testAddToFrameIndividually(const unsigned int performanceWidth, const unsigned int performanceHeight, const unsigned numberChannels, const double testDuration, Worker &worker)
Tests adding individual pixel values of a given source frame to a target frame if the corresponding m...
static bool testMeanValue(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the function determining the mean value.
static bool validateAddToFrameIndividually(const Frame &source, const Frame &mask, const Frame &testTarget, const Frame &testDenominators, const uint8_t nonMaskValue)
Validates adding individual pixel values of a given source frame to a target frame if the correspondi...
static bool testMeanValue(const double testDuration, Worker &worker)
Tests the function determining the mean value for individual pixel formats.
static T meanValue(const T &sum, const size_t size)
Determines the mean values based on the sum of all values and the number of values.
Definition: TestFrameMean.h:116
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