Ocean
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 
17 namespace Ocean
18 {
19 
20 /// Forward-declaration of class RandomGenerator
21 class RandomGenerator;
22 
23 namespace Test
24 {
25 
26 namespace TestCV
27 {
28 
29 /**
30  * This class implements a pixel bounding box test.
31  * @ingroup testcv
32  */
33 class OCEAN_TEST_CV_EXPORT TestHistogram : protected CV::ContrastLimitedAdaptiveHistogram
34 {
35  public:
36 
37  /**
38  * Tests the histogram function.
39  * @param testDuration Number of seconds for each test, range: (0, infinity)
40  * @param worker A worker instance for parallel execution of the tested function (performance)
41  * @return True if all tests of this class passed, otherwise false
42  */
43  static bool test(const double testDuration, Worker& worker);
44 
45  /**
46  * Performance and validation test for the computation of histograms
47  * @param testDuration Number of seconds for each test, range: (0, infinity)
48  * @param worker A worker instance for parallel execution of the tested function (performance)
49  * @return True if validation was successful, otherwise false
50  */
51  static bool testDetermineHistogram8BitPerChannel(const double testDuration, Worker& worker);
52 
53  /**
54  * Performance and validation test for the computation of histograms on sub-frames/-regions of an image
55  * @param testDuration Number of seconds for each test, range: (0, infinity)
56  * @param worker A worker instance for parallel execution of the tested function (performance)
57  * @return True if validation was successful, otherwise false
58  */
59  static bool testDetermineHistogram8BitPerChannelSubFrame(const double testDuration, Worker& worker);
60 
61  /**
62  * Performance and validation test for the computation of the CLAHE lookup tables
63  * @param testDuration Number of seconds for each test, range: (0, infinity)
64  * @param worker A worker instance for parallel execution of the tested function (performance)
65  * @return True if validation was successful, otherwise false
66  */
67  static bool testContrastLimitedAdaptiveHistogramTileLookupTables(const double testDuration, Worker& worker);
68 
69  /**
70  * Validation test for the computation of the CLAHE horizontal bilinear interpolation parameters
71  * @param testDuration Number of seconds for each test, range: (0, infinity)
72  * @return True if validation was successful, otherwise false
73  */
74  static bool testContrastLimitedAdaptiveBilinearInterpolationParameters(const double testDuration);
75 
76  /**
77  * Test the Contrast-Limited Histogram Equalization (CLAHE)
78  * @param testDuration Number of seconds that this test will run, range: (0, infinity)
79  * @param worker A worker instance for parallel execution of the tested function (performance)
80  * @return True if the test passed, otherwise false
81  */
82  static bool testContrastLimitedHistogramEqualization(const double testDuration, Worker& worker);
83 
84  /**
85  * Validation function for the computation of the CLAHE horizontal (or vertical) bilinear interpolation parameters
86  * @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`
87  * @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`
88  * @param imageEdgeLength Image edge length, either width or height, range: [1, infinity)
89  * @param tilesCount Number of horizontal (or vertical) tiles, range: [1, infinity)
90  * @return True if the validation was successful, otherwise false
91  */
92  static bool validateBilinearInterpolationParameters(const Indices32& lowBins, const std::vector<unsigned char>& lowFactors_fixed7, const unsigned int imageEdgeLength, const unsigned int tilesCount);
93 
94  /**
95  * Validation function for the computation of the CLAHE tile lookup tables
96  * @param source Pointer to the source image, must be initialized, expected size: `width` x `height`
97  * @param width The width of the source image
98  * @param height The height of the source image
99  * @param validationLookupTables Values that will be validated, must be initialized, expected size: `width` x `height`
100  * @param horizontalTiles Number of horizontal tiles, range: [1, infinity)
101  * @param verticalTiles Number of vertical tiles, range: [1, infinity)
102  * @param clipLimit CLAHE clip limit, range: [1, infinity)
103  * @param maxAbsError Will hold the value of the largest absolute error measured during the validation, otherwise this will be ignored, range: [0, 255]
104  * @param sourcePaddingElements Number of padding elements in the source data, range: [0u, infinity), default: 0
105  * @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
106  * @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
107  * @return Number of tiles for which the validation has failed. Will be zero if all tile validations were successful, range: [0, horizontalTiles * verticalTiles]
108  */
109  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);
110 
111  /**
112  * Validation function for CLAHE
113  * @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`)
114  * @param width The width of the source and target frames, range: [horizontalTiles, infinity)
115  * @param height The height of the source and target frames, range: [verticalTiles, infinity)
116  * @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
117  * @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)
118  * @param horizontalTiles Number of tiles the source image will be split horizontally, range: [1, infinity)
119  * @param verticalTiles Number of tiles the source image will be split vertically, range: [1, infinity)
120  * @param sourcePaddingElements Number of padding elements in the source data, range: [0, infinity), default: 0
121  * @param validationTargetPaddingElements Number of padding elements in the target data, range: [0, infinity), default: 0
122  * @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
123  * @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)
124  * @return True if the validation was successful, otherwise false
125  */
126  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);
127 
128  /**
129  * Performance and validation test for the computation of the CLAHE lookup tables
130  * @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)
131  * @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)
132  * @param clipLimit Clip limit to used for testing, if <= 0 this parameter will be selected randomly (between 1 and 100), range: [1, infinity)
133  * @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)
134  * @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)
135  * @param testDuration Number of seconds for each test, range: (0, infinity)
136  * @param worker A worker instance for parallel execution of the tested function (performance)
137  * @return True if validation was successful, otherwise false
138  */
139  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);
140 
141  /**
142  * Test the Contrast-Limited Histogram Equalization (CLAHE)
143  * @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)
144  * @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)
145  * @param clipLimit Clip limit to used for testing, if <= 0 this parameter will be selected randomly (between 1 and 100), range: [1, infinity)
146  * @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)
147  * @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)
148  * @param testDuration Number of seconds for each test, range: (0, infinity)
149  * @param worker A worker instance for parallel execution of the tested function (performance)
150  * @return True if validation was successful, otherwise false
151  */
152  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);
153 
154  /**
155  * Performance and validation test for the computation of histograms
156  * @param testDuration Number of seconds for each test, range: (0, infinity)
157  * @param width The width of the images that will be tested, if 0u the width will be selected randomly (max. 2000), range: [1, infinity)
158  * @param height The height of the images that will be tested, if 0u the height will be selected randomly (max. 2000), range: [1, infinity)
159  * @param randomGenerator A random generator that will be used to generate test data
160  * @param worker A worker instance for parallel execution of the tested function (performance)
161  * @return True if validation was successful, otherwise false
162  * @tparam tChannels Number of channels to use for this test, range: [1, 4]
163  */
164  template <unsigned int tChannels>
165  static bool testDetermineHistogram8BitPerChannel(const double testDuration, const unsigned int width, const unsigned int height, RandomGenerator& randomGenerator, Worker& worker);
166 
167  /**
168  * Performance and validation test for the computation of histograms for sub-frames/-regions of images
169  * @param testDuration Number of seconds for each test, range: (0, infinity)
170  * @param width The width of the images that will be tested, if 0u the width will be selected randomly (max. 2000), range: [1, infinity)
171  * @param height The height of the images that will be tested, if 0u the height will be selected randomly (max. 2000), range: [1, infinity)
172  * @param randomGenerator A random generator that will be used to generate test data
173  * @param worker A worker instance for parallel execution of the tested function (performance)
174  * @return True if validation was successful, otherwise false
175  * @tparam tChannels Number of channels to use for this test, range: [1, 4]
176  */
177  template <unsigned int tChannels>
178  static bool testDetermineHistogram8BitPerChannelSubFrame(const double testDuration, const unsigned int width, const unsigned int height, RandomGenerator& randomGenerator, Worker& worker);
179 
180  protected:
181 
182  /**
183  * Validate the computation of image histograms
184  * @param frame Valid pointer to the data of the original input image
185  * @param width The width of the images that will be tested, if 0u the width will be selected randomly (max. 2000), range: [1, infinity)
186  * @param height The height of the images that will be tested, if 0u the height will be selected randomly (max. 2000), range: [1, infinity)
187  * @param framePaddingElements Number of padding elements of the input image, range: [0, infinity)
188  * @param subFrameX Horizontal coordinate of the top-left corner of the sub-frame for which the histogram will be validated, range: [0, width)
189  * @param subFrameY Vertical coordinate of the top-left corner of the sub-frame for which the histogram will be validated, range: [0, height)
190  * @param subFrameWidth Width of the sub-frame that will be validated, range: [1, width) such that `subFrameX + subFrameWidth <= width`
191  * @param subFrameHeight Height of the sub-frame that will be validated, range: [1, height) such that `subFrameY + subFrameHeight <= height`
192  * @param histogramToValidate The histogram that will be validated given the input image `frame`.
193  * @return True if validation was successful, otherwise false
194  * @tparam tChannels Number of channels of the input image `frame`, range: [1, 4]
195  */
196  template <unsigned int tChannels>
197  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);
198 };
199 
200 } // namespace TestCV
201 
202 } // namespace Test
203 
204 } // namespace Ocean
205 
206 #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:34
static bool testContrastLimitedAdaptiveHistogramTileLookupTables(const double testDuration, Worker &worker)
Performance and validation test for the computation of the CLAHE lookup tables.
static bool test(const double testDuration, Worker &worker)
Tests the histogram function.
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 testContrastLimitedAdaptiveBilinearInterpolationParameters(const double testDuration)
Validation test for the computation of the CLAHE horizontal bilinear interpolation parameters.
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:128
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15