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