Ocean
TestAdvancedFrameInterpolatorBilinear.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_ADVANCED_FRAME_INTERPOLATOR_BILINEAR_H
9 #define META_OCEAN_TEST_TESTCV_TESTADVANCED_TEST_ADVANCED_FRAME_INTERPOLATOR_BILINEAR_H
10 
12 
13 #include "ocean/base/Frame.h"
14 #include "ocean/base/Worker.h"
15 
17 
18 #include "ocean/math/Vector2.h"
19 
20 namespace Ocean
21 {
22 
23 namespace Test
24 {
25 
26 namespace TestCV
27 {
28 
29 namespace TestAdvanced
30 {
31 
32 /**
33  * This class implements a bilinear frame interpolator test.
34  * @ingroup testcvadvanced
35  */
36 class OCEAN_TEST_CV_ADVANCED_EXPORT TestAdvancedFrameInterpolatorBilinear
37 {
38  protected:
39 
40  /**
41  * Definition of individual types of implementation.
42  */
43  enum ImplementationType : uint32_t
44  {
45  /// The naive implementation.
47  /// The template-based implementation.
49  /// The SSE-based implementation.
51  /// The NEON-based implementation.
53  /// The default implementation (which is actually used by default).
54  IT_DEFAULT
55  };
56 
57  public:
58 
59  /**
60  * Tests all advanced bilinear interpolation filter functions.
61  * @param testDuration Number of seconds for each test, with range (0, infinity)
62  * @param worker The worker object to distribute the CPU load
63  * @return True, if succeeded
64  */
65  static bool test(const double testDuration, Worker& worker);
66 
67  /**
68  * Tests the pixel interpolation function for frames with 8 bit per channel and mask.
69  * @param testDuration Number of seconds for each test, with range (0, infinity)
70  * @return True, if succeeded
71  */
72  static bool testInterpolatePixelWithMask8BitPerChannel(const double testDuration);
73 
74  /**
75  * Tests the pixel interpolation function for frames with 8 bit per channel and mask.
76  * @param testDuration Number of seconds for each test, with range (0, infinity)
77  * @param pixelCenter The pixel center to be used
78  * @return True, if succeeded
79  * @tparam TScalar The data type of the scalar to be used, either 'float' or 'double'
80  */
81  template <typename TScalar>
82  static bool testInterpolatePixelWithMask8BitPerChannel(const CV::PixelCenter pixelCenter, const double testDuration);
83 
84  /**
85  * Tests the bilinear square interpolation.
86  * @param testDuration Number of seconds for each test
87  * @return True, if succeeded
88  */
89  static bool testInterpolateSquare(const double testDuration);
90 
91  /**
92  * Tests the bilinear interpolation of an image patch with mask.
93  * @param testDuration Number of seconds for each test
94  * @return True, if succeeded
95  */
96  static bool testInterpolatePatchWithMask(const double testDuration);
97 
98  /**
99  * Tests the bilinear square interpolation mirrored at the frame borders.
100  * @param testDuration Number of seconds for each test
101  * @return True, if succeeded
102  */
103  static bool testInterpolateSquareMirroredBorder(const double testDuration);
104 
105  /**
106  * Tests the bilinear square interpolation.
107  * @param width The width of the test image, in pixel, with range [tSize, infinity)
108  * @param height The height of the test image, in pixel, with range [tSize, infinity)
109  * @param testDuration Number of seconds for each test
110  * @return True, if succeeded
111  * @tparam tChannels The number of data channels, with range [1, infinity)
112  * @tparam tPatchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
113  * @tparam tPixelCenter The pixel center to be used during interpolation, either 'PC_TOP_LEFT' or 'PC_CENTER'
114  */
115  template <unsigned int tChannels, unsigned int tPatchSize, CV::PixelCenter tPixelCenter>
116  static bool testInterpolateSquare(const unsigned int width, const unsigned int height, const double testDuration);
117 
118  /**
119  * Tests the bilinear interpolation of an image patch with mask.
120  * @param width The width of the test image, in pixel, with range [tSize, infinity)
121  * @param height The height of the test image, in pixel, with range [tSize, infinity)
122  * @param testDuration Number of seconds for each test
123  * @return True, if succeeded
124  * @tparam tChannels The number of data channels, with range [1, infinity)
125  * @tparam tPatchSize The size of the square patch (the edge length) in pixel, with range [1, infinity)
126  * @tparam tPixelCenter The pixel center to be used during interpolation, either 'PC_TOP_LEFT' or 'PC_CENTER'
127  */
128  template <unsigned int tChannels, unsigned int tPatchSize, CV::PixelCenter tPixelCenter>
129  static bool testInterpolatePatchWithMask(const unsigned int width, const unsigned int height, const double testDuration);
130 
131  /**
132  * Tests the bilinear square mirrored interpolation.
133  * Pixels inside the blocks mapping outside the frames are mirrored back into the frame.
134  * @param width The width of the test image, in pixel, with range [tSize, infinity)
135  * @param height The height of the test image, in pixel, with range [tSize, infinity)
136  * @param testDuration Number of seconds for each test, with range (0, infinity)
137  * @return True, if succeeded
138  * @tparam tChannels The number of data channels, with range [1, infinity)
139  * @tparam tPatchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
140  */
141  template <unsigned int tChannels, unsigned int tPatchSize>
142  static bool testInterpolateSquareMirroredBorder(const unsigned int width, const unsigned int height, const double testDuration);
143 
144  /**
145  * Interpolates a square image patch with sub-pixel accuracy.
146  * @param frame The frame in which the image patch is located, must be valid
147  * @param patchWidth The width of the square patch in pixel, with range [1, infinity), must be odd
148  * @param patchHeight The height of the square patch in pixel, with range [1, infinity), must be odd
149  * @param position The center position of the square image patch with range [patchSize/2, width - patchSize/2 - 1)x[patchSize/2, height - patchSize/2 - 1)
150  * @param pixelCenter The definition of the pixel center when applying the interpolation
151  * @param buffer The resulting (continuous) buffer of the interpolated image patch, must be valid
152  * @return True, if succeeded
153  */
154  static bool interpolatePatch8BitPerChannel(const Frame& frame, const unsigned int patchWidth, const unsigned int patchHeight, const Vector2& position, const CV::PixelCenter pixelCenter, uint8_t* buffer);
155 
156  /**
157  * Interpolates an image patch and mask with sub-pixel accuracy.
158  * @param frame The frame in which the image patch is located, must be valid
159  * @param mask The mask defining valid and invalid image pixels, must be valid
160  * @param patchWidth The width of the square patch in pixel, with range [1, infinity)
161  * @param patchHeight The height of the square patch in pixel, with range [1, infinity)
162  * @param position The center position of the square image patch with range [patchSize/2, width - patchSize/2 - 1)x[patchSize/2, height - patchSize/2 - 1)
163  * @param pixelCenter The definition of the pixel center when applying the interpolation
164  * @param patchBuffer The resulting (continuous) buffer of the interpolated image patch, must be valid
165  * @param patchMaskBuffer The resulting (continuous) buffer of the mask, must be valid
166  * @param validMaskValue The mask value of a valid pixel, with range [0, 255]
167  * @return True, if succeeded
168  */
169  static bool interpolatePatchWithMask8BitPerChannel(const Frame& frame, const Frame& mask, const unsigned int patchWidth, const unsigned int patchHeight, const Vector2& position, const CV::PixelCenter pixelCenter, uint8_t* patchBuffer, uint8_t* patchMaskBuffer, const uint8_t validMaskValue);
170 
171  /**
172  * Interpolates a square image patch with sub-pixel accuracy (mirrored at the image borders).
173  * The center of a pixel is expected to be located at the top-left corner of a pixel.
174  * @param frame The frame in which the image patch is located, must be valid
175  * @param patchSize The size of the square patch (the edge length) in pixel, with range [1, infinity), must be odd
176  * @param position The center position of the square image patch with range [patchSize/2, width - patchSize/2 - 1)x[patchSize/2, height - patchSize/2 - 1)
177  * @param buffer The resulting (continuous) buffer of the interpolated image patch, must be valid
178  */
179  static void interpolateSquarePatchMirroredBorder8BitPerChannel(const Frame& frame, const unsigned int patchSize, const Vector2& position, uint8_t* buffer);
180 
181  /**
182  * Tests the homography transformation function defining a binary mask for known and unknown image content.
183  * @param testDuration Number of seconds for each test, with range (0, infinity)
184  * @param worker The worker object to distribute the CPU load
185  * @return True, if succeeded
186  */
187  static bool testHomographyFilterMask(const double testDuration, Worker& worker);
188 
189  /**
190  * Tests the homography transformation function (with binary mask defining known and unknown image content) for a given frame dimension and channel number.
191  * @param width The width of the frame in pixel, with range [1, infinity)
192  * @param height The height of the frame in pixel, with range [1, infinity)
193  * @param channels The number of frame channels, with range [1, 4]
194  * @param testDuration Number of seconds for each test, with range (0, infinity)
195  * @param worker The worker object to distribute the CPU load
196  * @return True, if succeeded
197  */
198  static bool testHomographyFilterMask(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker& worker);
199 
200  protected:
201 
202  /**
203  * Validates a pixel interpolation result for frame with 8 bit per channel with mask.
204  * @param frame The frame in pixel the pixel interpolation was applied, must be valid
205  * @param mask The mask defining valid and invalid pixels, must be valid
206  * @param position The position for which the interpolated pixel will be determined, with ranges [0, frame.width() - 1]x[0, frame.height() - 1] for PC_TOP_LEFT, [0, frame.width()]x[0, frame.height()] for PC_CENTER
207  * @param pixelCenter The pixel center to be used during interpolation
208  * @param maskValue The mask pixel value defining a valid pixel, an invalid pixel is defined by 0xFF - maskValue
209  * @param interpolationResult The interpolation result to be verified, one for each frame channel
210  * @param maskResult The mask result to be verified
211  * @param threshold The maximal distance between interpolated result and ground-truth result so that the result is valid, with range [0, 255)
212  * @return True, if the interpolation is correct
213  * @tparam TScalar The data type of a scalar, either 'float' or 'double'
214  */
215  template <typename TScalar>
216  static bool validateInterpolatePixel8BitPerChannel(const Frame& frame, const Frame& mask, const VectorT2<TScalar>& position, const CV::PixelCenter pixelCenter, const uint8_t maskValue, const uint8_t* const interpolationResult, const uint8_t maskResult, const TScalar threshold);
217 
218  /**
219  * Validates the homography interpolation function (using a binary mask to define output pixels which will be interpolated).
220  * @param inputFrame The frame which will be interpolated based on the homography, must be valid
221  * @param outputFilterMask The filter mask defining output pixel which will be interpolated, must be valid
222  * @param outputFrame The original output frame before the interpolation was applied, must be valid
223  * @param interpolatedOutputFrame The interpolated frame to verify, must be valid
224  * @param input_H_output The homography that has been used to interpolate/warp the frame, transforming points in the output frame to points in the input frame, must not be singular
225  * @param boundingBox Optional bounding box to apply the interpolation to a subset of the output frame only, invalid to handle the entire output frame
226  * @return True, if the interpolation is correct
227  */
228  static bool validateHomographyFilterMask8BitPerChannel(const Frame& inputFrame, const Frame& outputFilterMask, const Frame& outputFrame, const Frame& interpolatedOutputFrame, const SquareMatrix3& input_H_output, const CV::PixelBoundingBox& boundingBox);
229 };
230 
231 }
232 
233 }
234 
235 }
236 
237 }
238 
239 #endif // META_OCEAN_TEST_TESTCV_TESTADVANCED_TEST_ADVANCED_FRAME_INTERPOLATOR_BILINEAR_H
This class implements Ocean's image class.
Definition: Frame.h:1792
This class implements a bilinear frame interpolator test.
Definition: TestAdvancedFrameInterpolatorBilinear.h:37
static bool interpolatePatch8BitPerChannel(const Frame &frame, const unsigned int patchWidth, const unsigned int patchHeight, const Vector2 &position, const CV::PixelCenter pixelCenter, uint8_t *buffer)
Interpolates a square image patch with sub-pixel accuracy.
static bool testInterpolatePatchWithMask(const unsigned int width, const unsigned int height, const double testDuration)
Tests the bilinear interpolation of an image patch with mask.
static bool interpolatePatchWithMask8BitPerChannel(const Frame &frame, const Frame &mask, const unsigned int patchWidth, const unsigned int patchHeight, const Vector2 &position, const CV::PixelCenter pixelCenter, uint8_t *patchBuffer, uint8_t *patchMaskBuffer, const uint8_t validMaskValue)
Interpolates an image patch and mask with sub-pixel accuracy.
ImplementationType
Definition of individual types of implementation.
Definition: TestAdvancedFrameInterpolatorBilinear.h:44
@ IT_SSE
The SSE-based implementation.
Definition: TestAdvancedFrameInterpolatorBilinear.h:50
@ IT_NEON
The NEON-based implementation.
Definition: TestAdvancedFrameInterpolatorBilinear.h:52
@ IT_NAIVE
The naive implementation.
Definition: TestAdvancedFrameInterpolatorBilinear.h:46
@ IT_TEMPLATE
The template-based implementation.
Definition: TestAdvancedFrameInterpolatorBilinear.h:48
static void interpolateSquarePatchMirroredBorder8BitPerChannel(const Frame &frame, const unsigned int patchSize, const Vector2 &position, uint8_t *buffer)
Interpolates a square image patch with sub-pixel accuracy (mirrored at the image borders).
static bool testHomographyFilterMask(const double testDuration, Worker &worker)
Tests the homography transformation function defining a binary mask for known and unknown image conte...
static bool testInterpolateSquare(const unsigned int width, const unsigned int height, const double testDuration)
Tests the bilinear square interpolation.
static bool testInterpolatePatchWithMask(const double testDuration)
Tests the bilinear interpolation of an image patch with mask.
static bool testInterpolateSquareMirroredBorder(const double testDuration)
Tests the bilinear square interpolation mirrored at the frame borders.
static bool validateInterpolatePixel8BitPerChannel(const Frame &frame, const Frame &mask, const VectorT2< TScalar > &position, const CV::PixelCenter pixelCenter, const uint8_t maskValue, const uint8_t *const interpolationResult, const uint8_t maskResult, const TScalar threshold)
Validates a pixel interpolation result for frame with 8 bit per channel with mask.
static bool testInterpolateSquare(const double testDuration)
Tests the bilinear square interpolation.
static bool testInterpolatePixelWithMask8BitPerChannel(const CV::PixelCenter pixelCenter, const double testDuration)
Tests the pixel interpolation function for frames with 8 bit per channel and mask.
static bool testHomographyFilterMask(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the homography transformation function (with binary mask defining known and unknown image conte...
static bool test(const double testDuration, Worker &worker)
Tests all advanced bilinear interpolation filter functions.
static bool testInterpolateSquareMirroredBorder(const unsigned int width, const unsigned int height, const double testDuration)
Tests the bilinear square mirrored interpolation.
static bool testInterpolatePixelWithMask8BitPerChannel(const double testDuration)
Tests the pixel interpolation function for frames with 8 bit per channel and mask.
static bool validateHomographyFilterMask8BitPerChannel(const Frame &inputFrame, const Frame &outputFilterMask, const Frame &outputFrame, const Frame &interpolatedOutputFrame, const SquareMatrix3 &input_H_output, const CV::PixelBoundingBox &boundingBox)
Validates the homography interpolation function (using a binary mask to define output pixels which wi...
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
PixelCenter
Definition of individual centers of pixels.
Definition: CV.h:117
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15