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