8 #ifndef META_OCEAN_CV_ADVANCED_ADVANCED_FRAME_INTERPOLATOR_BILINEAR_H
9 #define META_OCEAN_CV_ADVANCED_ADVANCED_FRAME_INTERPOLATOR_BILINEAR_H
94 template <
typename TScalar = Scalar>
95 static inline bool interpolatePixelWithMask8BitPerChannel(
const uint8_t* frame,
const uint8_t* mask,
const unsigned int channels,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const PixelCenter pixelCenter,
const VectorT2<TScalar>& position, uint8_t* result, uint8_t& resultMask,
const uint8_t maskValue = 0xFFu);
113 template <
unsigned int tChannels, PixelCenter tPixelCenter = PC_TOP_LEFT,
typename TScalar = Scalar>
114 static inline void interpolatePatch8BitPerChannel(
const uint8_t*
const frame,
const unsigned int width,
const unsigned int framePaddingElements, uint8_t*
const buffer,
const VectorT2<TScalar>& position,
const unsigned int patchWidth,
const unsigned int patchHeight);
127 template <
unsigned int tChannels,
unsigned int tPatchSize, PixelCenter tPixelCenter = PC_TOP_LEFT>
128 static inline void interpolateSquarePatch8BitPerChannel(
const uint8_t*
const frame,
const unsigned int width,
const unsigned int framePaddingElements, uint8_t*
const buffer,
const Vector2& position);
152 template <
unsigned int tChannels, PixelCenter tPixelCenter,
typename TScalar = Scalar>
153 static void interpolatePatchWithMask8BitPerChannel(
const uint8_t* frame,
const uint8_t* mask,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const VectorT2<TScalar>& position, uint8_t* patch, uint8_t* patchMask,
const unsigned int patchWidth,
const unsigned int patchHeight,
const unsigned int patchPaddingElements,
const unsigned int patchMaskPaddingElements,
const uint8_t maskValue = 0xFFu);
167 template <
unsigned int tChannels>
168 static void interpolateSquareMirroredBorder8BitPerChannel(
const uint8_t* frame,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements, uint8_t*
const buffer,
const Vector2& position,
const unsigned int patchSize);
182 template <
unsigned int tChannels,
unsigned int tPatchSize>
183 static void interpolateSquareMirroredBorder8BitPerChannel(
const uint8_t* frame,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements, uint8_t* buffer,
const Vector2& position);
200 template <
unsigned int tChannels>
201 static void interpolateTriangle8BitPerChannel(
const uint8_t* source, uint8_t* target,
const PixelTriangle& sourceTriangle,
const PixelTriangle& targetTriangle,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int targetWidth,
const unsigned int targetHeight,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
218 template <
unsigned int tChannels>
219 static void interpolateTriangle8BitPerChannel(
const uint8_t* source, uint8_t* target,
const Triangle2& sourceTriangle,
const Triangle2& targetTriangle,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int targetWidth,
const unsigned int targetHeight,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker =
nullptr);
261 template <
unsigned int tChannels, PixelCenter tPixelCenter = PC_TOP_LEFT,
typename TScalar = Scalar>
262 static inline void interpolatePixelWithMask8BitPerChannel(
const uint8_t* frame,
const uint8_t* mask,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const VectorT2<TScalar>& position, uint8_t* result, uint8_t& resultMask,
const uint8_t maskValue = 0xFFu);
284 template <
unsigned int tChannels>
285 static void homographyFilterMask8BitPerChannel(
const uint8_t* input,
const uint8_t* outputFilterMask, uint8_t* output,
const unsigned int inputWidth,
const unsigned int inputHeight,
const unsigned int outputWidth,
const unsigned int outputHeight,
const unsigned int inputPaddingElements,
const unsigned int outputFilterMaskPaddingElements,
const unsigned int outputPaddingElements,
const SquareMatrix3& input_H_output,
const PixelBoundingBox& outputBoundingBox =
PixelBoundingBox(),
Worker* worker =
nullptr);
308 template <
unsigned int tChannels>
309 static void interpolateTriangle8BitPerChannelSubset(
const uint8_t* source, uint8_t* target,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int targetWidth,
const unsigned int targetHeight,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
const Triangle2* targetTriangle,
const Triangle2* sourceTriangle,
const PixelLine* targetLine01,
const PixelLine* targetLine02,
const PixelLine* targetLine12,
const unsigned int firstTargetRow,
const unsigned int numberTargetRows);
327 template <
unsigned int tChannels>
328 static void homographyFilterMask8BitPerChannelSubset(
const uint8_t* input,
const uint8_t* outputFilterMask, uint8_t* output,
const unsigned int inputWidth,
const unsigned int inputHeight,
const unsigned int inputPaddingElements,
const unsigned int outputFilterMaskStrideElements,
const unsigned int outputStrideElements,
const SquareMatrix3* input_H_output,
const unsigned int firstOutputColumn,
const unsigned int numberOutputColumns,
const unsigned int firstOutputRow,
const unsigned int numberOutputRows);
331 template <
unsigned int tChannels, PixelCenter tPixelCenter,
typename TScalar>
334 AdvancedFrameInterpolatorBilinearBase::interpolatePatch8BitPerChannel<tChannels, tPixelCenter, TScalar>(frame, width, framePaddingElements, buffer, position, patchWidth, patchHeight);
337 template <
unsigned int tChannels,
unsigned int tPatchSize, PixelCenter tPixelCenter>
340 #if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION >= 41
342 if constexpr (tPatchSize >= 5u)
344 AdvancedFrameInterpolatorBilinearSSE::interpolateSquarePatch8BitPerChannel<tChannels, tPatchSize, tPixelCenter>(frame, width, framePaddingElements, buffer, position);
350 #if defined(OCEAN_HARDWARE_NEON_VERSION) && OCEAN_HARDWARE_NEON_VERSION >= 10
352 if constexpr (tPatchSize >= 5u)
354 AdvancedFrameInterpolatorBilinearNEON::interpolateSquarePatch8BitPerChannel<tChannels, tPatchSize, tPixelCenter>(frame, width, framePaddingElements, buffer, position);
360 AdvancedFrameInterpolatorBilinearBase::interpolateSquarePatch8BitPerChannelTemplate<tChannels, tPatchSize, tPixelCenter>(frame, width, framePaddingElements, buffer, position);
363 template <
unsigned int tChannels, PixelCenter tPixelCenter,
typename TScalar>
364 void AdvancedFrameInterpolatorBilinear::interpolatePatchWithMask8BitPerChannel(
const uint8_t* frame,
const uint8_t* mask,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const VectorT2<TScalar>& position, uint8_t* patch, uint8_t* patchMask,
const unsigned int patchWidth,
const unsigned int patchHeight,
const unsigned int patchPaddingElements,
const unsigned int patchMaskPaddingElements,
const uint8_t maskValue)
366 ocean_assert(frame !=
nullptr && mask !=
nullptr);
367 ocean_assert(patch !=
nullptr && patchMask !=
nullptr);
369 ocean_assert(patchWidth >= 1u && patchHeight >= 1u);
371 const unsigned int patchMaskStrideElements = patchWidth + patchMaskPaddingElements;
373 const TScalar left = position.
x() - TScalar(patchWidth - 1u) * TScalar(0.5);
374 const TScalar top = position.
y() - TScalar(patchHeight - 1u) * TScalar(0.5);
376 for (
unsigned int y = 0u; y < patchHeight; ++y)
378 for (
unsigned int x = 0u; x < patchWidth; ++x)
380 interpolatePixelWithMask8BitPerChannel<tChannels, tPixelCenter, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements,
VectorT2<TScalar>(left + TScalar(x), top + TScalar(y)), patch, patchMask[x], maskValue);
385 patch += patchPaddingElements;
386 patchMask += patchMaskStrideElements;
390 template <
unsigned int tChannels>
393 AdvancedFrameInterpolatorBilinearBase::interpolateSquareMirroredBorder8BitPerChannel<tChannels>(frame, width, height, framePaddingElements, buffer, position, patchSize);
396 template <
unsigned int tChannels,
unsigned int tPatchSize>
399 AdvancedFrameInterpolatorBilinearBase::interpolateSquareMirroredBorderTemplate8BitPerChannel<tChannels, tPatchSize>(frame, width, height, framePaddingElements, buffer, position);
402 template <
typename TScalar>
403 bool AdvancedFrameInterpolatorBilinear::Comfort::interpolatePixelWithMask8BitPerChannel(
const uint8_t* frame,
const uint8_t* mask,
const unsigned int channels,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const PixelCenter pixelCenter,
const VectorT2<TScalar>& position, uint8_t* result, uint8_t& resultMask,
const uint8_t maskValue)
405 ocean_assert(frame !=
nullptr);
406 ocean_assert(mask !=
nullptr);
407 ocean_assert(channels >= 1u && channels <= 8u);
414 AdvancedFrameInterpolatorBilinear::interpolatePixelWithMask8BitPerChannel<1u, PC_TOP_LEFT, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements, position, result, resultMask, maskValue);
418 AdvancedFrameInterpolatorBilinear::interpolatePixelWithMask8BitPerChannel<2u, PC_TOP_LEFT, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements, position, result, resultMask, maskValue);
422 AdvancedFrameInterpolatorBilinear::interpolatePixelWithMask8BitPerChannel<3u, PC_TOP_LEFT, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements, position, result, resultMask, maskValue);
426 AdvancedFrameInterpolatorBilinear::interpolatePixelWithMask8BitPerChannel<4u, PC_TOP_LEFT, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements, position, result, resultMask, maskValue);
430 AdvancedFrameInterpolatorBilinear::interpolatePixelWithMask8BitPerChannel<5u, PC_TOP_LEFT, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements, position, result, resultMask, maskValue);
434 AdvancedFrameInterpolatorBilinear::interpolatePixelWithMask8BitPerChannel<6u, PC_TOP_LEFT, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements, position, result, resultMask, maskValue);
438 AdvancedFrameInterpolatorBilinear::interpolatePixelWithMask8BitPerChannel<7u, PC_TOP_LEFT, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements, position, result, resultMask, maskValue);
442 AdvancedFrameInterpolatorBilinear::interpolatePixelWithMask8BitPerChannel<8u, PC_TOP_LEFT, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements, position, result, resultMask, maskValue);
453 AdvancedFrameInterpolatorBilinear::interpolatePixelWithMask8BitPerChannel<1u, PC_CENTER, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements, position, result, resultMask, maskValue);
457 AdvancedFrameInterpolatorBilinear::interpolatePixelWithMask8BitPerChannel<2u, PC_CENTER, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements, position, result, resultMask, maskValue);
461 AdvancedFrameInterpolatorBilinear::interpolatePixelWithMask8BitPerChannel<3u, PC_CENTER, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements, position, result, resultMask, maskValue);
465 AdvancedFrameInterpolatorBilinear::interpolatePixelWithMask8BitPerChannel<4u, PC_CENTER, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements, position, result, resultMask, maskValue);
469 AdvancedFrameInterpolatorBilinear::interpolatePixelWithMask8BitPerChannel<5u, PC_CENTER, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements, position, result, resultMask, maskValue);
473 AdvancedFrameInterpolatorBilinear::interpolatePixelWithMask8BitPerChannel<6u, PC_CENTER, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements, position, result, resultMask, maskValue);
477 AdvancedFrameInterpolatorBilinear::interpolatePixelWithMask8BitPerChannel<7u, PC_CENTER, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements, position, result, resultMask, maskValue);
481 AdvancedFrameInterpolatorBilinear::interpolatePixelWithMask8BitPerChannel<8u, PC_CENTER, TScalar>(frame, mask, width, height, framePaddingElements, maskPaddingElements, position, result, resultMask, maskValue);
486 ocean_assert(
false &&
"Invalid channel number");
490 template <
unsigned int tChannels>
491 void AdvancedFrameInterpolatorBilinear::interpolateTriangle8BitPerChannel(
const uint8_t* source, uint8_t* target,
const PixelTriangle& sourceTriangle,
const PixelTriangle& targetTriangle,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int targetWidth,
const unsigned int targetHeight,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker)
493 ocean_assert(source && target);
494 ocean_assert(sourceWidth > 0u && sourceHeight > 0u);
495 ocean_assert(targetWidth > 0u && targetHeight > 0u);
497 ocean_assert(sourceTriangle.
isValid() && targetTriangle.
isValid());
499 const unsigned int targetMinY = targetTriangle.
top();
500 const unsigned int targetMaxY = min(targetTriangle.
bottom(), targetHeight - 1u);
516 worker->
executeFunction(
Worker::Function::createStatic(&interpolateTriangle8BitPerChannelSubset<tChannels>, source, target, sourceWidth, sourceHeight, targetWidth, targetHeight, sourcePaddingElements, targetPaddingElements, &tTriangle, &sTriangle, &targetLine01, &targetLine02, &targetLine12, 0u, 0u), targetMinY, targetMaxY - targetMinY + 1u, 13u, 14u, 20u);
520 interpolateTriangle8BitPerChannelSubset<tChannels>(source, target, sourceWidth, sourceHeight, targetWidth, targetHeight, sourcePaddingElements, targetPaddingElements, &tTriangle, &sTriangle, &targetLine01, &targetLine02, &targetLine12, targetMinY, targetMaxY - targetMinY + 1u);
524 template <
unsigned int tChannels>
525 void AdvancedFrameInterpolatorBilinear::interpolateTriangle8BitPerChannel(
const uint8_t* source, uint8_t* target,
const Triangle2& sourceTriangle,
const Triangle2& targetTriangle,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int targetWidth,
const unsigned int targetHeight,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
Worker* worker)
527 ocean_assert(source && target);
528 ocean_assert(sourceWidth > 0u && sourceHeight > 0u);
529 ocean_assert(targetWidth > 0u && targetHeight > 0u);
531 ocean_assert(sourceTriangle.
isValid() && targetTriangle.
isValid());
533 const PixelTriangle targetPixelTriangle(targetTriangle, targetWidth, targetHeight);
535 const unsigned int targetMinY = min(targetPixelTriangle.
point0().y(), min(targetPixelTriangle.
point1().y(), targetPixelTriangle.
point2().y()));
536 const unsigned int targetMaxY = max(targetPixelTriangle.
point0().y(), max(targetPixelTriangle.
point1().y(), targetPixelTriangle.
point2().y()));
544 worker->
executeFunction(
Worker::Function::createStatic(&interpolateTriangle8BitPerChannelSubset<tChannels>, source, target, sourceWidth, sourceHeight, targetWidth, targetHeight, sourcePaddingElements, targetPaddingElements, &targetTriangle, &sourceTriangle, &targetLine01, &targetLine02, &targetLine12, 0u, 0u), targetMinY, targetMaxY - targetMinY + 1u, 13u, 14u, 20u);
548 interpolateTriangle8BitPerChannelSubset<tChannels>(source, target, sourceWidth, sourceHeight, targetWidth, targetHeight, sourcePaddingElements, targetPaddingElements, &targetTriangle, &sourceTriangle, &targetLine01, &targetLine02, &targetLine12, targetMinY, targetMaxY - targetMinY + 1u);
552 template <
unsigned int tChannels>
553 void AdvancedFrameInterpolatorBilinear::interpolateTriangle8BitPerChannelSubset(
const uint8_t* source, uint8_t* target,
const unsigned int sourceWidth,
const unsigned int sourceHeight,
const unsigned int targetWidth,
const unsigned int targetHeight,
const unsigned int sourcePaddingElements,
const unsigned int targetPaddingElements,
const Triangle2* targetTriangle,
const Triangle2* sourceTriangle,
const PixelLine* targetLine01,
const PixelLine* targetLine02,
const PixelLine* targetLine12,
const unsigned int firstTargetRow,
const unsigned int numberTargetRows)
555 static_assert(tChannels != 0u,
"Invalid data channels!");
557 ocean_assert(source !=
nullptr && target !=
nullptr);
561 const unsigned int targetMaxY = min((
unsigned int)(
Numeric::round32(targetTriangle->
bottom())), targetHeight - 1u);
563 ocean_assert(firstTargetRow >= targetMinY);
564 ocean_assert(firstTargetRow + numberTargetRows <= targetMaxY + 1u);
567 ocean_assert_and_suppress_unused(firstTargetRow + numberTargetRows <= targetHeight, targetHeight);
569 const unsigned int targetStrideElements = targetWidth * tChannels + targetPaddingElements;
571 unsigned int x01, x02, x12;
573 for (
unsigned int y = firstTargetRow; y < firstTargetRow + numberTargetRows; ++y)
575 unsigned int xMin = 0xFFFFFFFF;
576 unsigned int xMax = 0;
580 xMin = min(xMin, x01);
581 xMax = max(xMax, x01);
585 xMin = min(xMin, min(targetLine01->
p0().x(), targetLine01->
p1().x()));
586 xMax = max(xMax, max(targetLine01->
p0().x(), targetLine01->
p1().x()));
592 xMin = min(xMin, x02);
593 xMax = max(xMax, x02);
597 xMin = min(xMin, min(targetLine02->
p0().x(), targetLine02->
p1().x()));
598 xMax = max(xMax, max(targetLine02->
p0().x(), targetLine02->
p1().x()));
604 xMin = min(xMin, x12);
605 xMax = max(xMax, x12);
609 xMin = min(xMin, min(targetLine12->
p0().x(), targetLine12->
p1().x()));
610 xMax = max(xMax, max(targetLine12->
p0().x(), targetLine12->
p1().x()));
614 uint8_t*
const targetRow = target + y * targetStrideElements;
616 for (
unsigned int x = xMin; x <= min(xMax, targetWidth - 1u); ++x)
624 CV::FrameInterpolatorBilinear::interpolatePixel8BitPerChannel<tChannels, CV::PC_TOP_LEFT>(source, sourceWidth, sourceHeight, sourcePaddingElements, clippedPosition, targetRow + tChannels * x);
629 template <
unsigned int tChannels, PixelCenter tPixelCenter,
typename TScalar>
632 static_assert(tChannels != 0u,
"Invalid channel number!");
633 static_assert(tPixelCenter ==
PC_TOP_LEFT || tPixelCenter ==
PC_CENTER,
"Invalid pixel center!");
635 ocean_assert(frame !=
nullptr && mask !=
nullptr);
636 ocean_assert(result !=
nullptr);
637 ocean_assert(width != 0u && height != 0u);
639 const unsigned int frameStrideElements = width * tChannels + framePaddingElements;
640 const unsigned int maskStrideElements = width + maskPaddingElements;
648 if (left < -1 || top < -1 || left >=
int(width) || top >=
int(height))
650 resultMask = 0xFFu - maskValue;
654 const TScalar sFactorRight = shiftedPosition.
x() - TScalar(left);
655 ocean_assert(sFactorRight >= 0 && sFactorRight <= 1);
656 const unsigned int factorRight = (
unsigned int)(sFactorRight * TScalar(128) + TScalar(0.5));
657 const unsigned int factorLeft = 128u - factorRight;
659 const TScalar sFactorBottom = shiftedPosition.
y() - TScalar(top);
660 ocean_assert(sFactorBottom >= 0 && sFactorBottom <= 1);
661 const unsigned int factorBottom = (
unsigned int)(sFactorBottom * TScalar(128) + TScalar(0.5));
662 const unsigned int factorTop = 128u - factorBottom;
664 const unsigned int factorTopLeft = factorTop * factorLeft;
665 const unsigned int factorTopRight = factorTop * factorRight;
666 const unsigned int factorBottomLeft = factorBottom * factorLeft;
667 const unsigned int factorBottomRight = factorBottom * factorRight;
669 const uint8_t* topLeft = frame + top * int(frameStrideElements) + int(tChannels) * left;
670 const uint8_t* maskTopLeft = mask + top * int(maskStrideElements) + left;
672 const uint32_t stateTopLeft = (left >= 0 && top >= 0 && left < int(width) && top < int(height) && maskTopLeft[0] == maskValue) ? 1u : 0u;
673 const uint32_t stateTopRight = (left >= -1 && left < int(width - 1u) && top >= 0 && top < int(height) && maskTopLeft[1] == maskValue) ? 1u : 0u;
674 const uint32_t stateBottomLeft = (left >= 0 && top >= -1 && left < int(width) && top < int(height - 1u) && maskTopLeft[maskStrideElements] == maskValue) ? 1u : 0u;
675 const uint32_t stateBottomRight = (left >= -1 && left < int(width - 1u) && top >= -1 && top < int(height - 1u) && maskTopLeft[maskStrideElements + 1u] == maskValue) ? 1u : 0u;
677 const uint32_t state = stateTopLeft | (stateTopRight << 8u) | (stateBottomLeft << 16u) | (stateBottomRight << 24u);
687 for (
unsigned int n = 0u; n < tChannels; ++n)
689 result[n] = uint8_t((topLeft[n] * factorTopLeft + topLeft[tChannels + n] * factorTopRight
690 + topLeft[frameStrideElements + n] * factorBottomLeft + topLeft[frameStrideElements + tChannels + n] * factorBottomRight + 8192u) >> 14u);
693 resultMask = maskValue;
701 const unsigned int factorSum = factorTopRight + factorBottomLeft + factorBottomRight;
705 resultMask = 0xFFu - maskValue;
709 for (
unsigned int n = 0u; n < tChannels; ++n)
711 result[n] = uint8_t((topLeft[tChannels + n] * factorTopRight
712 + topLeft[frameStrideElements + n] * factorBottomLeft + topLeft[frameStrideElements + tChannels + n] * factorBottomRight + factorSum / 2u) / factorSum);
715 resultMask = maskValue;
723 const unsigned int factorSum = factorTopLeft + factorBottomLeft + factorBottomRight;
727 resultMask = 0xFFu - maskValue;
731 for (
unsigned int n = 0u; n < tChannels; ++n)
733 result[n] = uint8_t((topLeft[n] * factorTopLeft
734 + topLeft[frameStrideElements + n] * factorBottomLeft + topLeft[frameStrideElements + tChannels + n] * factorBottomRight + factorSum / 2u) / factorSum);
737 resultMask = maskValue;
745 const unsigned int factorSum = factorTopLeft + factorTopRight + factorBottomRight;
749 resultMask = 0xFFu - maskValue;
753 for (
unsigned int n = 0u; n < tChannels; ++n)
755 result[n] = uint8_t((topLeft[n] * factorTopLeft + topLeft[tChannels + n] * factorTopRight
756 + topLeft[frameStrideElements + tChannels + n] * factorBottomRight + factorSum / 2u) / factorSum);
759 resultMask = maskValue;
767 const unsigned int factorSum = factorTopLeft + factorTopRight + factorBottomLeft;
771 resultMask = 0xFFu - maskValue;
775 for (
unsigned int n = 0u; n < tChannels; ++n)
777 result[n] = uint8_t((topLeft[n] * factorTopLeft + topLeft[tChannels + n] * factorTopRight
778 + topLeft[frameStrideElements + n] * factorBottomLeft + factorSum / 2u) / factorSum);
781 resultMask = maskValue;
789 const unsigned int factorSum = factorBottomLeft + factorBottomRight;
793 resultMask = 0xFFu - maskValue;
797 for (
unsigned int n = 0u; n < tChannels; ++n)
799 result[n] = uint8_t((topLeft[frameStrideElements + n] * factorBottomLeft + topLeft[frameStrideElements + tChannels + n] * factorBottomRight + factorSum / 2u) / factorSum);
802 resultMask = maskValue;
810 const unsigned int factorSum = factorTopLeft + factorBottomLeft;
814 resultMask = 0xFFu - maskValue;
818 for (
unsigned int n = 0u; n < tChannels; ++n)
820 result[n] = uint8_t((topLeft[n] * factorTopLeft + topLeft[frameStrideElements + n] * factorBottomLeft + factorSum / 2u) / factorSum);
823 resultMask = maskValue;
831 const unsigned int factorSum = factorTopLeft + factorTopRight;
835 resultMask = 0xFF - maskValue;
839 for (
unsigned int n = 0u; n < tChannels; ++n)
841 result[n] = uint8_t((topLeft[n] * factorTopLeft + topLeft[tChannels + n] * factorTopRight + factorSum / 2u) / factorSum);
844 resultMask = maskValue;
852 const unsigned int factorSum = factorTopRight + factorBottomRight;
856 resultMask = 0xFFu - maskValue;
860 for (
unsigned int n = 0u; n < tChannels; ++n)
862 result[n] = uint8_t((topLeft[tChannels + n] * factorTopRight
863 + topLeft[frameStrideElements + tChannels + n] * factorBottomRight + factorSum / 2u) / factorSum);
866 resultMask = maskValue;
874 const unsigned int factorSum = factorTopRight + factorBottomLeft;
878 resultMask = 0xFFu - maskValue;
882 for (
unsigned int n = 0u; n < tChannels; ++n)
884 result[n] = uint8_t((topLeft[tChannels + n] * factorTopRight
885 + topLeft[frameStrideElements + n] * factorBottomLeft + factorSum / 2u) / factorSum);
888 resultMask = maskValue;
896 const unsigned int factorSum = factorTopLeft + factorBottomRight;
900 resultMask = 0xFFu - maskValue;
904 for (
unsigned int n = 0u; n < tChannels; ++n)
906 result[n] = uint8_t((topLeft[n] * factorTopLeft + topLeft[frameStrideElements + tChannels + n] * factorBottomRight + factorSum / 2u) / factorSum);
909 resultMask = maskValue;
917 if (factorBottomRight == 0u)
919 resultMask = 0xFFu - maskValue;
923 *((PixelType*)(result)) = *((
const PixelType*)(topLeft + frameStrideElements) + 1);
924 resultMask = maskValue;
933 if (factorTopLeft== 0u)
935 resultMask = 0xFFu - maskValue;
939 *((PixelType*)(result)) = *((
const PixelType*)(topLeft));
940 resultMask = maskValue;
949 if (factorTopRight == 0u)
951 resultMask = 0xFFu - maskValue;
955 *((PixelType*)(result)) = *((
const PixelType*)(topLeft) + 1);
956 resultMask = maskValue;
965 if (factorBottomLeft == 0u)
967 resultMask = 0xFFu - maskValue;
971 *((PixelType*)(result)) = *((
const PixelType*)(topLeft + frameStrideElements));
972 resultMask = maskValue;
981 resultMask = 0xFFu - maskValue;
986 ocean_assert(
false &&
"Invalid state!");
987 resultMask = 0xFFu - maskValue;
990 template <
unsigned int tChannels>
991 void AdvancedFrameInterpolatorBilinear::homographyFilterMask8BitPerChannel(
const uint8_t* input,
const uint8_t* outputFilterMask, uint8_t* output,
const unsigned int inputWidth,
const unsigned int inputHeight,
const unsigned int outputWidth,
const unsigned int outputHeight,
const unsigned int inputPaddingElements,
const unsigned int outputFilterMaskPaddingElements,
const unsigned int outputPaddingElements,
const SquareMatrix3& input_H_output,
const PixelBoundingBox& outputBoundingBox,
Worker* worker)
993 static_assert(tChannels >= 1u,
"Invalid channel number!");
995 const unsigned int outputFirstColumn = outputBoundingBox ? outputBoundingBox.
left() : 0u;
996 const unsigned int outputNumberColumns = outputBoundingBox ? outputBoundingBox.
width() : outputWidth;
998 const unsigned int outputFirstRow = outputBoundingBox ? outputBoundingBox.
top() : 0u;
999 const unsigned int outputNumberRows = outputBoundingBox ? outputBoundingBox.
height() : outputHeight;
1001 const unsigned int outputFilterMaskStrideElemnets = outputWidth + outputFilterMaskPaddingElements;
1002 const unsigned int outputStrideElements = outputWidth * tChannels + outputPaddingElements;
1006 worker->
executeFunction(
Worker::Function::createStatic(&homographyFilterMask8BitPerChannelSubset<tChannels>, input, outputFilterMask, output, inputWidth, inputHeight, inputPaddingElements, outputFilterMaskStrideElemnets, outputStrideElements, &input_H_output, outputFirstColumn, outputNumberColumns, 0u, 0u), outputFirstRow, outputNumberRows, 11u, 12u, 40u);
1010 homographyFilterMask8BitPerChannelSubset<tChannels>(input, outputFilterMask, output, inputWidth, inputHeight, inputPaddingElements, outputFilterMaskStrideElemnets, outputStrideElements, &input_H_output, outputFirstColumn, outputNumberColumns, outputFirstRow, outputNumberRows);
1014 template <
unsigned int tChannels>
1015 void AdvancedFrameInterpolatorBilinear::homographyFilterMask8BitPerChannelSubset(
const uint8_t* input,
const uint8_t* outputFilterMask, uint8_t* output,
const unsigned int inputWidth,
const unsigned int inputHeight,
const unsigned int inputPaddingElements,
const unsigned int outputFilterMaskStrideElements,
const unsigned int outputStrideElements,
const SquareMatrix3* input_H_output,
const unsigned int firstOutputColumn,
const unsigned int numberOutputColumns,
const unsigned int firstOutputRow,
const unsigned int numberOutputRows)
1017 static_assert(tChannels >= 1u,
"Invalid channel number!");
1019 ocean_assert(input !=
nullptr && outputFilterMask !=
nullptr && output !=
nullptr);
1020 ocean_assert(inputWidth >= 1u && inputHeight >= 1u);
1021 ocean_assert(outputFilterMaskStrideElements >= 1u && outputStrideElements >= tChannels);
1023 outputFilterMask += firstOutputRow * outputFilterMaskStrideElements;
1024 output += firstOutputRow * outputStrideElements;
1029 for (
unsigned int y = firstOutputRow; y < firstOutputRow + numberOutputRows; ++y)
1031 for (
unsigned int x = firstOutputColumn; x < firstOutputColumn + numberOutputColumns; ++x)
1033 if (outputFilterMask[x] != 0xFFu)
1038 CV::FrameInterpolatorBilinear::interpolatePixel8BitPerChannel<tChannels, CV::PC_TOP_LEFT>(input, inputWidth, inputHeight, inputPaddingElements, clampedPosition, output + x * tChannels);
1042 outputFilterMask += outputFilterMaskStrideElements;
1043 output += outputStrideElements;
The following comfort class provides comfortable functions simplifying prototyping applications but a...
Definition: AdvancedFrameInterpolatorBilinear.h:56
static bool interpolatePixelWithMask8BitPerChannel(const uint8_t *frame, const uint8_t *mask, const unsigned int channels, const unsigned int width, const unsigned int height, const unsigned int framePaddingElements, const unsigned int maskPaddingElements, const PixelCenter pixelCenter, const VectorT2< TScalar > &position, uint8_t *result, uint8_t &resultMask, const uint8_t maskValue=0xFFu)
Determines the interpolated pixel values for a given pixel position in an 8 bit per channel frame whi...
Definition: AdvancedFrameInterpolatorBilinear.h:403
static bool homographyFilterMask(const Frame &input, const Frame &outputFilterMask, Frame &output, const SquareMatrix3 &input_H_output, const PixelBoundingBox &outputBoundingBox=PixelBoundingBox(), Worker *worker=nullptr)
Transforms a given input frame into an output frame (with arbitrary frame dimension) by application o...
This class implements an advanced bilinear frame interpolator.
Definition: AdvancedFrameInterpolatorBilinear.h:47
static void interpolateSquarePatch8BitPerChannel(const uint8_t *const frame, const unsigned int width, const unsigned int framePaddingElements, uint8_t *const buffer, const Vector2 &position)
Interpolates the content of a square image patch with sub-pixel accuracy inside a given image and sto...
Definition: AdvancedFrameInterpolatorBilinear.h:338
static void homographyFilterMask8BitPerChannel(const uint8_t *input, const uint8_t *outputFilterMask, uint8_t *output, const unsigned int inputWidth, const unsigned int inputHeight, const unsigned int outputWidth, const unsigned int outputHeight, const unsigned int inputPaddingElements, const unsigned int outputFilterMaskPaddingElements, const unsigned int outputPaddingElements, const SquareMatrix3 &input_H_output, const PixelBoundingBox &outputBoundingBox=PixelBoundingBox(), Worker *worker=nullptr)
Transforms a subset of a given input frame into an output frame (with arbitrary frame dimension) by a...
Definition: AdvancedFrameInterpolatorBilinear.h:991
static void interpolatePixelWithMask8BitPerChannel(const uint8_t *frame, const uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int framePaddingElements, const unsigned int maskPaddingElements, const VectorT2< TScalar > &position, uint8_t *result, uint8_t &resultMask, const uint8_t maskValue=0xFFu)
Determines the interpolated pixel values for a given pixel position in an 8 bit per channel frame whi...
Definition: AdvancedFrameInterpolatorBilinear.h:630
static void interpolatePatchWithMask8BitPerChannel(const uint8_t *frame, const uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int framePaddingElements, const unsigned int maskPaddingElements, const VectorT2< TScalar > &position, uint8_t *patch, uint8_t *patchMask, const unsigned int patchWidth, const unsigned int patchHeight, const unsigned int patchPaddingElements, const unsigned int patchMaskPaddingElements, const uint8_t maskValue=0xFFu)
Interpolates the content of an image patch with sub-pixel accuracy inside a given image and stores th...
Definition: AdvancedFrameInterpolatorBilinear.h:364
static bool interpolateTriangle(const Frame &source, Frame &target, const Triangle2 &sourceTriangle, const Triangle2 &targetTriangle, Worker *worker=nullptr)
Interpolates the content of a triangle to another triangle.
static void interpolateSquareMirroredBorder8BitPerChannel(const uint8_t *frame, const unsigned int width, const unsigned int height, const unsigned int framePaddingElements, uint8_t *const buffer, const Vector2 &position, const unsigned int patchSize)
Interpolates the content of a square image patch with sub-pixel accuracy inside a given image and sto...
Definition: AdvancedFrameInterpolatorBilinear.h:391
static void interpolateTriangle8BitPerChannelSubset(const uint8_t *source, uint8_t *target, const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int targetWidth, const unsigned int targetHeight, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, const Triangle2 *targetTriangle, const Triangle2 *sourceTriangle, const PixelLine *targetLine01, const PixelLine *targetLine02, const PixelLine *targetLine12, const unsigned int firstTargetRow, const unsigned int numberTargetRows)
Interpolates the subset of a content of a triangle.
Definition: AdvancedFrameInterpolatorBilinear.h:553
static bool interpolateTriangle(const Frame &source, Frame &target, const PixelTriangle &sourceTriangle, const PixelTriangle &targetTriangle, Worker *worker=nullptr)
Interpolates the content of a triangle to another triangle.
static void interpolateTriangle8BitPerChannel(const uint8_t *source, uint8_t *target, const PixelTriangle &sourceTriangle, const PixelTriangle &targetTriangle, const unsigned int sourceWidth, const unsigned int sourceHeight, const unsigned int targetWidth, const unsigned int targetHeight, const unsigned int sourcePaddingElements, const unsigned int targetPaddingElements, Worker *worker=nullptr)
Interpolates the content of a source triangle to target triangle.
Definition: AdvancedFrameInterpolatorBilinear.h:491
static void homographyFilterMask8BitPerChannelSubset(const uint8_t *input, const uint8_t *outputFilterMask, uint8_t *output, const unsigned int inputWidth, const unsigned int inputHeight, const unsigned int inputPaddingElements, const unsigned int outputFilterMaskStrideElements, const unsigned int outputStrideElements, const SquareMatrix3 *input_H_output, const unsigned int firstOutputColumn, const unsigned int numberOutputColumns, const unsigned int firstOutputRow, const unsigned int numberOutputRows)
Transforms a subset of a given input frame into an output frame (with arbitrary frame dimension) by a...
Definition: AdvancedFrameInterpolatorBilinear.h:1015
static void interpolatePatch8BitPerChannel(const uint8_t *const frame, const unsigned int width, const unsigned int framePaddingElements, uint8_t *const buffer, const VectorT2< TScalar > &position, const unsigned int patchWidth, const unsigned int patchHeight)
Interpolates the content of an image patch with sub-pixel accuracy inside a given image and stores th...
Definition: AdvancedFrameInterpolatorBilinear.h:332
This class implements a 2D line with pixel precision.
Definition: PixelLine.h:65
bool isHorizontal() const
Returns whether this line is horizontal.
Definition: PixelLine.h:215
const PixelPositionT< T > & p0() const
Returns the first end point of this line.
Definition: PixelLine.h:203
const PixelPositionT< T > & p1() const
Returns the second end point of this line.
Definition: PixelLine.h:209
bool horizontalIntersection(const T y, T &x) const
Calculates the intersection between this line and a horizontal scan line.
Definition: PixelLine.h:236
This class implements a 2D triangle with pixel precision.
Definition: PixelTriangle.h:70
const PixelPositionT< T > & point1() const
Returns the second corner point of this triangle.
Definition: PixelTriangle.h:233
T bottom() const
Returns the most bottom (including) position of this triangle.
Definition: PixelTriangle.h:266
const PixelPositionT< T > & point0() const
Returns the first corner point of this triangle.
Definition: PixelTriangle.h:227
const PixelPositionT< T > & point2() const
Returns the third corner point of this triangle.
Definition: PixelTriangle.h:239
T top() const
Returns the most top (including) position of this triangle.
Definition: PixelTriangle.h:252
bool isValid() const
Returns whether this triangle holds three valid corner points.
Definition: PixelTriangle.h:273
T left() const
Returns the left (including) pixel position of this bounding box.
Definition: PixelBoundingBox.h:416
unsigned int width() const
Returns the width (the number of horizontal including pixels) of this bounding box.
Definition: PixelBoundingBox.h:482
T top() const
Returns the top (including) pixel position of this bounding box.
Definition: PixelBoundingBox.h:423
unsigned int height() const
Returns the height (the number of vertical including pixels) of this bounding box.
Definition: PixelBoundingBox.h:489
static Caller< void > createStatic(typename StaticFunctionPointerMaker< void, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass >::Type function)
Creates a new caller container for a static function with no function parameter.
Definition: Caller.h:2876
Template class allowing to define an array of data types.
Definition: DataType.h:27
This class implements Ocean's image class.
Definition: Frame.h:1792
This class provides basic numeric functionalities.
Definition: Numeric.h:57
static constexpr int32_t round32(const T value)
Returns the rounded 32 bit integer value of a given value.
Definition: Numeric.h:2064
This class implements a 2D triangle with Cartesian coordinates.
Definition: Triangle2.h:81
VectorT3< T > cartesian2barycentric(const VectorT2< T > &cartesian) const
Returns the barycentric coordinate of a given 2D Cartesian coordinate defined in relation to this tri...
Definition: Triangle2.h:767
VectorT2< T > barycentric2cartesian(const VectorT3< T > &barycentric) const
Returns the 2D Cartesian coordinate of a given barycentric coordinate defined in relation to this tri...
Definition: Triangle2.h:758
T top() const
Returns the most top position of this triangle.
Definition: Triangle2.h:446
bool isValid() const
Returns whether this triangle can provide valid barycentric coordinates (for 64 bit floating point va...
Definition: Triangle2.h:806
T bottom() const
Returns the most bottom position of this triangle.
Definition: Triangle2.h:460
static bool isValidBarycentric(const VectorT3< T > &barycentric, const T &epsilon=NumericT< T >::eps())
Returns whether the a barycentric coordinate is valid.
Definition: Triangle.h:77
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
bool executeFunction(const Function &function, const unsigned int first, const unsigned int size, const unsigned int firstIndex=(unsigned int)(-1), const unsigned int sizeIndex=(unsigned int)(-1), const unsigned int minimalIterations=1u, const unsigned int threadIndex=(unsigned int)(-1))
Executes a callback function separable by two function parameters.
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
PixelBoundingBoxT< unsigned int > PixelBoundingBox
Definition of the default PixelBoundingBox object with data type allowing only positive coordinate va...
Definition: PixelBoundingBox.h:21
@ PC_TOP_LEFT
The center of a pixel is in the upper-left corner of each pixel's square.
Definition: CV.h:133
@ PC_CENTER
The center of a pixel is located in the center of each pixel's square (with an offset of 0....
Definition: CV.h:150
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