8 #ifndef META_OCEAN_TEST_TESTCV_TEST_FRAME_INTERPOLATOR_BILINEAR_H
9 #define META_OCEAN_TEST_TESTCV_TEST_FRAME_INTERPOLATOR_BILINEAR_H
47 static bool test(
const unsigned int width,
const unsigned int height,
const double testDuration,
Worker& worker);
63 template <
typename TScalar>
82 template <
typename TSource,
typename TTarget,
typename TScalar>
100 template <
typename T>
134 template <
typename T>
152 template <
typename T>
163 static bool testLookupMask(
const unsigned int width,
const unsigned int height,
const double testDuration,
Worker& worker);
173 static bool testRotateFrame(
const unsigned int width,
const unsigned int height,
const double testDuration,
Worker& worker);
193 static bool testAffine(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
205 template <
typename T>
206 static bool testHomography(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
217 static bool testHomographyMask(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
230 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);
244 template <
typename T>
245 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 template <
typename T>
272 static bool testLookup(
const unsigned int width,
const unsigned int height,
const unsigned int channels,
const double testDuration,
Worker& worker);
289 template <
typename T>
309 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);
329 template <
typename T>
330 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);
344 template <
typename T>
345 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);
358 static bool testPatchIntensitySum1Channel(
const unsigned int width,
const unsigned int height,
const unsigned int patchWidth,
const unsigned int patchHeight,
const double testDuration);
370 template <
typename TScalar>
385 template <
typename TSource,
typename TTarget,
typename TScalar>
420 template <
typename T>
471 template <u
int32_t tChannels>
472 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);
492 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);
495 template <
typename T>
496 void 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)
498 ocean_assert(source !=
nullptr && target !=
nullptr);
499 ocean_assert(sourceWidth != 0u && sourceHeight != 0u);
500 ocean_assert(targetWidth != 0u && targetHeight != 0u);
501 ocean_assert(channels >= 1u);
502 ocean_assert(xSource_s_xTarget > 0.0 && ySource_s_yTarget > 0.0);
504 const unsigned int sourceStrideElements = sourceWidth * channels + sourcePaddingElements;
505 const unsigned int targetStrideElements = targetWidth * channels + targetPaddingElements;
507 std::vector<T> result(channels, T(0));
519 double sumAbsError = 0.0;
520 double maxAbsError = 0.0;
522 for (
unsigned int y = 0u; y < targetHeight; ++y)
524 for (
unsigned int x = 0u; x < targetWidth; ++x)
526 const double sx =
minmax(0.0, (
double(x) + 0.5) * xSource_s_xTarget - 0.5,
double(sourceWidth - 1u));
527 const double sy =
minmax(0.0, (
double(y) + 0.5) * ySource_s_yTarget - 0.5,
double(sourceHeight - 1u));
529 const unsigned int leftPixel = (
unsigned int)sx;
530 const unsigned int rightPixel = min(leftPixel + 1u, sourceWidth - 1u);
531 ocean_assert(leftPixel < sourceWidth && rightPixel < sourceWidth);
533 const unsigned int topPixel = (
unsigned int)sy;
534 const unsigned int bottomPixel = min(topPixel + 1u, sourceHeight - 1u);
535 ocean_assert(topPixel < sourceHeight && bottomPixel < sourceHeight);
537 const double rightFactor = sx - double(leftPixel);
538 const double bottomFactor = sy - double(topPixel);
540 ocean_assert(rightFactor >= 0.0 && rightFactor <= 1.0);
541 ocean_assert(bottomFactor >= 0.0 && bottomFactor <= 1.0);
543 const double leftFactor = 1.0 - rightFactor;
544 const double topFactor = 1.0 - bottomFactor;
546 const T* sourceTopLeft = source + sourceStrideElements * topPixel + leftPixel * channels;
547 const T* sourceTopRight = source + sourceStrideElements * topPixel + rightPixel * channels;
549 const T* sourceBottomLeft = source + sourceStrideElements * bottomPixel + leftPixel * channels;
550 const T* sourceBottomRight = source + sourceStrideElements * bottomPixel + rightPixel * channels;
552 for (
unsigned int n = 0u; n < channels; ++n)
554 const double top = double(sourceTopLeft[n]) * leftFactor + double(sourceTopRight[n]) * rightFactor;
555 const double bottom = double(sourceBottomLeft[n]) * leftFactor + double(sourceBottomRight[n]) * rightFactor;
557 const double interpolated = top * topFactor + bottom * bottomFactor;
559 result[n] = T(interpolated);
562 const T*
const targetValue = target + targetStrideElements * y + x * channels;
564 for (
unsigned int n = 0u; n < channels; ++n)
566 const double absError =
NumericD::abs(
double(result[n]) -
double(targetValue[n]));
568 sumAbsError += absError;
569 maxAbsError = max(maxAbsError, absError);
574 memcpy(groundTruth + (y * targetWidth + x) * channels, result.data(),
sizeof(T) * channels);
581 *averageAbsError = sumAbsError / double(targetWidth * targetHeight * channels);
586 *maximalAbsError = maxAbsError;
590 template <
typename T>
597 ocean_assert(backgroundColor !=
nullptr);
603 const unsigned int channels = input.
channels();
604 ocean_assert(channels >= 1u);
606 std::vector<T> result(channels, T(0));
608 if (averageAbsError !=
nullptr)
613 if (maximalAbsError !=
nullptr)
618 if (groundTruth !=
nullptr)
623 double sumAbsError = 0.0;
624 double maxAbsError = 0.0;
625 unsigned long long measurements = 0ull;
627 for (
unsigned int yOutput = 0u; yOutput < output.
height(); ++yOutput)
629 for (
unsigned int xOutput = 0u; xOutput < output.
width(); ++xOutput)
631 const T*
const outputPixel = output.
constpixel<T>(xOutput, yOutput);
634 const Vector2 inputPosition = input_H_output * outputPosition;
638 const unsigned int inputLeftPixel = (
unsigned int)(inputPosition.
x());
639 const unsigned int inputRightPixel = min(inputLeftPixel + 1u, input.
width() - 1u);
641 const unsigned int inputTopPixel = (
unsigned int)(inputPosition.
y());
642 const unsigned int inputBottomPixel = min(inputTopPixel + 1u, input.
height() - 1u);
644 const double rightFactor = double(inputPosition.
x()) - double(inputLeftPixel);
645 const double bottomFactor = double(inputPosition.
y()) - double(inputTopPixel);
647 ocean_assert(rightFactor >= 0.0 && rightFactor <= 1.0);
648 ocean_assert(bottomFactor >= 0.0 && bottomFactor <= 1.0);
650 const double leftFactor = 1.0 - rightFactor;
651 const double topFactor = 1.0 - bottomFactor;
653 const T*
const inputTopLeft = input.
constpixel<T>(inputLeftPixel, inputTopPixel);
654 const T*
const inputTopRight = input.
constpixel<T>(inputRightPixel, inputTopPixel);
656 const T*
const inputBottomLeft = input.
constpixel<T>(inputLeftPixel, inputBottomPixel);
657 const T*
const inputBottomRight = input.
constpixel<T>(inputRightPixel, inputBottomPixel);
659 for (
unsigned int n = 0u; n < channels; ++n)
661 const double top = double(inputTopLeft[n]) * leftFactor + double(inputTopRight[n]) * rightFactor;
662 const double bottom = double(inputBottomLeft[n]) * leftFactor + double(inputBottomRight[n]) * rightFactor;
664 const double interpolated = top * topFactor + bottom * bottomFactor;
666 result[n] = T(interpolated);
673 for (
unsigned int n = 0u; n < channels; ++n)
675 const double absError =
NumericD::abs(
double(result[n]) -
double(outputPixel[n]));
677 sumAbsError += absError;
678 maxAbsError = max(maxAbsError, absError);
684 if (groundTruth !=
nullptr)
686 memcpy(groundTruth->
pixel<T>(xOutput, yOutput), result.data(),
sizeof(T) * channels);
695 for (
unsigned int n = 0u; n < channels; ++n)
697 const double absError =
NumericD::abs(
double(backgroundColor[n]) -
double(outputPixel[n]));
699 sumAbsError += absError;
700 maxAbsError = max(maxAbsError, absError);
706 if (groundTruth !=
nullptr)
708 memcpy(groundTruth->
pixel<T>(xOutput, yOutput), backgroundColor,
sizeof(T) * channels);
714 ocean_assert(measurements != 0ull || input.
width() <= 2u || input.
height() <= 2u || output.
width() <= 2u || output.
height() <= 2u);
716 if (averageAbsError && measurements != 0ull)
718 *averageAbsError = sumAbsError / double(measurements);
723 *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
const FrameType & frameType() const
Returns the frame type of this frame.
Definition: Frame.h:3775
bool isValid() const
Returns whether this frame is valid.
Definition: Frame.h:4448
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:4209
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:4250
unsigned int width() const
Returns the width of the frame format in pixel.
Definition: Frame.h:3143
uint32_t numberPlanes() const
Returns the number of planes of the pixel format of this frame.
Definition: Frame.h:3183
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition: Frame.h:3153
unsigned int height() const
Returns the height of the frame in pixel.
Definition: Frame.h:3148
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:3198
unsigned int channels() const
Returns the number of individual channels the frame has.
Definition: Frame.h:3173
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:2613
static constexpr T maxValue()
Returns the max scalar value.
Definition: Numeric.h:3244
bool isSingular() const
Returns whether this matrix is singular (and thus cannot be inverted).
Definition: SquareMatrix3.h:1341
This class implements a bilinear frame interpolation test.
Definition: TestFrameInterpolatorBilinear.h:36
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 bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests all bilinear interpolation filter functions.
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:591
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 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 vector with two elements.
Definition: Vector2.h:96
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
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:903
PixelCenter
Definition of individual centers of pixels.
Definition: CV.h:117
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