Ocean
Loading...
Searching...
No Matches
TestHistogram.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_TEST_HISTOGRAM_H
9#define META_OCEAN_TEST_TESTCV_TEST_HISTOGRAM_H
10
12
13#include "ocean/base/Frame.h"
14
15#include "ocean/cv/Histogram.h"
16
18
19namespace Ocean
20{
21
22/// Forward-declaration of class RandomGenerator
23class RandomGenerator;
24
25namespace Test
26{
27
28namespace TestCV
29{
30
31/**
32 * This class implements a pixel bounding box test.
33 * @ingroup testcv
34 */
35class OCEAN_TEST_CV_EXPORT TestHistogram : protected CV::ContrastLimitedAdaptiveHistogram
36{
37 public:
38
39 /**
40 * Tests the histogram function.
41 * @param testDuration Number of seconds for each test, range: (0, infinity)
42 * @param worker A worker instance for parallel execution of the tested function (performance)
43 * @param selector Test selector for filtering sub-tests; default runs all tests
44 * @return True if all tests of this class passed, otherwise false
45 */
46 static bool test(const double testDuration, Worker& worker, const TestSelector& selector = TestSelector());
47
48 /**
49 * Performance and validation test for the computation of histograms
50 * @param testDuration Number of seconds for each test, range: (0, infinity)
51 * @param worker A worker instance for parallel execution of the tested function (performance)
52 * @return True if validation was successful, otherwise false
53 */
54 static bool testDetermineHistogram8BitPerChannel(const double testDuration, Worker& worker);
55
56 /**
57 * Performance and validation test for the computation of histograms on sub-frames/-regions of an image
58 * @param testDuration Number of seconds for each test, range: (0, infinity)
59 * @param worker A worker instance for parallel execution of the tested function (performance)
60 * @return True if validation was successful, otherwise false
61 */
62 static bool testDetermineHistogram8BitPerChannelSubFrame(const double testDuration, Worker& worker);
63
64 /**
65 * Performance and validation test for the computation of the CLAHE lookup tables
66 * @param testDuration Number of seconds for each test, range: (0, infinity)
67 * @param worker A worker instance for parallel execution of the tested function (performance)
68 * @return True if validation was successful, otherwise false
69 */
70 static bool testContrastLimitedAdaptiveHistogramTileLookupTables(const double testDuration, Worker& worker);
71
72 /**
73 * Validation test for the computation of the CLAHE horizontal bilinear interpolation parameters
74 * @param testDuration Number of seconds for each test, range: (0, infinity)
75 * @return True if validation was successful, otherwise false
76 */
77 static bool testContrastLimitedAdaptiveBilinearInterpolationParameters(const double testDuration);
78
79 /**
80 * Test the Contrast-Limited Histogram Equalization (CLAHE)
81 * @param testDuration Number of seconds that this test will run, range: (0, infinity)
82 * @param worker A worker instance for parallel execution of the tested function (performance)
83 * @return True if the test passed, otherwise false
84 */
85 static bool testContrastLimitedHistogramEqualization(const double testDuration, Worker& worker);
86
87 /**
88 * Validation function for the computation of the CLAHE horizontal (or vertical) bilinear interpolation parameters
89 * @param lowBins Left (or top) bins for each pixel in a column (or row) that will be validated, must be initialized, size identical to `imageEdgeLength`
90 * @param lowFactors_fixed7 Left (or top) interpolation factors for each pixel in a column (or row) that will be validated, must be initialized as fixed-point, 7-bit precision numbers, size identical to `imageEdgeLength`
91 * @param imageEdgeLength Image edge length, either width or height, range: [1, infinity)
92 * @param tilesCount Number of horizontal (or vertical) tiles, range: [1, infinity)
93 * @return True if the validation was successful, otherwise false
94 */
95 static bool validateBilinearInterpolationParameters(const Indices32& lowBins, const std::vector<unsigned char>& lowFactors_fixed7, const unsigned int imageEdgeLength, const unsigned int tilesCount);
96
97 /**
98 * Validation function for the computation of the CLAHE tile lookup tables
99 * @param source Pointer to the source image, must be initialized, expected size: `width` x `height`
100 * @param width The width of the source image
101 * @param height The height of the source image
102 * @param validationLookupTables Values that will be validated, must be initialized, expected size: `width` x `height`
103 * @param horizontalTiles Number of horizontal tiles, range: [1, infinity)
104 * @param verticalTiles Number of vertical tiles, range: [1, infinity)
105 * @param clipLimit CLAHE clip limit, range: [1, infinity)
106 * @param maxAbsError Will hold the value of the largest absolute error measured during the validation, otherwise this will be ignored, range: [0, 255]
107 * @param sourcePaddingElements Number of padding elements in the source data, range: [0u, infinity), default: 0
108 * @param maxAbsErrorThresholdMultiple Maximum allowed absolute error value if the both, image width and height, are a multiples of the horizontal and vertical number of tiles tiles, range: [0, infinity), default: 1.0
109 * @param maxAbsErrorThreshold Maximum allowed absolute error value if the image is not a multiple of the number of tiles, range: [0, infinity), default: 25.0
110 * @return Number of tiles for which the validation has failed. Will be zero if all tile validations were successful, range: [0, horizontalTiles * verticalTiles]
111 */
112 static unsigned int validateTileLookupTables(const unsigned char* source, const unsigned int width, const unsigned int height, const std::vector<unsigned char>& validationLookupTables, const unsigned int horizontalTiles, const unsigned int verticalTiles, const Scalar clipLimit, double& maxAbsError, const unsigned int sourcePaddingElements = 0u, const double maxAbsErrorThresholdMultiple = 1.0, const double maxAbsErrorThreshold = 25.0);
113
114 /**
115 * Validation function for CLAHE
116 * @param source Pointer to the data of the source frame that will be processed, must be valid and 8-bit unsigned, 1-channel (`FrameType::FORMAT_Y8`)
117 * @param width The width of the source and target frames, range: [horizontalTiles, infinity)
118 * @param height The height of the source and target frames, range: [verticalTiles, infinity)
119 * @param validationTarget Equalization result that will be validated, must be valid and 8-bit unsigned, 1-channel (`FrameType::FORMAT_Y8`) and have the same size as the source
120 * @param clipLimit Global scaling factor to determine the tile clip limit, `tileClipLimit = clipLimit * N`, where `N = (tileSize / histogramSize)` is the number of pixels per bin if all pixels are distributed evenly over the histogram (average), range: [0, infinity)
121 * @param horizontalTiles Number of tiles the source image will be split horizontally, range: [1, infinity)
122 * @param verticalTiles Number of tiles the source image will be split vertically, range: [1, infinity)
123 * @param sourcePaddingElements Number of padding elements in the source data, range: [0, infinity), default: 0
124 * @param validationTargetPaddingElements Number of padding elements in the target data, range: [0, infinity), default: 0
125 * @param maxError If specified, it will hold the maximum absolute error value that has been found during the validation, otherwise this parameter will be ignored
126 * @param groundtruth If specified, it will contain the groundtruth used in the validation; if specified, it must be initialized to the same size of source (no padding allowed)
127 * @return True if the validation was successful, otherwise false
128 */
129 static bool validateEqualization8BitPerChannel(const unsigned char* const source, const unsigned int width, const unsigned height, const unsigned char* const validationTarget, const Scalar clipLimit = Scalar(40), const unsigned int horizontalTiles = 8u, const unsigned int verticalTiles = 8u, const unsigned int sourcePaddingElements = 0u, const unsigned int validationTargetPaddingElements = 0u, double* maxError = nullptr, unsigned char* groundtruth = nullptr);
130
131 /**
132 * Performance and validation test for the computation of the CLAHE lookup tables
133 * @param width The width of the images that will be tested, if 0u the width will be selected randomly (max. 2000), range: [16 * horizontalTiles, infinity)
134 * @param height The height of the images that will be tested, if 0u the height will be selected randomly (max. 2000), range: [16 * verticalTiles, infinity)
135 * @param clipLimit Clip limit to used for testing, if <= 0 this parameter will be selected randomly (between 1 and 100), range: [1, infinity)
136 * @param horizontalTiles Number of horizontal tiles to be used for testing, if 0 this parameter will be selected randomly (between 2 and 16), range: [2, infinity)
137 * @param verticalTiles Number of vertical tiles to be used for testing, if 0 this parameter will be selected randomly (between 2 and 16), range: [2, infinity)
138 * @param testDuration Number of seconds for each test, range: (0, infinity)
139 * @param worker A worker instance for parallel execution of the tested function (performance)
140 * @return True if validation was successful, otherwise false
141 */
142 static bool testContrastLimitedAdaptiveHistogramTileLookupTables(const unsigned int width, const unsigned int height, const Scalar clipLimit, const unsigned int horizontalTiles, const unsigned int verticalTiles, const double testDuration, Worker& worker);
143
144 /**
145 * Test the Contrast-Limited Histogram Equalization (CLAHE)
146 * @param width The width of the images that will be tested, if 0u the width will be selected randomly (max. 2000), range: [16 * horizontalTiles, infinity)
147 * @param height The height of the images that will be tested, if 0u the height will be selected randomly (max. 2000), range: [16 * verticalTiles, infinity)
148 * @param clipLimit Clip limit to used for testing, if <= 0 this parameter will be selected randomly (between 1 and 100), range: [1, infinity)
149 * @param horizontalTiles Number of horizontal tiles to be used for testing, if 0 this parameter will be selected randomly (between 2 and 16), range: [2, infinity)
150 * @param verticalTiles Number of vertical tiles to be used for testing, if 0 this parameter will be selected randomly (between 2 and 16), range: [2, infinity)
151 * @param testDuration Number of seconds for each test, range: (0, infinity)
152 * @param worker A worker instance for parallel execution of the tested function (performance)
153 * @return True if validation was successful, otherwise false
154 */
155 static bool testContrastLimitedHistogramEqualization(const unsigned int width, const unsigned int height, const Scalar clipLimit, const unsigned int horizontalTiles, const unsigned int verticalTiles, const double testDuration, Worker& worker);
156
157 /**
158 * Performance and validation test for the computation of histograms
159 * @param testDuration Number of seconds for each test, range: (0, infinity)
160 * @param width The width of the images that will be tested, if 0u the width will be selected randomly (max. 2000), range: [1, infinity)
161 * @param height The height of the images that will be tested, if 0u the height will be selected randomly (max. 2000), range: [1, infinity)
162 * @param randomGenerator A random generator that will be used to generate test data
163 * @param worker A worker instance for parallel execution of the tested function (performance)
164 * @return True if validation was successful, otherwise false
165 * @tparam tChannels Number of channels to use for this test, range: [1, 4]
166 */
167 template <unsigned int tChannels>
168 static bool testDetermineHistogram8BitPerChannel(const double testDuration, const unsigned int width, const unsigned int height, RandomGenerator& randomGenerator, Worker& worker);
169
170 /**
171 * Performance and validation test for the computation of histograms for sub-frames/-regions of images
172 * @param testDuration Number of seconds for each test, range: (0, infinity)
173 * @param width The width of the images that will be tested, if 0u the width will be selected randomly (max. 2000), range: [1, infinity)
174 * @param height The height of the images that will be tested, if 0u the height will be selected randomly (max. 2000), range: [1, infinity)
175 * @param randomGenerator A random generator that will be used to generate test data
176 * @param worker A worker instance for parallel execution of the tested function (performance)
177 * @return True if validation was successful, otherwise false
178 * @tparam tChannels Number of channels to use for this test, range: [1, 4]
179 */
180 template <unsigned int tChannels>
181 static bool testDetermineHistogram8BitPerChannelSubFrame(const double testDuration, const unsigned int width, const unsigned int height, RandomGenerator& randomGenerator, Worker& worker);
182
183 protected:
184
185 /**
186 * Validate the computation of image histograms
187 * @param frame Valid pointer to the data of the original input image
188 * @param width The width of the images that will be tested, if 0u the width will be selected randomly (max. 2000), range: [1, infinity)
189 * @param height The height of the images that will be tested, if 0u the height will be selected randomly (max. 2000), range: [1, infinity)
190 * @param framePaddingElements Number of padding elements of the input image, range: [0, infinity)
191 * @param subFrameX Horizontal coordinate of the top-left corner of the sub-frame for which the histogram will be validated, range: [0, width)
192 * @param subFrameY Vertical coordinate of the top-left corner of the sub-frame for which the histogram will be validated, range: [0, height)
193 * @param subFrameWidth Width of the sub-frame that will be validated, range: [1, width) such that `subFrameX + subFrameWidth <= width`
194 * @param subFrameHeight Height of the sub-frame that will be validated, range: [1, height) such that `subFrameY + subFrameHeight <= height`
195 * @param histogramToValidate The histogram that will be validated given the input image `frame`.
196 * @return True if validation was successful, otherwise false
197 * @tparam tChannels Number of channels of the input image `frame`, range: [1, 4]
198 */
199 template <unsigned int tChannels>
200 static bool validateDetermineHistogram8BitPerChannel(const uint8_t* frame, const unsigned int width, const unsigned int height, const unsigned int framePaddingElements, const unsigned int subFrameX, const unsigned int subFrameY, const unsigned int subFrameWidth, const unsigned int subFrameHeight, const CV::Histogram::Histogram8BitPerChannel<tChannels>& histogramToValidate);
201};
202
203} // namespace TestCV
204
205} // namespace Test
206
207} // namespace Ocean
208
209#endif // META_OCEAN_TEST_TESTCV_TEST_HISTOGRAM_H
Implementation of Contrast-Limited Adaptive Histogram Equalization (CLAHE).
Definition Histogram.h:755
This class implements a standard histogram object storing 8 bit per channel.
Definition Histogram.h:208
This class implements a generator for random numbers.
Definition RandomGenerator.h:42
This class implements a pixel bounding box test.
Definition TestHistogram.h:36
static bool testContrastLimitedAdaptiveHistogramTileLookupTables(const double testDuration, Worker &worker)
Performance and validation test for the computation of the CLAHE lookup tables.
static bool validateBilinearInterpolationParameters(const Indices32 &lowBins, const std::vector< unsigned char > &lowFactors_fixed7, const unsigned int imageEdgeLength, const unsigned int tilesCount)
Validation function for the computation of the CLAHE horizontal (or vertical) bilinear interpolation ...
static unsigned int validateTileLookupTables(const unsigned char *source, const unsigned int width, const unsigned int height, const std::vector< unsigned char > &validationLookupTables, const unsigned int horizontalTiles, const unsigned int verticalTiles, const Scalar clipLimit, double &maxAbsError, const unsigned int sourcePaddingElements=0u, const double maxAbsErrorThresholdMultiple=1.0, const double maxAbsErrorThreshold=25.0)
Validation function for the computation of the CLAHE tile lookup tables.
static bool testDetermineHistogram8BitPerChannelSubFrame(const double testDuration, const unsigned int width, const unsigned int height, RandomGenerator &randomGenerator, Worker &worker)
Performance and validation test for the computation of histograms for sub-frames/-regions of images.
static bool testContrastLimitedAdaptiveHistogramTileLookupTables(const unsigned int width, const unsigned int height, const Scalar clipLimit, const unsigned int horizontalTiles, const unsigned int verticalTiles, const double testDuration, Worker &worker)
Performance and validation test for the computation of the CLAHE lookup tables.
static bool testDetermineHistogram8BitPerChannel(const double testDuration, const unsigned int width, const unsigned int height, RandomGenerator &randomGenerator, Worker &worker)
Performance and validation test for the computation of histograms.
static bool testDetermineHistogram8BitPerChannel(const double testDuration, Worker &worker)
Performance and validation test for the computation of histograms.
static bool testDetermineHistogram8BitPerChannelSubFrame(const double testDuration, Worker &worker)
Performance and validation test for the computation of histograms on sub-frames/-regions of an image.
static bool validateEqualization8BitPerChannel(const unsigned char *const source, const unsigned int width, const unsigned height, const unsigned char *const validationTarget, const Scalar clipLimit=Scalar(40), const unsigned int horizontalTiles=8u, const unsigned int verticalTiles=8u, const unsigned int sourcePaddingElements=0u, const unsigned int validationTargetPaddingElements=0u, double *maxError=nullptr, unsigned char *groundtruth=nullptr)
Validation function for CLAHE.
static bool testContrastLimitedHistogramEqualization(const unsigned int width, const unsigned int height, const Scalar clipLimit, const unsigned int horizontalTiles, const unsigned int verticalTiles, const double testDuration, Worker &worker)
Test the Contrast-Limited Histogram Equalization (CLAHE)
static bool validateDetermineHistogram8BitPerChannel(const uint8_t *frame, const unsigned int width, const unsigned int height, const unsigned int framePaddingElements, const unsigned int subFrameX, const unsigned int subFrameY, const unsigned int subFrameWidth, const unsigned int subFrameHeight, const CV::Histogram::Histogram8BitPerChannel< tChannels > &histogramToValidate)
Validate the computation of image histograms.
static bool testContrastLimitedHistogramEqualization(const double testDuration, Worker &worker)
Test the Contrast-Limited Histogram Equalization (CLAHE)
static bool test(const double testDuration, Worker &worker, const TestSelector &selector=TestSelector())
Tests the histogram function.
static bool testContrastLimitedAdaptiveBilinearInterpolationParameters(const double testDuration)
Validation test for the computation of the CLAHE horizontal bilinear interpolation parameters.
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
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition Base.h:96
float Scalar
Definition of a scalar type.
Definition Math.h:129
The namespace covering the entire Ocean framework.
Definition Accessor.h:15