8 #ifndef META_OCEAN_CV_SYNTHESIS_MAPPING_F_1_H
9 #define META_OCEAN_CV_SYNTHESIS_MAPPING_F_1_H
78 MappingF1(
const unsigned int width,
const unsigned int height);
93 template <
unsigned int tChannels>
94 inline Scalar spatialCost4Neighborhood(
const unsigned int xTarget,
const unsigned int yTarget,
const Scalar xSource,
const Scalar ySource,
const uint8_t* targetMask,
const unsigned int targetMaskPaddingElements,
const Scalar maxCost)
const;
109 template <
unsigned int tChannels>
110 unsigned int appearanceCost5x5(
const unsigned int xTarget,
const unsigned int yTarget,
const Scalar xSource,
const Scalar ySource,
const uint8_t* frame,
const uint8_t* mask,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const unsigned int borderFactor)
const;
127 template <
unsigned int tChannels>
128 inline unsigned int appearanceReferenceCost5x5(
const unsigned int xTarget,
const unsigned int yTarget,
const Scalar xSource,
const Scalar ySource,
const uint8_t* frame,
const uint8_t* mask,
const uint8_t* reference,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const unsigned int referencePaddingElements,
const unsigned int borderFactor)
const;
134 void applyMapping(
Frame& frame,
const Frame& mask,
const unsigned int xStart,
const unsigned int xWidth,
const unsigned int yStart,
const unsigned int yHeight,
Worker* worker =
nullptr)
const override;
150 template <
unsigned int tChannels>
151 inline void applyOneFrameMapping8BitPerChannel(uint8_t*
const frame,
const uint8_t*
const mask,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const unsigned int xStart,
const unsigned int xWidth,
const unsigned int yStart,
const unsigned int yHeight,
Worker* worker =
nullptr)
const;
200 template <
unsigned int tChannels,
unsigned int tPatchSize>
201 static inline unsigned int sumSquareDifferencesThreePatch8BitPerChannel(
const uint8_t* image0,
const uint8_t* image1,
const uint8_t* image2,
const unsigned int width0,
const unsigned int width1,
const unsigned int width2,
unsigned int image0PaddingElements,
const unsigned int image1PaddingElements,
const unsigned int image2PaddingElements,
const unsigned int factor02,
const unsigned int factor12,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int centerX1,
const unsigned int centerY1,
const Scalar centerX2,
const Scalar centerY2);
224 template <
unsigned int tChannels>
225 static inline unsigned int ssd5x5Mask(
const uint8_t* frame0,
const uint8_t* frame1,
const uint8_t* mask0,
const unsigned int width0,
const unsigned int height0,
const unsigned int width1,
const unsigned int height1,
const unsigned int xPosition0,
const unsigned int yPosition0,
const Scalar xPosition1,
const Scalar yPosition1,
const unsigned int frame0PaddingElements,
const unsigned int frame1PaddingElements,
const unsigned int mask0PaddingElements,
const unsigned int borderFactor);
239 inline Scalar spatialCost4Neighborhood(
const unsigned int xTarget,
const unsigned int yTarget,
const Scalar xSource,
const Scalar ySource,
const uint8_t* targetMask,
const unsigned int targetMaskPaddingElements,
const Scalar maxCost)
const;
254 template <
unsigned int tChannels>
255 void applyOneFrameMapping8BitPerChannelSubset(uint8_t*
const frame,
const uint8_t*
const mask,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const unsigned int xStart,
const unsigned int xWidth,
const unsigned int firstRow,
const unsigned int numberRows)
const;
258 template <
unsigned int tChannels>
261 return std::min(
spatialCost4Neighborhood(xTarget, yTarget, xSource, ySource, targetMask, targetMaskPaddingElements, maxCost) *
Scalar(appearanceCostNormalization<tChannels>()), maxCost);
264 template <
unsigned int tChannels>
265 unsigned int MappingF1::appearanceCost5x5(
const unsigned int xTarget,
const unsigned int yTarget,
const Scalar xSource,
const Scalar ySource,
const uint8_t* frame,
const uint8_t* mask,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const unsigned int borderFactor)
const
267 static_assert(tChannels >= 1u,
"Invalid channel number!");
269 ocean_assert(mask !=
nullptr && mask !=
nullptr);
273 ocean_assert(xTarget >= 2u && xTarget <=
width_ - 3u);
274 ocean_assert(yTarget >= 2u && yTarget <=
height_ - 3u);
279 const unsigned int maskStrideElements =
width_ + maskPaddingElements;
282 ocean_assert(mask[yTarget * maskStrideElements + xTarget] != 0xFFu);
289 ocean_assert(mask[ySourceRounded * maskStrideElements + xSourceRounded] == 0xFFu);
292 constexpr
unsigned int patchSize = 5u;
293 constexpr
unsigned int patchSize_2 = patchSize / 2u;
295 constexpr
unsigned int patchArea = patchSize * patchSize;
299 if (mask[yTarget * maskStrideElements + xTarget] == 0x00u || mask[yTarget * maskStrideElements + xTarget] >= 3u)
301 ocean_assert(xTarget >= patchSize_2 && yTarget >= patchSize_2 && xTarget <=
width_ - patchSize_2 - 1u && yTarget <=
height_ - patchSize_2 - 1u);
303 return Advanced::AdvancedSumSquareDifferences::patch8BitPerChannel<tChannels, patchSize>(frame, frame,
width_,
width_, xTarget, yTarget, xSource, ySource, framePaddingElements, framePaddingElements) * spatialCostNormalization<tChannels>() / patchArea;
306 if (xTarget >= patchSize_2 && yTarget >= patchSize_2 && xTarget <=
width_ - patchSize_2 - 1u && yTarget <=
height_ - patchSize_2 - 1u)
308 return ssd5x5Mask<tChannels>(frame, frame, mask,
width_,
height_,
width_,
height_, xTarget, yTarget, xSource, ySource, framePaddingElements, framePaddingElements, maskPaddingElements, borderFactor) * spatialCostNormalization<tChannels>() / patchArea;
312 ocean_assert(
false &&
"This should never happen!");
316 template <
unsigned int tChannels>
317 inline unsigned int MappingF1::appearanceReferenceCost5x5(
const unsigned int xTarget,
const unsigned int yTarget,
const Scalar xSource,
const Scalar ySource,
const uint8_t* frame,
const uint8_t* mask,
const uint8_t* reference,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const unsigned int referencePaddingElements,
const unsigned int borderFactor)
const
319 static_assert(tChannels >= 1u,
"Invalid channel number!");
321 ocean_assert(mask !=
nullptr && mask !=
nullptr && reference !=
nullptr);
325 ocean_assert(xTarget >= 2u && xTarget <=
width_ - 3u);
326 ocean_assert(yTarget >= 2u && yTarget <=
height_ - 3u);
331 const unsigned int maskStrideElements =
width_ + maskPaddingElements;
334 ocean_assert(mask[yTarget * maskStrideElements + xTarget] != 0xFF);
341 ocean_assert(mask[ySourceRounded * maskStrideElements + xSourceRounded] == 0xFFu);
344 constexpr
unsigned int patchSize = 5u;
345 constexpr
unsigned int patchSize_2 = patchSize / 2u;
347 constexpr
unsigned int patchArea = patchSize * patchSize;
351 if (mask[yTarget * maskStrideElements + xTarget] == 0x00u || mask[yTarget * maskStrideElements + xTarget] >= 3u)
353 ocean_assert(xTarget >= patchSize_2 && yTarget >= patchSize_2 && xTarget <=
width_ - patchSize_2 - 1u && yTarget <=
height_ - patchSize_2 - 1u);
355 return sumSquareDifferencesThreePatch8BitPerChannel<tChannels, patchSize>(frame, reference, frame,
width_,
width_,
width_, framePaddingElements, referencePaddingElements, framePaddingElements, 1u, 5u, xTarget, yTarget, xTarget, yTarget, xSource, ySource) * spatialCostNormalization<tChannels>() / patchArea;
358 if (xTarget >= patchSize_2 && yTarget >= patchSize_2 && xTarget <=
width_ - patchSize_2 - 1u && yTarget <=
height_ - patchSize_2 - 1u)
360 return (5u * ssd5x5Mask<tChannels>(reference, frame, mask,
width_,
height_,
width_,
height_, xTarget, yTarget, xSource, ySource, referencePaddingElements, framePaddingElements, maskPaddingElements, borderFactor)
361 + ssd5x5Mask<tChannels>(frame, frame, mask,
width_,
height_,
width_,
height_, xTarget, yTarget, xSource, ySource, framePaddingElements, framePaddingElements, maskPaddingElements, borderFactor)) * spatialCostNormalization<tChannels>() / patchArea;
365 ocean_assert(
false &&
"This should never happen!");
371 ocean_assert(targetMask !=
nullptr);
372 ocean_assert(maxCost >
Scalar(0));
374 const unsigned int targetMaskStrideElements =
width_ + targetMaskPaddingElements;
380 ocean_assert(targetMask[yTarget * targetMaskStrideElements + xTarget] != 0xFF);
384 const uint8_t* targetMaskPointer = targetMask + (int(yTarget) - 1) *
int(targetMaskStrideElements) + xTarget;
388 if (yTarget > 0 && *targetMaskPointer != 0xFF)
390 ocean_assert(mappingPointer->
x() >= 0 && mappingPointer->
x() <
Scalar(
width_));
391 ocean_assert(mappingPointer->
y() >= 0 && mappingPointer->
y() <
Scalar(
height_));
392 ocean_assert(*mappingPointer ==
mappingF_[(yTarget - 1u) *
width_ + xTarget]);
393 ocean_assert(*targetMaskPointer == targetMask[(yTarget - 1u) * targetMaskStrideElements + xTarget]);
397 const Scalar localCost =
sqr(mappingPointer->
x() - xSource) +
sqr(mappingPointer->
y() - ySource + 1);
404 if (localCost < cost)
411 ocean_assert(
width_ >= 1u);
412 targetMaskPointer += targetMaskStrideElements - 1u;
413 mappingPointer +=
width_ - 1u;
416 if (xTarget > 0 && *targetMaskPointer != 0xFF)
418 ocean_assert(mappingPointer->
x() >= 0 && mappingPointer->
x() <
Scalar(
width_));
419 ocean_assert(mappingPointer->
y() >= 0 && mappingPointer->
y() <
Scalar(
height_));
420 ocean_assert(*mappingPointer ==
mappingF_[yTarget *
width_ + xTarget - 1u]);
421 ocean_assert(*targetMaskPointer == targetMask[yTarget * targetMaskStrideElements + xTarget - 1u]);
425 const Scalar localCost =
sqr(mappingPointer->
x() - xSource + 1) +
sqr(mappingPointer->
y() - ySource);
432 if (localCost < cost)
439 targetMaskPointer += 2;
443 if (xTarget + 1 <
width_ && *targetMaskPointer != 0xFF)
445 ocean_assert(mappingPointer->
x() >= 0 && mappingPointer->
x() <
Scalar(
width_));
446 ocean_assert(mappingPointer->
y() >= 0 && mappingPointer->
y() <
Scalar(
height_));
447 ocean_assert(*mappingPointer ==
mappingF_[yTarget *
width_ + xTarget + 1u]);
448 ocean_assert(*targetMaskPointer == targetMask[yTarget * targetMaskStrideElements + xTarget + 1u]);
452 const Scalar localCost =
sqr(mappingPointer->
x() - xSource - 1) +
sqr(mappingPointer->
y() - ySource);
459 if (localCost < cost)
466 targetMaskPointer += targetMaskStrideElements - 1u;
467 mappingPointer +=
width_ - 1u;
470 if (yTarget + 1 <
height_ && *targetMaskPointer != 0xFF)
472 ocean_assert(mappingPointer->
x() >= 0 && mappingPointer->
x() <
Scalar(
width_));
473 ocean_assert(mappingPointer->
y() >= 0 && mappingPointer->
y() <
Scalar(
height_));
474 ocean_assert(*mappingPointer ==
mappingF_[(yTarget + 1u) *
width_ + xTarget]);
475 ocean_assert(*targetMaskPointer == targetMask[(yTarget + 1u) * targetMaskStrideElements + xTarget]);
479 const Scalar localCost =
sqr(mappingPointer->
x() - xSource) +
sqr(mappingPointer->
y() - ySource - 1);
486 if (localCost < cost)
511 template <
unsigned int tChannels>
512 inline unsigned int MappingF1::ssd5x5Mask(
const uint8_t* frame0,
const uint8_t* frame1,
const uint8_t* mask0,
const unsigned int width0,
const unsigned int height0,
const unsigned int width1,
const unsigned int height1,
const unsigned int xPosition0,
const unsigned int yPosition0,
const Scalar xPosition1,
const Scalar yPosition1,
const unsigned int frame0PaddingElements,
const unsigned int frame1PaddingElements,
const unsigned int mask0PaddingElements,
const unsigned int borderFactor)
514 static_assert(tChannels >= 1u,
"Invalid channel number!");
516 ocean_assert(frame0 !=
nullptr && frame1 !=
nullptr && mask0 !=
nullptr);
517 ocean_assert_and_suppress_unused(width0 >= 5u && height0 >= 5u, height0);
518 ocean_assert_and_suppress_unused(width1 >= 6u && height1 >= 6u, height1);
520 ocean_assert(xPosition0 >= 2u && xPosition0 <= width0 - 2u);
521 ocean_assert(yPosition0 >= 2u && yPosition0 <= height0 - 2u);
523 ocean_assert(xPosition1 >=
Scalar(2) && xPosition1 <
Scalar(width1 - 3u));
524 ocean_assert(yPosition1 >=
Scalar(2) && yPosition1 <
Scalar(height1 - 3u));
526 ocean_assert(borderFactor >= 1u);
528 constexpr
unsigned int patchSize = 5u;
529 constexpr
unsigned int patchArea = patchSize * patchSize;
531 constexpr
unsigned int framePatch0PaddingElements = 0u;
532 constexpr
unsigned int maskPatch0PaddingElements = 0u;
534 uint8_t framePatch0[patchArea * tChannels];
535 FrameConverter::patchFrame<uint8_t>(frame0, framePatch0, width0, tChannels, xPosition0, yPosition0, patchSize, frame0PaddingElements, framePatch0PaddingElements);
537 uint8_t maskPatch0[patchArea];
538 FrameConverter::patchFrame<uint8_t>(mask0, maskPatch0, width0, 1u, xPosition0, yPosition0, patchSize, mask0PaddingElements, maskPatch0PaddingElements);
540 uint8_t framePatch1[patchArea * tChannels];
541 Advanced::AdvancedFrameInterpolatorBilinear::interpolateSquarePatch8BitPerChannel<tChannels, patchSize, CV::PC_TOP_LEFT>(frame1, width1, frame1PaddingElements, framePatch1,
Vector2(xPosition1, yPosition1));
543 unsigned int ssd = 0u;
545 for (
unsigned int n = 0u; n < patchArea; ++n)
547 unsigned int ssdLocal = 0u;
549 for (
unsigned int c = 0u; c < tChannels; ++c)
551 const int value = int(framePatch0[n * tChannels + c]) - int(framePatch1[n * tChannels + c]);
552 ssdLocal += value * value;
555 if (maskPatch0[n] == 0xFFu)
557 ssd += ssdLocal * borderFactor;
568 template <
unsigned int tChannels>
569 inline void MappingF1::applyOneFrameMapping8BitPerChannel(uint8_t*
const frame,
const uint8_t*
const mask,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const unsigned int xStart,
const unsigned int xWidth,
const unsigned int yStart,
const unsigned int yHeight,
Worker* worker)
const
571 ocean_assert(frame !=
nullptr && mask !=
nullptr);
573 ocean_assert(xStart + xWidth <=
width_);
574 ocean_assert(yStart + yHeight <=
height_);
578 worker->
executeFunction(
Worker::Function::create(*
this, &MappingF1::applyOneFrameMapping8BitPerChannelSubset<tChannels>, frame, mask, framePaddingElements, maskPaddingElements, xStart, xWidth, 0u, 0u), yStart, yHeight, 6u, 7u, 20u);
582 applyOneFrameMapping8BitPerChannelSubset<tChannels>(frame, mask, framePaddingElements, maskPaddingElements, xStart, xWidth, yStart, yHeight);
586 #if defined(OCEAN_HARDWARE_SSE_VERSION) && OCEAN_HARDWARE_SSE_VERSION >= 41
589 inline unsigned int MappingF1::sumSquareDifferencesThreePatch8BitPerChannel<3u, 5u>(
const uint8_t* image0,
const uint8_t* image1,
const uint8_t* image2,
const unsigned int width0,
const unsigned int width1,
const unsigned int width2,
unsigned int image0PaddingElements,
const unsigned int image1PaddingElements,
const unsigned int image2PaddingElements,
const unsigned int factor02,
const unsigned int factor12,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int centerX1,
const unsigned int centerY1,
const Scalar centerX2,
const Scalar centerY2)
591 constexpr
unsigned int tChannels = 3u;
592 constexpr
unsigned int tPatchSize = 5u;
593 constexpr
unsigned int tPatchSize_2 = tPatchSize / 2u;
595 ocean_assert(image0 !=
nullptr && image1 !=
nullptr && image2 !=
nullptr);
597 ocean_assert(centerX0 >= tPatchSize_2 && centerX0 < width0 - tPatchSize_2);
598 ocean_assert(centerY0 >= tPatchSize_2);
600 ocean_assert(centerX1 >= tPatchSize_2 && centerX1 < width1 - tPatchSize_2);
601 ocean_assert(centerY1 >= tPatchSize_2);
603 ocean_assert(centerX2 >=
Scalar(tPatchSize_2) && centerX2 <
Scalar(width2 - tPatchSize_2 - 1u));
604 ocean_assert(centerY2 >=
Scalar(tPatchSize_2));
606 const unsigned int image0StrideElements = width0 * tChannels + image0PaddingElements;
607 const unsigned int image1StrideElements = width1 * tChannels + image1PaddingElements;
608 const unsigned int image2StrideElements = width2 * tChannels + image2PaddingElements;
610 const uint8_t* imageTopLeft0 = image0 + (centerY0 - tPatchSize_2) * image0StrideElements + (centerX0 - tPatchSize_2) * tChannels;
611 const uint8_t* imageTopLeft1 = image1 + (centerY1 - tPatchSize_2) * image1StrideElements + (centerX1 - tPatchSize_2) * tChannels;
612 const uint8_t* imageTopLeft2 = image2 + ((
unsigned int)(centerY2) - tPatchSize_2) * image2StrideElements + ((
unsigned int)(centerX2) - tPatchSize_2) * tChannels;
614 const Scalar scalarFx2 = centerX2 -
Scalar((
unsigned int)(centerX2));
615 const Scalar scalarFy2 = centerY2 -
Scalar((
unsigned int)(centerY2));
617 ocean_assert(scalarFx2 >= 0 && scalarFx2 <= 1);
618 ocean_assert(scalarFy2 >= 0 && scalarFy2 <= 1);
620 const unsigned int fx2 = (
unsigned int)(
Scalar(128) * scalarFx2 +
Scalar(0.5));
621 const unsigned int fy2 = (
unsigned int)(
Scalar(128) * scalarFy2 +
Scalar(0.5));
633 const unsigned int fx2_ = 128u - fx2;
634 const unsigned int fy2_ = 128u - fy2;
636 const __m128i f2x_y_ = _mm_set1_epi16(
short(fx2_ * fy2_));
637 const __m128i f2xy_ = _mm_set1_epi16(
short(fx2 * fy2_));
638 const __m128i f2x_y = _mm_set1_epi16(
short(fx2_ * fy2));
639 const __m128i f2xy = _mm_set1_epi16(
short(fx2 * fy2));
646 __m128i image0_row0 = _mm_shuffle_epi8(_mm_lddqu_si128((__m128i*)imageTopLeft0),
SSE::set128i(0x0E0D0C0B0A0908A0ull, 0x0706050403020100ull));
648 __m128i image2_row0Front = _mm_lddqu_si128((__m128i*)imageTopLeft2);
649 __m128i image2_row1Front = _mm_lddqu_si128((__m128i*)(imageTopLeft2 + image2StrideElements));
652 __m128i image1_row0 = _mm_shuffle_epi8(_mm_lddqu_si128((__m128i*)imageTopLeft1),
SSE::set128i(0x0E0D0C0B0A0908A0ull, 0x0706050403020100ull));
654 __m128i image2_row0Back = _mm_lddqu_si128((__m128i*)(imageTopLeft2 + 8u));
655 __m128i image2_row1Back = _mm_lddqu_si128((__m128i*)(imageTopLeft2 + image2StrideElements + 8u));
668 __m128i image0_row1 = _mm_shuffle_epi8(_mm_lddqu_si128((__m128i*)(imageTopLeft0 + 1u * image0StrideElements)),
SSE::set128i(0x0E0D0C0B0A0908A0ull, 0x0706050403020100ull));
670 __m128i image2_row2Front = _mm_lddqu_si128((__m128i*)(imageTopLeft2 + 2u * image2StrideElements));
673 __m128i image1_row1 = _mm_shuffle_epi8(_mm_lddqu_si128((__m128i*)(imageTopLeft1 + 1u * image1StrideElements)),
SSE::set128i(0x0E0D0C0B0A0908A0ull, 0x0706050403020100ull));
675 __m128i image2_row2Back = _mm_lddqu_si128((__m128i*)(imageTopLeft2 + 2u * image2StrideElements + 8u));
688 __m128i image0_row2 = _mm_shuffle_epi8(_mm_lddqu_si128((__m128i*)(imageTopLeft0 + 2u * image0StrideElements)),
SSE::set128i(0x0E0D0C0B0A0908A0ull, 0x0706050403020100ull));
690 __m128i image2_row3Front = _mm_lddqu_si128((__m128i*)(imageTopLeft2 + 3u * image2StrideElements));
693 __m128i image1_row2 = _mm_shuffle_epi8(_mm_lddqu_si128((__m128i*)(imageTopLeft1 + 2u * image1StrideElements)),
SSE::set128i(0x0E0D0C0B0A0908A0ull, 0x0706050403020100ull));
695 __m128i image2_row3Back = _mm_lddqu_si128((__m128i*)(imageTopLeft2 + 3u * image2StrideElements + 8u));
707 __m128i image0_row3 = _mm_shuffle_epi8(_mm_lddqu_si128((__m128i*)(imageTopLeft0 + 3u * image0StrideElements)),
SSE::set128i(0x0E0D0C0B0A0908A0ull, 0x0706050403020100ull));
709 __m128i image2_row4Front = _mm_lddqu_si128((__m128i*)(imageTopLeft2 + 4u * image2StrideElements));
712 __m128i image1_row3 = _mm_shuffle_epi8(_mm_lddqu_si128((__m128i*)(imageTopLeft1 + 3u * image1StrideElements)),
SSE::set128i(0x0E0D0C0B0A0908A0ull, 0x0706050403020100ull));
714 __m128i image2_row4Back = _mm_lddqu_si128((__m128i*)(imageTopLeft2 + 4u * image2StrideElements + 8u));
723 __m128i image0_row4 = _mm_shuffle_epi8(_mm_lddqu_si128((__m128i*)(imageTopLeft0 + 4u * image0StrideElements)),
SSE::set128i(0x0E0D0C0B0A0908A0ull, 0x0706050403020100ull));
725 __m128i image2_row5Front = _mm_lddqu_si128((__m128i*)(imageTopLeft2 + 5u * image2StrideElements));
728 __m128i image1_row4 = _mm_shuffle_epi8(_mm_lddqu_si128((__m128i*)(imageTopLeft1 + 4u * image1StrideElements)),
SSE::set128i(0x0E0D0C0B0A0908A0ull, 0x0706050403020100ull));
730 __m128i image2_row5Back = _mm_srli_si128(_mm_lddqu_si128((__m128i*)(imageTopLeft2 + 5u * image2StrideElements + 8u - 6u)), 6);
742 template <
unsigned int tChannels,
unsigned int tPatchSize>
743 inline unsigned int MappingF1::sumSquareDifferencesThreePatch8BitPerChannel(
const uint8_t* image0,
const uint8_t* image1,
const uint8_t* image2,
const unsigned int width0,
const unsigned int width1,
const unsigned int width2,
unsigned int image0PaddingElements,
const unsigned int image1PaddingElements,
const unsigned int image2PaddingElements,
const unsigned int factor02,
const unsigned int factor12,
const unsigned int centerX0,
const unsigned int centerY0,
const unsigned int centerX1,
const unsigned int centerY1,
const Scalar centerX2,
const Scalar centerY2)
745 static_assert(tChannels >= 1u,
"Invalid channel number!");
746 static_assert(tPatchSize >= 1u && tPatchSize % 2u == 1u,
"Invalid channel number!");
748 constexpr
unsigned int tPatchSize_2 = tPatchSize / 2u;
750 ocean_assert(image0 !=
nullptr && image1 !=
nullptr && image2 !=
nullptr);
752 ocean_assert_and_suppress_unused(centerX0 >= tPatchSize_2 && centerX0 < width0 - tPatchSize_2, tPatchSize_2);
753 ocean_assert(centerY0 >= tPatchSize_2);
755 ocean_assert(centerX1 >= tPatchSize_2 && centerX1 < width1 - tPatchSize_2);
756 ocean_assert(centerY1 >= tPatchSize_2);
758 ocean_assert(centerX2 >=
Scalar(tPatchSize_2) && centerX2 <
Scalar(width2 - tPatchSize_2 - 1u));
759 ocean_assert(centerY2 >=
Scalar(tPatchSize_2));
761 uint8_t interpolated2[tPatchSize * tPatchSize * tChannels];
763 CV::Advanced::AdvancedFrameInterpolatorBilinear::interpolateSquarePatch8BitPerChannel<tChannels, tPatchSize>(image2, width2, image2PaddingElements, interpolated2,
Vector2(centerX2, centerY2));
765 return SumSquareDifferencesBase::patchBuffer8BitPerChannelTemplate<tChannels, tPatchSize>(image0, width0, centerX0, centerY0, image0PaddingElements, interpolated2) * factor02
766 + SumSquareDifferencesBase::patchBuffer8BitPerChannelTemplate<tChannels, tPatchSize>(image1, width1, centerX1, centerY1, image1PaddingElements, interpolated2) * factor12;
769 template <
unsigned int tChannels>
770 void MappingF1::applyOneFrameMapping8BitPerChannelSubset(uint8_t*
const frame,
const uint8_t*
const mask,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const unsigned int xStart,
const unsigned int xWidth,
const unsigned int firstRow,
const unsigned int numberRows)
const
772 static_assert(tChannels >= 1u,
"Invalid channels!");
776 ocean_assert(xStart + xWidth <=
width_);
777 ocean_assert(firstRow + numberRows <=
height_);
779 const unsigned int frameStrideElements =
width_ * tChannels + framePaddingElements;
780 const unsigned int maskStrideElements =
width_ + maskPaddingElements;
782 for (
unsigned int y = firstRow; y < firstRow + numberRows; ++y)
784 DataType* framePixel = ((
DataType*)(frame + y * frameStrideElements)) + xStart;
785 const uint8_t* maskPixel = mask + y * maskStrideElements + xStart;
789 for (
unsigned int n = 0u; n < xWidth; ++n)
791 if (*maskPixel != 0xFF)
793 CV::FrameInterpolatorBilinear::interpolatePixel8BitPerChannel<tChannels, CV::PC_TOP_LEFT>(frame,
width_,
height_, framePaddingElements, *mappingPixel, (uint8_t*)(framePixel));
static void prefetchT0(const void *const data)
Prefetches a block of temporal memory into all cache levels.
Definition: SSE.h:1255
static __m128i sumSquareDifference8Bit16Elements(const uint8_t *const image0, const uint8_t *const image1)
Sum square difference determination for 16 elements with 8 bit precision.
Definition: SSE.h:1533
static OCEAN_FORCE_INLINE unsigned int sum_u32_4(const __m128i &value)
Adds the four (all four) individual 32 bit unsigned integer values of a m128i value and returns the r...
Definition: SSE.h:1322
static __m128i set128i(const unsigned long long high64, const unsigned long long low64)
Sets a 128i value by two 64 bit values.
Definition: SSE.h:3770
static __m128i interpolation3Channel24Bit8Elements(const __m128i &values0, const __m128i &values1, const __m128i &fx_fy_, const __m128i &fxfy_, const __m128i &fx_fy, const __m128i &fxfy)
Interpolates 8 elements of 2x2 blocks for 3 channel 24 bit frames.
Definition: SSE.h:1879
Cost function:
Definition: MappingF1.h:52
void applyOneFrameMapping8BitPerChannel(uint8_t *const frame, const uint8_t *const mask, const unsigned int framePaddingElements, const unsigned int maskPaddingElements, const unsigned int xStart, const unsigned int xWidth, const unsigned int yStart, const unsigned int yHeight, Worker *worker=nullptr) const
Applies the current mapping for one given frame.
Definition: MappingF1.h:569
unsigned int appearanceCost5x5(const unsigned int xTarget, const unsigned int yTarget, const Scalar xSource, const Scalar ySource, const uint8_t *frame, const uint8_t *mask, const unsigned int framePaddingElements, const unsigned int maskPaddingElements, const unsigned int borderFactor) const
Calculates the appearance cost for a given point in a given frame.
Definition: MappingF1.h:265
MappingF1(MappingF1 &&mapping) noexcept
Move constructor.
MappingF1 & operator=(const MappingI &right)
Assigns a pixel mapping with float accuracy.
MappingF1()
Creates an empty mapping object.
MappingF1 & operator=(const MappingF1 &right)
Assigns a pixel mapping with float accuracy.
Definition: MappingF1.h:495
unsigned int appearanceReferenceCost5x5(const unsigned int xTarget, const unsigned int yTarget, const Scalar xSource, const Scalar ySource, const uint8_t *frame, const uint8_t *mask, const uint8_t *reference, const unsigned int framePaddingElements, const unsigned int maskPaddingElements, const unsigned int referencePaddingElements, const unsigned int borderFactor) const
Calculates the appearance cost for a given point between two given frames.
Definition: MappingF1.h:317
void applyOneFrameMapping8BitPerChannelSubset(uint8_t *const frame, const uint8_t *const mask, const unsigned int framePaddingElements, const unsigned int maskPaddingElements, const unsigned int xStart, const unsigned int xWidth, const unsigned int firstRow, const unsigned int numberRows) const
Applies the current mapping in a subset of one given frame.
Definition: MappingF1.h:770
Scalar spatialCost4Neighborhood(const unsigned int xTarget, const unsigned int yTarget, const Scalar xSource, const Scalar ySource, const uint8_t *targetMask, const unsigned int targetMaskPaddingElements, const Scalar maxCost) const
Calculates the smallest/cheapest spatial cost for a given point in a four-neighborhood and normalizes...
Definition: MappingF1.h:259
static unsigned int sumSquareDifferencesThreePatch8BitPerChannel(const uint8_t *image0, const uint8_t *image1, const uint8_t *image2, const unsigned int width0, const unsigned int width1, const unsigned int width2, unsigned int image0PaddingElements, const unsigned int image1PaddingElements, const unsigned int image2PaddingElements, const unsigned int factor02, const unsigned int factor12, const unsigned int centerX0, const unsigned int centerY0, const unsigned int centerX1, const unsigned int centerY1, const Scalar centerX2, const Scalar centerY2)
Returns the sum of square differences for a 5x5 block determined between two individual pixel and one...
Definition: MappingF1.h:743
MappingF1(const MappingF1 &pixelMapping)
Copies a mapping from a given mapping object.
MappingF1(const unsigned int width, const unsigned int height)
Creates a new mapping object width defined dimension.
static unsigned int ssd5x5Mask(const uint8_t *frame0, const uint8_t *frame1, const uint8_t *mask0, const unsigned int width0, const unsigned int height0, const unsigned int width1, const unsigned int height1, const unsigned int xPosition0, const unsigned int yPosition0, const Scalar xPosition1, const Scalar yPosition1, const unsigned int frame0PaddingElements, const unsigned int frame1PaddingElements, const unsigned int mask0PaddingElements, const unsigned int borderFactor)
Calculates the sum of square differences between two 5x5 frame regions in two frames with explicit we...
Definition: MappingF1.h:512
void applyMapping(Frame &frame, const Frame &mask, const unsigned int xStart, const unsigned int xWidth, const unsigned int yStart, const unsigned int yHeight, Worker *worker=nullptr) const override
Applies the current mapping for one given frame.
This class implements a mapping with float accuracy.
Definition: MappingF.h:30
Vector2 * mappingF_
Sub-pixel mappings for each pixel.
Definition: MappingF.h:137
MappingF & operator=(const MappingF &mappingObject)
Assign operator.
Definition: MappingF.h:240
unsigned int width_
Width of this pixel mapping object in pixel.
Definition: Mapping.h:147
unsigned int height_
Height of this pixel mapping object in pixel.
Definition: Mapping.h:150
This class implements a mapping with integer accuracy.
Definition: MappingI.h:30
static Caller< void > create(CT &object, typename MemberFunctionPointerMaker< CT, 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 member function with no function parameter.
Definition: Caller.h:3023
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
static constexpr int32_t round32(const T value)
Returns the rounded 32 bit integer value of a given value.
Definition: Numeric.h:2064
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.
unsigned int sqr(const char value)
Returns the square value of a given value.
Definition: base/Utilities.h:1029
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