8#ifndef META_OCEAN_TEST_TESTCV_TEST_FRAME_INTERPOLATOR_BILINEAR_H
9#define META_OCEAN_TEST_TESTCV_TEST_FRAME_INTERPOLATOR_BILINEAR_H
66 template <
typename TScalar>
85 template <
typename TSource,
typename TTarget,
typename TScalar>
103 template <
typename T>
137 template <
typename T>
163 template <
typename T>
174 static bool testLookupMask(
const unsigned int width,
const unsigned int height,
const double testDuration,
Worker& worker);
184 static bool testRotateFrame(
const unsigned int width,
const unsigned int height,
const double testDuration,
Worker& worker);
204 static bool testAffine(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
216 template <
typename T>
217 static bool testHomography(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
228 static bool testHomographyMask(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
241 static bool testResize(
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int sourceChannels,
const unsigned int targetWidth,
const unsigned int targetHeight,
const double testDuration,
Worker& worker);
255 template <
typename T>
256 static bool testResize(
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int sourceChannels,
const unsigned int targetWidth,
const unsigned int targetHeight,
const double testDuration,
Worker& worker);
271 static bool testScale(
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int channels,
const unsigned int targetWidth,
const unsigned int targetHeight,
const double xSource_s_xTarget,
const double ySource_s_yTarget,
const double testDuration,
Worker& worker);
297 template <
typename T>
298 static bool testLookup(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
315 template <
typename T>
335 static void validateScaleFrame(
const unsigned char* source,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int channels,
const unsigned char* target,
const unsigned int targetWidth,
const unsigned int targetHeight,
const double xTargetToSource,
const double yTargetToSource,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
double* averageAbsErrorToInteger,
unsigned int* maximalAbsErrorToInteger,
unsigned char* groundTruth =
nullptr);
355 template <
typename T>
356 static void validateScaleFrame(
const T* source,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int channels,
const T* target,
const unsigned int targetWidth,
const unsigned int targetHeight,
const double xSource_s_xTarget,
const double ySource_s_yTarget,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
double* averageAbsError,
double* maximalAbsError, T* groundTruth =
nullptr);
370 template <
typename T>
371 static void validateHomography(
const Frame& input,
const Frame& output,
const SquareMatrix3& input_H_output,
const T* backgroundColor,
const CV::PixelPositionI& interpolatedFrameOrigin,
double* averageAbsError,
double* maximalAbsError,
Frame* groundTruth =
nullptr);
384 static bool testPatchIntensitySum1Channel(
const unsigned int width,
const unsigned int height,
const unsigned int patchWidth,
const unsigned int patchHeight,
const double testDuration);
396 template <
typename TScalar>
411 template <
typename TSource,
typename TTarget,
typename TScalar>
446 template <
typename T>
497 template <u
int32_t tChannels>
498 static bool validatePatchFrame8BitPerChannel(
const uint8_t*
const source,
const uint8_t*
const validationTarget,
const uint32_t sourceWidth,
const uint32_t sourceHeight,
const Scalar x,
const Scalar y,
const uint32_t validationTargetWidth,
const uint32_t validationTargetHeight,
const uint32_t sourcePaddingElements,
const uint32_t validationTargetPaddingElements);
518 static void validateScaleFramePrecision7Bit(
const uint8_t* source,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int channels,
const uint8_t* target,
const unsigned int targetWidth,
const unsigned int targetHeight,
const double xSource_s_xTarget,
const double ySource_s_yTarget,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
double* averageAbsError,
double* maximalAbsError, uint8_t* groundTruth =
nullptr);
522void TestFrameInterpolatorBilinear::validateScaleFrame(
const T* source,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int channels,
const T* target,
const unsigned int targetWidth,
const unsigned int targetHeight,
const double xSource_s_xTarget,
const double ySource_s_yTarget,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
double* averageAbsError,
double* maximalAbsError, T* groundTruth)
524 ocean_assert(source !=
nullptr && target !=
nullptr);
525 ocean_assert(sourceWidth != 0u && sourceHeight != 0u);
526 ocean_assert(targetWidth != 0u && targetHeight != 0u);
527 ocean_assert(channels >= 1u);
528 ocean_assert(xSource_s_xTarget > 0.0 && ySource_s_yTarget > 0.0);
530 const unsigned int sourceStrideElements = sourceWidth * channels + sourcePaddingElements;
531 const unsigned int targetStrideElements = targetWidth * channels + targetPaddingElements;
533 std::vector<T> result(channels, T(0));
545 double sumAbsError = 0.0;
546 double maxAbsError = 0.0;
548 for (
unsigned int y = 0u; y < targetHeight; ++y)
550 for (
unsigned int x = 0u; x < targetWidth; ++x)
552 const double sx =
minmax(0.0, (
double(x) + 0.5) * xSource_s_xTarget - 0.5,
double(sourceWidth - 1u));
553 const double sy =
minmax(0.0, (
double(y) + 0.5) * ySource_s_yTarget - 0.5,
double(sourceHeight - 1u));
555 const unsigned int leftPixel = (
unsigned int)sx;
556 const unsigned int rightPixel = min(leftPixel + 1u, sourceWidth - 1u);
557 ocean_assert(leftPixel < sourceWidth && rightPixel < sourceWidth);
559 const unsigned int topPixel = (
unsigned int)sy;
560 const unsigned int bottomPixel = min(topPixel + 1u, sourceHeight - 1u);
561 ocean_assert(topPixel < sourceHeight && bottomPixel < sourceHeight);
563 const double rightFactor = sx - double(leftPixel);
564 const double bottomFactor = sy - double(topPixel);
566 ocean_assert(rightFactor >= 0.0 && rightFactor <= 1.0);
567 ocean_assert(bottomFactor >= 0.0 && bottomFactor <= 1.0);
569 const double leftFactor = 1.0 - rightFactor;
570 const double topFactor = 1.0 - bottomFactor;
572 const T* sourceTopLeft = source + sourceStrideElements * topPixel + leftPixel * channels;
573 const T* sourceTopRight = source + sourceStrideElements * topPixel + rightPixel * channels;
575 const T* sourceBottomLeft = source + sourceStrideElements * bottomPixel + leftPixel * channels;
576 const T* sourceBottomRight = source + sourceStrideElements * bottomPixel + rightPixel * channels;
578 for (
unsigned int n = 0u; n < channels; ++n)
580 const double top = double(sourceTopLeft[n]) * leftFactor + double(sourceTopRight[n]) * rightFactor;
581 const double bottom = double(sourceBottomLeft[n]) * leftFactor + double(sourceBottomRight[n]) * rightFactor;
583 const double interpolated = top * topFactor + bottom * bottomFactor;
585 result[n] = T(interpolated);
588 const T*
const targetValue = target + targetStrideElements * y + x * channels;
590 for (
unsigned int n = 0u; n < channels; ++n)
592 const double absError =
NumericD::abs(
double(result[n]) -
double(targetValue[n]));
594 sumAbsError += absError;
595 maxAbsError = max(maxAbsError, absError);
600 memcpy(groundTruth + (y * targetWidth + x) * channels, result.data(),
sizeof(T) * channels);
607 *averageAbsError = sumAbsError / double(targetWidth * targetHeight * channels);
612 *maximalAbsError = maxAbsError;
623 ocean_assert(backgroundColor !=
nullptr);
629 const unsigned int channels = input.
channels();
630 ocean_assert(channels >= 1u);
632 std::vector<T> result(channels, T(0));
634 if (averageAbsError !=
nullptr)
639 if (maximalAbsError !=
nullptr)
644 if (groundTruth !=
nullptr)
649 double sumAbsError = 0.0;
650 double maxAbsError = 0.0;
651 unsigned long long measurements = 0ull;
653 for (
unsigned int yOutput = 0u; yOutput < output.
height(); ++yOutput)
655 for (
unsigned int xOutput = 0u; xOutput < output.
width(); ++xOutput)
657 const T*
const outputPixel = output.
constpixel<T>(xOutput, yOutput);
660 const Vector2 inputPosition = input_H_output * outputPosition;
664 const unsigned int inputLeftPixel = (
unsigned int)(inputPosition.
x());
665 const unsigned int inputRightPixel = min(inputLeftPixel + 1u, input.
width() - 1u);
667 const unsigned int inputTopPixel = (
unsigned int)(inputPosition.
y());
668 const unsigned int inputBottomPixel = min(inputTopPixel + 1u, input.
height() - 1u);
670 const double rightFactor = double(inputPosition.
x()) - double(inputLeftPixel);
671 const double bottomFactor = double(inputPosition.
y()) - double(inputTopPixel);
673 ocean_assert(rightFactor >= 0.0 && rightFactor <= 1.0);
674 ocean_assert(bottomFactor >= 0.0 && bottomFactor <= 1.0);
676 const double leftFactor = 1.0 - rightFactor;
677 const double topFactor = 1.0 - bottomFactor;
679 const T*
const inputTopLeft = input.
constpixel<T>(inputLeftPixel, inputTopPixel);
680 const T*
const inputTopRight = input.
constpixel<T>(inputRightPixel, inputTopPixel);
682 const T*
const inputBottomLeft = input.
constpixel<T>(inputLeftPixel, inputBottomPixel);
683 const T*
const inputBottomRight = input.
constpixel<T>(inputRightPixel, inputBottomPixel);
685 for (
unsigned int n = 0u; n < channels; ++n)
687 const double top = double(inputTopLeft[n]) * leftFactor + double(inputTopRight[n]) * rightFactor;
688 const double bottom = double(inputBottomLeft[n]) * leftFactor + double(inputBottomRight[n]) * rightFactor;
690 const double interpolated = top * topFactor + bottom * bottomFactor;
692 result[n] = T(interpolated);
699 for (
unsigned int n = 0u; n < channels; ++n)
701 const double absError =
NumericD::abs(
double(result[n]) -
double(outputPixel[n]));
703 sumAbsError += absError;
704 maxAbsError = max(maxAbsError, absError);
710 if (groundTruth !=
nullptr)
712 memcpy(groundTruth->
pixel<T>(xOutput, yOutput), result.data(),
sizeof(T) * channels);
721 for (
unsigned int n = 0u; n < channels; ++n)
723 const double absError =
NumericD::abs(
double(backgroundColor[n]) -
double(outputPixel[n]));
725 sumAbsError += absError;
726 maxAbsError = max(maxAbsError, absError);
732 if (groundTruth !=
nullptr)
734 memcpy(groundTruth->
pixel<T>(xOutput, yOutput), backgroundColor,
sizeof(T) * channels);
740 ocean_assert(measurements != 0ull || input.
width() <= 2u || input.
height() <= 2u || output.
width() <= 2u || output.
height() <= 2u);
742 if (averageAbsError && measurements != 0ull)
744 *averageAbsError = sumAbsError / double(measurements);
749 *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:1969
const FrameType & frameType() const
Returns the frame type of this frame.
Definition Frame.h:4029
bool isValid() const
Returns whether this frame is valid.
Definition Frame.h:4705
T * pixel(const unsigned int x, const unsigned int y, const unsigned int planeIndex=0u)
Returns the pointer to the data of a specific pixel.
Definition Frame.h:4466
bool set(const FrameType &frameType, const bool forceOwner, const bool forceWritable=false, const Indices32 &planePaddingElements=Indices32(), const Timestamp ×tamp=Timestamp(false), bool *reallocated=nullptr)
Sets a new frame type for this frame.
const T * constpixel(const unsigned int x, const unsigned int y, const unsigned int planeIndex=0u) const
Returns the pointer to the constant data of a specific pixel.
Definition Frame.h:4507
unsigned int width() const
Returns the width of the frame format in pixel.
Definition Frame.h:3334
uint32_t numberPlanes() const
Returns the number of planes of the pixel format of this frame.
Definition Frame.h:3374
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition Frame.h:3344
unsigned int height() const
Returns the height of the frame in pixel.
Definition Frame.h:3339
bool isPixelFormatCompatible(const PixelFormat pixelFormat) const
Returns whether the pixel format of this frame type is compatible with a given pixel format.
Definition Frame.h:3391
unsigned int channels() const
Returns the number of individual channels the frame has.
Definition Frame.h:3364
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 bool isNotEqual(const T first, const T second)
Returns whether two values are not equal up to a small epsilon.
Definition Numeric.h:2622
static constexpr T maxValue()
Returns the max scalar value.
Definition Numeric.h:3253
bool isSingular() const
Returns whether this matrix is singular (and thus cannot be inverted).
Definition SquareMatrix3.h:1342
This class implements a bilinear frame interpolation test.
Definition TestFrameInterpolatorBilinear.h:38
static bool testResampleCameraImage(const double testDuration, Worker &worker)
Tests the function to re-sample a camera image.
static bool testSpecialCasesResize400x400To256x256_8BitPerChannel(const double testDuration)
Tests the special case resize function for image resolutions from 400x400 to 256x256.
static bool testLookup(const double testDuration, Worker &worker)
Tests the frame transformation function applying a lookup table.
static bool testSpecialCasesResize400x400To224x224_8BitPerChannel(const double testDuration)
Tests the special case resize function for image resolutions from 400x400 to 224x224.
static bool testRotateFrame(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the frame rotate function.
static bool validateRotatedFrame(const Frame &source, const Frame &target, const Scalar anchorX, const Scalar anchorY, const Scalar angle)
Validates the rotation of a frame using a bilinear interpolation.
static bool testResize(const double testDuration, Worker &worker)
Tests the bilinear resize function.
static bool testInterpolatePixel(const double testDuration)
Tests the pixel interpolation function for frames with arbitrary data type.
static bool testLookup(const double testDuration, Worker &worker)
Tests the frame transformation function applying a lookup table.
static bool testPatchIntensitySum1Channel(const unsigned int width, const unsigned int height, const unsigned int patchWidth, const unsigned int patchHeight, const double testDuration)
Tests the intensity sum of an image patch with sub-pixel location in a 1-channel frame using an integ...
static bool testInterpolatePixel8BitPerChannel(const CV::PixelCenter pixelCenter, const double testDuration)
Tests the pixel interpolation function for frames with 8 bit per channel.
static bool testResampleCameraImage(const double testDuration, Worker &worker)
Tests the function to re-sample a camera image.
static bool testPatchIntensitySum1Channel(const unsigned int width, const unsigned int height, const double testDuration)
Tests the intensity sum of an image patch with sub-pixel location in a 1-channel frame using an integ...
static bool testScale(const double testDuration, Worker &worker)
Tests the bilinear scale function with scale factors which are not derived from the frame dimensions.
static bool validateInterpolatePixel8BitPerChannel(const Frame &frame, const VectorT2< TScalar > &position, const CV::PixelCenter pixelCenter, const uint8_t *const interpolationResult, const TScalar threshold)
Validates a pixel interpolation result for frame with 8 bit per channel.
static bool testHomography(const double testDuration, Worker &worker)
Tests the homography transformation function supporting arbitrary pixel formats using a constant colo...
static bool testResize(const double testDuration, Worker &worker)
Tests the bilinear resize function supporting arbitrary data types.
static bool testAffine(const double testDuration, Worker &worker)
Tests the affine transformation function using a constant color for unknown image content.
static bool testResize(const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int sourceChannels, const unsigned int targetWidth, const unsigned int targetHeight, const double testDuration, Worker &worker)
Tests the bilinear resize function for arbitrary data types and for a given frame dimension and chann...
static bool testAffine(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the function for affine transformations (with constant color for unknown image content) for a g...
static void validateHomography(const Frame &input, const Frame &output, const SquareMatrix3 &input_H_output, const T *backgroundColor, const CV::PixelPositionI &interpolatedFrameOrigin, double *averageAbsError, double *maximalAbsError, Frame *groundTruth=nullptr)
Validates the homography interpolation function for (almost) arbitrary pixel formats (using a constan...
Definition TestFrameInterpolatorBilinear.h:617
static bool testResizeExtremeResolutions(const double testDuration, Worker &worker)
Tests the bilinear resize function for extreme image resolutions.
static void validateScaleFrame(const unsigned char *source, const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int channels, const unsigned char *target, const unsigned int targetWidth, const unsigned int targetHeight, const double xTargetToSource, const double yTargetToSource, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, double *averageAbsErrorToInteger, unsigned int *maximalAbsErrorToInteger, unsigned char *groundTruth=nullptr)
Validates the bilinear frame resize function.
static bool testLookup(const unsigned int width, const unsigned int height, const unsigned int channels, const double testDuration, Worker &worker)
Tests the frame transformation function applying a lookup table.
static bool validatePatchIntensitySum1Channel(const Frame &yFrame, const unsigned int patchWidth, const unsigned int patchHeight, const Vector2 ¢er, const CV::PixelCenter pixelCenter, const Scalar intensity)
Validate the intensity sum of an image patch with sub-pixel location in a 1-channel frame.
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 bool validateLookup(const Frame &sourceFrame, const Frame &targetFrame, const LookupCorner2< Vector2 > &lookupTable, const bool offset, const T *backgroundColor)
Validates the frame transformation function applying a lookup table.
static bool testInterpolatePixel8BitPerChannel(const double testDuration)
Tests the pixel interpolation function for frames with 8 bit per channel.
static bool testInterpolatePixel(const CV::PixelCenter pixelCenter, const double testDuration)
Tests the pixel interpolation function for frames arbitrary data type.
static bool testLookupMask(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 validateLookupMask(const Frame &sourceFrame, const Frame &targetFrame, const Frame &targetMask, const LookupCorner2< Vector2 > &lookupTable, const bool offset)
Validates the frame mask transformation function applying a lookup table.
static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker, const TestSelector &selector=TestSelector())
Tests all bilinear interpolation filter functions.
static bool testScale(const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int channels, const unsigned int targetWidth, const unsigned int targetHeight, const double xSource_s_xTarget, const double ySource_s_yTarget, const double testDuration, Worker &worker)
Tests the bilinear scale function for a given frame dimension, channel number, and pair of scale fact...
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 testResize(const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int sourceChannels, const unsigned int targetWidth, const unsigned int targetHeight, const double testDuration, Worker &worker)
Tests the bilinear resize function for a given frame dimension and channel number.
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 (with constant color for unknown image content) for arbi...
static bool validateHomographyMask8BitPerChannel(const Frame &frame, const Frame &interpolatedFrame, const Frame &interpolatedMask, const SquareMatrix3 &input_H_output, const CV::PixelPositionI &interpolatedFrameOrigin)
Validates the homography interpolation function (using a binary mask to define known and unknown imag...
static bool validateTransformation8BitPerChannel(const Frame &source, const Frame &validationTarget, const SquareMatrix3 &source_H_target, const uint8_t *backgroundColor, const CV::PixelPositionI &interpolatedFrameOrigin)
Validation function for the bilinear interpolation of 2D homogeneous image transformations (+ constan...
static void validateScaleFramePrecision7Bit(const uint8_t *source, const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int channels, const uint8_t *target, const unsigned int targetWidth, const unsigned int targetHeight, const double xSource_s_xTarget, const double ySource_s_yTarget, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, double *averageAbsError, double *maximalAbsError, uint8_t *groundTruth=nullptr)
Validates the bilinear frame resize function for uint8_t data types using 7-bit integer precision.
static bool validatePatchFrame8BitPerChannel(const uint8_t *const source, const uint8_t *const validationTarget, const uint32_t sourceWidth, const uint32_t sourceHeight, const Scalar x, const Scalar y, const uint32_t validationTargetWidth, const uint32_t validationTargetHeight, const uint32_t sourcePaddingElements, const uint32_t validationTargetPaddingElements)
Validate the bilinear extraction of frame patches.
static bool validateInterpolatePixel(const Frame &frame, const VectorT2< TScalar > &position, const CV::PixelCenter pixelCenter, const TTarget *const interpolationResult, const TScalar threshold)
Validates a pixel interpolation result for frame with arbitrary data type.
This class implements a test selector that parses test function strings and determines which tests sh...
Definition TestSelector.h:51
This class implements a vector with two elements.
Definition Vector2.h:96
const T & x() const noexcept
Returns the x value.
Definition Vector2.h:703
const T & y() const noexcept
Returns the y value.
Definition Vector2.h:715
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
T minmax(const T &lowerBoundary, const T &value, const T &upperBoundary)
This function fits a given parameter into a specified value range.
Definition base/Utilities.h:973
PixelCenter
Definition of individual centers of pixels.
Definition CV.h:117
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