8 #ifndef META_OCEAN_TEST_TESTCV_TEST_FRAME_INTERPOLATOR_NEAREST_PIXEL_H
9 #define META_OCEAN_TEST_TESTCV_TEST_FRAME_INTERPOLATOR_NEAREST_PIXEL_H
42 static bool test(
const unsigned int width,
const unsigned int height,
const double testDuration,
Worker& worker);
61 static bool testAffine(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
84 static bool testHomography(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
103 static bool testHomographyMask(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
125 template <
typename T,
unsigned int tChannels>
126 static bool testResize(
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int targetWidth,
const unsigned int targetHeight,
const double testDuration,
Worker& worker);
144 template <
bool tOffset>
145 static bool testTransform(
const unsigned int width,
const unsigned int height,
const double testDuration,
Worker& worker);
156 template <
bool tOffset>
157 static bool testTransformMask(
const unsigned int width,
const unsigned int height,
const double testDuration,
Worker& worker);
177 template <
typename TElementType,
unsigned int tChannels>
178 static bool testRotate90(
const unsigned int width,
const unsigned int height,
const double testDuration,
Worker& worker);
198 template <
typename T>
199 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);
215 template <
typename T>
216 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);
227 template <
bool tOffset>
240 template <
bool tOffset>
257 template <
typename TElementType>
258 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);
274 template <
typename T>
275 void 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)
277 ocean_assert(frame !=
nullptr && interpolatedFrame !=
nullptr);
278 ocean_assert(frameWidth != 0u && frameHeight != 0u);
279 ocean_assert(interpolatedFrameWidth != 0u && interpolatedFrameHeight != 0u);
280 ocean_assert(channels != 0u);
282 ocean_assert(backgroundColor !=
nullptr);
284 double sumAbsError = 0.0;
285 double maxAbsError = 0.0;
286 unsigned long long measurements = 0ull;
288 for (
unsigned int y = 0u; y < interpolatedFrameHeight; ++y)
290 for (
unsigned int x = 0u; x < interpolatedFrameWidth; ++x)
292 const T*
const interpolatedPixel = interpolatedFrame + (interpolatedFrameWidth * y + x) * channels + y * interpolatedFramePaddingElements;
295 const Vector2 inputPosition = homography * outputPosition;
301 if (inputXI == -1 || inputXI == 0 || inputXI == (
int)(frameWidth - 1u) || inputXI == (
int)frameWidth || inputYI == -1 || inputYI == 0 || inputYI == (
int)(frameHeight - 1u) || inputYI == (
int)(frameHeight))
306 const unsigned int inputX = (
unsigned int)inputXI;
307 const unsigned int inputY = (
unsigned int)inputYI;
309 if (inputX < frameWidth && inputY < frameHeight)
311 const unsigned int nearestNeighborIndex = (inputY * frameWidth + inputX) * channels + inputY * framePaddingElements;
313 for (
unsigned int n = 0u; n < channels; ++n)
317 *groundtruth = frame[nearestNeighborIndex + n];
321 const double interpolatedPixelD = double(interpolatedPixel[n]);
322 const double framePixelD = double(frame[nearestNeighborIndex + n]);
323 const double absError =
NumericD::abs(interpolatedPixelD - framePixelD);
325 sumAbsError += absError;
327 if (absError > maxAbsError)
329 maxAbsError = absError;
337 for (
unsigned int n = 0u; n < channels; ++n)
341 *groundtruth = backgroundColor[n];
345 const double absError =
NumericD::abs(
double(interpolatedPixel[n]) -
double(backgroundColor[n]));
347 sumAbsError += absError;
349 if (absError > maxAbsError)
351 maxAbsError = absError;
362 ocean_assert(measurements != 0ull);
363 *averageAbsError = sumAbsError / double(measurements);
368 *maximalAbsError = maxAbsError;
This class implements a 2D pixel position with pixel precision.
Definition: PixelPosition.h:65
T y() const
Returns the vertical coordinate position of this object.
Definition: PixelPosition.h:470
T x() const
Returns the horizontal coordinate position of this object.
Definition: PixelPosition.h:458
This class implements Ocean's image class.
Definition: Frame.h:1792
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:2064
bool isSingular() const
Returns whether this matrix is singular (and thus cannot be inverted).
Definition: SquareMatrix3.h:1341
This class implements a nearest pixel frame interpolator test.
Definition: TestFrameInterpolatorNearestPixel.h:31
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:275
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 test(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests all nearest pixel interpolation filter functions.
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.
const T & x() const noexcept
Returns the x value.
Definition: Vector2.h:698
const T & y() const noexcept
Returns the y value.
Definition: Vector2.h:710
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:128
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition: Vector2.h:21
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15