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>
155 template <
typename T>
166 static bool testLookupMask(
const unsigned int width,
const unsigned int height,
const double testDuration,
Worker& worker);
176 static bool testRotateFrame(
const unsigned int width,
const unsigned int height,
const double testDuration,
Worker& worker);
196 static bool testAffine(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
208 template <
typename T>
209 static bool testHomography(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
220 static bool testHomographyMask(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
233 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);
247 template <
typename T>
248 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);
274 template <
typename T>
275 static bool testLookup(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
292 template <
typename T>
312 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);
332 template <
typename T>
333 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);
347 template <
typename T>
348 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);
361 static bool testPatchIntensitySum1Channel(
const unsigned int width,
const unsigned int height,
const unsigned int patchWidth,
const unsigned int patchHeight,
const double testDuration);
373 template <
typename TScalar>
388 template <
typename TSource,
typename TTarget,
typename TScalar>
423 template <
typename T>
474 template <u
int32_t tChannels>
475 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);
495 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);
499void 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)
501 ocean_assert(source !=
nullptr && target !=
nullptr);
502 ocean_assert(sourceWidth != 0u && sourceHeight != 0u);
503 ocean_assert(targetWidth != 0u && targetHeight != 0u);
504 ocean_assert(channels >= 1u);
505 ocean_assert(xSource_s_xTarget > 0.0 && ySource_s_yTarget > 0.0);
507 const unsigned int sourceStrideElements = sourceWidth * channels + sourcePaddingElements;
508 const unsigned int targetStrideElements = targetWidth * channels + targetPaddingElements;
510 std::vector<T> result(channels, T(0));
522 double sumAbsError = 0.0;
523 double maxAbsError = 0.0;
525 for (
unsigned int y = 0u; y < targetHeight; ++y)
527 for (
unsigned int x = 0u; x < targetWidth; ++x)
529 const double sx =
minmax(0.0, (
double(x) + 0.5) * xSource_s_xTarget - 0.5,
double(sourceWidth - 1u));
530 const double sy =
minmax(0.0, (
double(y) + 0.5) * ySource_s_yTarget - 0.5,
double(sourceHeight - 1u));
532 const unsigned int leftPixel = (
unsigned int)sx;
533 const unsigned int rightPixel = min(leftPixel + 1u, sourceWidth - 1u);
534 ocean_assert(leftPixel < sourceWidth && rightPixel < sourceWidth);
536 const unsigned int topPixel = (
unsigned int)sy;
537 const unsigned int bottomPixel = min(topPixel + 1u, sourceHeight - 1u);
538 ocean_assert(topPixel < sourceHeight && bottomPixel < sourceHeight);
540 const double rightFactor = sx - double(leftPixel);
541 const double bottomFactor = sy - double(topPixel);
543 ocean_assert(rightFactor >= 0.0 && rightFactor <= 1.0);
544 ocean_assert(bottomFactor >= 0.0 && bottomFactor <= 1.0);
546 const double leftFactor = 1.0 - rightFactor;
547 const double topFactor = 1.0 - bottomFactor;
549 const T* sourceTopLeft = source + sourceStrideElements * topPixel + leftPixel * channels;
550 const T* sourceTopRight = source + sourceStrideElements * topPixel + rightPixel * channels;
552 const T* sourceBottomLeft = source + sourceStrideElements * bottomPixel + leftPixel * channels;
553 const T* sourceBottomRight = source + sourceStrideElements * bottomPixel + rightPixel * channels;
555 for (
unsigned int n = 0u; n < channels; ++n)
557 const double top = double(sourceTopLeft[n]) * leftFactor + double(sourceTopRight[n]) * rightFactor;
558 const double bottom = double(sourceBottomLeft[n]) * leftFactor + double(sourceBottomRight[n]) * rightFactor;
560 const double interpolated = top * topFactor + bottom * bottomFactor;
562 result[n] = T(interpolated);
565 const T*
const targetValue = target + targetStrideElements * y + x * channels;
567 for (
unsigned int n = 0u; n < channels; ++n)
569 const double absError =
NumericD::abs(
double(result[n]) -
double(targetValue[n]));
571 sumAbsError += absError;
572 maxAbsError = max(maxAbsError, absError);
577 memcpy(groundTruth + (y * targetWidth + x) * channels, result.data(),
sizeof(T) * channels);
584 *averageAbsError = sumAbsError / double(targetWidth * targetHeight * channels);
589 *maximalAbsError = maxAbsError;
600 ocean_assert(backgroundColor !=
nullptr);
606 const unsigned int channels = input.
channels();
607 ocean_assert(channels >= 1u);
609 std::vector<T> result(channels, T(0));
611 if (averageAbsError !=
nullptr)
616 if (maximalAbsError !=
nullptr)
621 if (groundTruth !=
nullptr)
626 double sumAbsError = 0.0;
627 double maxAbsError = 0.0;
628 unsigned long long measurements = 0ull;
630 for (
unsigned int yOutput = 0u; yOutput < output.
height(); ++yOutput)
632 for (
unsigned int xOutput = 0u; xOutput < output.
width(); ++xOutput)
634 const T*
const outputPixel = output.
constpixel<T>(xOutput, yOutput);
637 const Vector2 inputPosition = input_H_output * outputPosition;
641 const unsigned int inputLeftPixel = (
unsigned int)(inputPosition.
x());
642 const unsigned int inputRightPixel = min(inputLeftPixel + 1u, input.
width() - 1u);
644 const unsigned int inputTopPixel = (
unsigned int)(inputPosition.
y());
645 const unsigned int inputBottomPixel = min(inputTopPixel + 1u, input.
height() - 1u);
647 const double rightFactor = double(inputPosition.
x()) - double(inputLeftPixel);
648 const double bottomFactor = double(inputPosition.
y()) - double(inputTopPixel);
650 ocean_assert(rightFactor >= 0.0 && rightFactor <= 1.0);
651 ocean_assert(bottomFactor >= 0.0 && bottomFactor <= 1.0);
653 const double leftFactor = 1.0 - rightFactor;
654 const double topFactor = 1.0 - bottomFactor;
656 const T*
const inputTopLeft = input.
constpixel<T>(inputLeftPixel, inputTopPixel);
657 const T*
const inputTopRight = input.
constpixel<T>(inputRightPixel, inputTopPixel);
659 const T*
const inputBottomLeft = input.
constpixel<T>(inputLeftPixel, inputBottomPixel);
660 const T*
const inputBottomRight = input.
constpixel<T>(inputRightPixel, inputBottomPixel);
662 for (
unsigned int n = 0u; n < channels; ++n)
664 const double top = double(inputTopLeft[n]) * leftFactor + double(inputTopRight[n]) * rightFactor;
665 const double bottom = double(inputBottomLeft[n]) * leftFactor + double(inputBottomRight[n]) * rightFactor;
667 const double interpolated = top * topFactor + bottom * bottomFactor;
669 result[n] = T(interpolated);
676 for (
unsigned int n = 0u; n < channels; ++n)
678 const double absError =
NumericD::abs(
double(result[n]) -
double(outputPixel[n]));
680 sumAbsError += absError;
681 maxAbsError = max(maxAbsError, absError);
687 if (groundTruth !=
nullptr)
689 memcpy(groundTruth->
pixel<T>(xOutput, yOutput), result.data(),
sizeof(T) * channels);
698 for (
unsigned int n = 0u; n < channels; ++n)
700 const double absError =
NumericD::abs(
double(backgroundColor[n]) -
double(outputPixel[n]));
702 sumAbsError += absError;
703 maxAbsError = max(maxAbsError, absError);
709 if (groundTruth !=
nullptr)
711 memcpy(groundTruth->
pixel<T>(xOutput, yOutput), backgroundColor,
sizeof(T) * channels);
717 ocean_assert(measurements != 0ull || input.
width() <= 2u || input.
height() <= 2u || output.
width() <= 2u || output.
height() <= 2u);
719 if (averageAbsError && measurements != 0ull)
721 *averageAbsError = sumAbsError / double(measurements);
726 *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
const FrameType & frameType() const
Returns the frame type of this frame.
Definition Frame.h:3936
bool isValid() const
Returns whether this frame is valid.
Definition Frame.h:4612
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:4373
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:4414
unsigned int width() const
Returns the width of the frame format in pixel.
Definition Frame.h:3241
uint32_t numberPlanes() const
Returns the number of planes of the pixel format of this frame.
Definition Frame.h:3281
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition Frame.h:3251
unsigned int height() const
Returns the height of the frame in pixel.
Definition Frame.h:3246
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:3298
unsigned int channels() const
Returns the number of individual channels the frame has.
Definition Frame.h:3271
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 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:594
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 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: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
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