8#ifndef META_OCEAN_TEST_TESTCV_TEST_FRAME_INTERPOLATOR_NEAREST_PIXEL_H
9#define META_OCEAN_TEST_TESTCV_TEST_FRAME_INTERPOLATOR_NEAREST_PIXEL_H
64 static bool testAffine(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
87 static bool testHomography(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
106 static bool testHomographyMask(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
128 template <
typename T,
unsigned int tChannels>
129 static bool testResize(
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int targetWidth,
const unsigned int targetHeight,
const double testDuration,
Worker& worker);
147 template <
bool tOffset>
148 static bool testTransform(
const unsigned int width,
const unsigned int height,
const double testDuration,
Worker& worker);
159 template <
bool tOffset>
160 static bool testTransformMask(
const unsigned int width,
const unsigned int height,
const double testDuration,
Worker& worker);
180 template <
typename TElementType,
unsigned int tChannels>
181 static bool testRotate90(
const unsigned int width,
const unsigned int height,
const double testDuration,
Worker& worker);
201 template <
typename T>
202 static void validateHomography(
const T* frame,
const unsigned int frameWidth,
const unsigned int frameHeight,
const unsigned int framePaddingElements,
const T* interpolatedFrame,
const unsigned int interpolatedFrameWidth,
const unsigned int interpolatedFrameHeight,
const unsigned int interpolatedFramePaddingElements,
const unsigned int channels,
const SquareMatrix3& homography,
const T* backgroundColor,
const CV::PixelPositionI& interpolatedFrameOrigin,
double* maximalAbsError =
nullptr,
double* averageAbsError =
nullptr, T* groundtruth =
nullptr);
218 template <
typename T>
219 static bool validateResizedFrame(
const T* source,
const T* target,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int targetWidth,
const unsigned int targetHeight,
const unsigned int channels,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements);
230 template <
bool tOffset>
243 template <
bool tOffset>
260 template <
typename TElementType>
261 static bool validateRotate90(
const TElementType* frame,
const unsigned int channels,
const unsigned int width,
const unsigned int height,
const TElementType* clockwise,
const TElementType* counterClockwise,
const unsigned int framePaddingElements,
const unsigned int clockwisePaddingElements,
const unsigned int counterClockwisePaddingElements);
278void TestFrameInterpolatorNearestPixel::validateHomography(
const T* frame,
const unsigned int frameWidth,
const unsigned int frameHeight,
const unsigned int framePaddingElements,
const T* interpolatedFrame,
const unsigned int interpolatedFrameWidth,
const unsigned int interpolatedFrameHeight,
const unsigned int interpolatedFramePaddingElements,
const unsigned int channels,
const SquareMatrix3& homography,
const T* backgroundColor,
const CV::PixelPositionI& interpolatedFrameOrigin,
double* maximalAbsError,
double* averageAbsError, T* groundtruth)
280 ocean_assert(frame !=
nullptr && interpolatedFrame !=
nullptr);
281 ocean_assert(frameWidth != 0u && frameHeight != 0u);
282 ocean_assert(interpolatedFrameWidth != 0u && interpolatedFrameHeight != 0u);
283 ocean_assert(channels != 0u);
285 ocean_assert(backgroundColor !=
nullptr);
287 double sumAbsError = 0.0;
288 double maxAbsError = 0.0;
289 unsigned long long measurements = 0ull;
291 for (
unsigned int y = 0u; y < interpolatedFrameHeight; ++y)
293 for (
unsigned int x = 0u; x < interpolatedFrameWidth; ++x)
295 const T*
const interpolatedPixel = interpolatedFrame + (interpolatedFrameWidth * y + x) * channels + y * interpolatedFramePaddingElements;
298 const Vector2 inputPosition = homography * outputPosition;
304 if (inputXI == -1 || inputXI == 0 || inputXI == (
int)(frameWidth - 1u) || inputXI == (
int)frameWidth || inputYI == -1 || inputYI == 0 || inputYI == (
int)(frameHeight - 1u) || inputYI == (
int)(frameHeight))
309 const unsigned int inputX = (
unsigned int)inputXI;
310 const unsigned int inputY = (
unsigned int)inputYI;
312 if (inputX < frameWidth && inputY < frameHeight)
314 const unsigned int nearestNeighborIndex = (inputY * frameWidth + inputX) * channels + inputY * framePaddingElements;
316 for (
unsigned int n = 0u; n < channels; ++n)
320 *groundtruth = frame[nearestNeighborIndex + n];
324 const double interpolatedPixelD = double(interpolatedPixel[n]);
325 const double framePixelD = double(frame[nearestNeighborIndex + n]);
326 const double absError =
NumericD::abs(interpolatedPixelD - framePixelD);
328 sumAbsError += absError;
330 if (absError > maxAbsError)
332 maxAbsError = absError;
340 for (
unsigned int n = 0u; n < channels; ++n)
344 *groundtruth = backgroundColor[n];
348 const double absError =
NumericD::abs(
double(interpolatedPixel[n]) -
double(backgroundColor[n]));
350 sumAbsError += absError;
352 if (absError > maxAbsError)
354 maxAbsError = absError;
365 ocean_assert(measurements != 0ull);
366 *averageAbsError = sumAbsError / double(measurements);
371 *maximalAbsError = maxAbsError;
This class implements a 2D pixel position with pixel precision.
Definition PixelPosition.h:63
T y() const
Returns the vertical coordinate position of this object.
Definition PixelPosition.h:468
T x() const
Returns the horizontal coordinate position of this object.
Definition PixelPosition.h:456
This class implements Ocean's image class.
Definition Frame.h:1879
This class implements a 2D lookup object with values at the bins' corners defining the individual loo...
Definition Lookup2.h:636
static T abs(const T value)
Returns the absolute value of a given value.
Definition Numeric.h:1220
static constexpr int32_t round32(const T value)
Returns the rounded 32 bit integer value of a given value.
Definition Numeric.h:2073
bool isSingular() const
Returns whether this matrix is singular (and thus cannot be inverted).
Definition SquareMatrix3.h:1342
This class implements a nearest pixel frame interpolator test.
Definition TestFrameInterpolatorNearestPixel.h:33
static bool testResize(const double testDuration, Worker &worker)
Tests the resize function.
static bool testAffine(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Test for affine image transformations for varying frame dimensions and channel numbers.
static bool testResize(const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int targetWidth, const unsigned int targetHeight, const double testDuration, Worker &worker)
Tests the resize function for a given frame dimension and channel number.
static bool testHomography(const double testDuration, Worker &worker)
Tests the homography transformation function.
static bool validateRotate90(const TElementType *frame, const unsigned int channels, const unsigned int width, const unsigned int height, const TElementType *clockwise, const TElementType *counterClockwise, const unsigned int framePaddingElements, const unsigned int clockwisePaddingElements, const unsigned int counterClockwisePaddingElements)
Validates the 90 degree rotate function.
static bool validateHomographyMask8BitPerChannel(const Frame &inputFrame, const Frame &outputFrame, const Frame &outputMask, const SquareMatrix3 &input_H_output, const CV::PixelPositionI &outputFrameOrigin)
Validates the homography interpolation function (using a binary mask to define known and unknown imag...
static bool testTransform(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the frame transformation function applying a lookup table.
static bool testTransformMask(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the frame mask transformation function applying a lookup table.
static bool testHomographyMask(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 void validateHomography(const T *frame, const unsigned int frameWidth, const unsigned int frameHeight, const unsigned int framePaddingElements, const T *interpolatedFrame, const unsigned int interpolatedFrameWidth, const unsigned int interpolatedFrameHeight, const unsigned int interpolatedFramePaddingElements, const unsigned int channels, const SquareMatrix3 &homography, const T *backgroundColor, const CV::PixelPositionI &interpolatedFrameOrigin, double *maximalAbsError=nullptr, double *averageAbsError=nullptr, T *groundtruth=nullptr)
Validation function for the nearest-neighbor interpolation of 2D homogeneous image transformations (+...
Definition TestFrameInterpolatorNearestPixel.h:278
static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker, const TestSelector &selector=TestSelector())
Tests all nearest pixel interpolation filter functions.
static bool testRotate90(const double testDuration, Worker &worker)
Tests the 90 degree rotate function.
static bool validateTransformationMask(const Frame &frame, const Frame &target, const Frame &targetMask, const CV::FrameInterpolatorNearestPixel::LookupTable &lookupTable, const uint8_t maskValue)
Validates the frame mask transformation function applying a lookup table.
static bool testHomography(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the homography transformation function for a given frame dimension and channel number.
static bool validateResizedFrame(const T *source, const T *target, const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int targetWidth, const unsigned int targetHeight, const unsigned int channels, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements)
Validates a resized frame.
static bool testHomographyMask(const double testDuration, Worker &worker)
Tests the homography transformation function defining a binary mask for known and unknown image conte...
static bool testAffine(const double testDuration, Worker &worker)
Test for affine image transformations.
static bool validateTransformation(const Frame &frame, const Frame &target, const CV::FrameInterpolatorNearestPixel::LookupTable &lookupTable, const uint8_t *borderColor)
Validates the frame transformation function applying a lookup table.
static bool testRotate90(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the 90 degree rotate function for a specific frame size and number of channels.
static bool testSpecialCasesResize400x400To224x224_8BitPerChannel(const double testDuration)
Tests the special case resize function for image resolutions from 400x400 to 224x224.
This class implements a test selector that parses test function strings and determines which tests sh...
Definition TestSelector.h:51
const T & x() const noexcept
Returns the x value.
Definition Vector2.h:710
const T & y() const noexcept
Returns the y value.
Definition Vector2.h:722
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
float Scalar
Definition of a scalar type.
Definition Math.h:129
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition Vector2.h:28
The namespace covering the entire Ocean framework.
Definition Accessor.h:15