8 #ifndef META_OCEAN_CV_SEGMENTATION_CONTOUR_MAPPING_H
9 #define META_OCEAN_CV_SEGMENTATION_CONTOUR_MAPPING_H
29 namespace Segmentation
55 template <
unsigned int tChannels>
56 static Indices32 contour2mapping8BitPerChannel(
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 PixelPositions& denseContour);
74 template <
unsigned int tChannels>
75 static void mappingInterpolation8BitPerChannel(uint8_t* frame, uint8_t* mask,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const PixelPositions& denseContour,
const PixelBoundingBox& boundingBox,
const Indices32& mapping);
94 template <
unsigned int tChannels>
95 static Indices32 mappingInitialization8BitPerChannel(
const uint8_t* frame,
const uint8_t* mask,
const uint8_t* outline,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const unsigned int outlinePaddingElements,
const PixelPositions& denseContour,
const unsigned int appearanceThreshold);
111 template <
unsigned int tChannels>
112 static void improveMapping8BitPerChannel(
const uint8_t* frame,
const uint8_t* mask,
const uint8_t* outline,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const unsigned int outlinePaddingElements,
const PixelPositions& denseContour,
Indices32& mapping);
131 template <
unsigned int tChannels>
132 static unsigned int totalForwardCost8BitPerChannel(
const uint8_t* frame,
const uint8_t* mask,
const uint8_t* outline,
const unsigned int width,
const unsigned int height,
const unsigned int frameStrideElements,
const unsigned int maskStrideElements,
const unsigned int outlineStrideElements,
const PixelPositions& denseContour,
const Indices32& mapping,
const unsigned int sourceIndex,
const unsigned int targetIndex,
const bool oneWay);
151 template <
unsigned int tChannels>
152 static unsigned int totalBackwardCost8BitPerChannel(
const uint8_t* frame,
const uint8_t* mask,
const uint8_t* outline,
const unsigned int width,
const unsigned int height,
const unsigned int frameStrideElements,
const unsigned int maskStrideElements,
const unsigned int outlineStrideElements,
const PixelPositions& denseContour,
const Indices32& mapping,
const unsigned int sourceIndex,
const unsigned int targetIndex,
const bool oneWay);
166 template <
unsigned int tChannels>
167 static unsigned int directMappingCostAppearance8BitPerChannelKernel3(
const uint8_t* frame,
const unsigned int width,
const unsigned int height,
const unsigned int frameStrideElements,
const PixelPositions& denseContour,
const unsigned int sourceIndex,
const unsigned int targetIndex);
203 static int distanceInContour(
const unsigned int highIndex,
const unsigned int lowIndex,
const unsigned int size);
218 static bool isLineOutsideMask(
const uint8_t* mask,
const uint8_t* outline,
const unsigned int width,
const unsigned int height,
const unsigned int maskStrideElements,
const unsigned int outlineStrideElements,
const PixelPosition& start,
const PixelPosition& stop);
225 static inline unsigned int sqr(
const int value);
228 template <
unsigned int tChannels>
231 static_assert(tChannels != 0u,
"Invalid channel number!");
233 ocean_assert(frame !=
nullptr && mask !=
nullptr);
234 ocean_assert(width != 0u && height != 0u);
244 ocean_assert(densePixel.x() < width && densePixel.y() < height);
246 outlineFrame.
pixel<uint8_t>(densePixel.x(), densePixel.y())[0] = 0x00;
249 Indices32 mapping(mappingInitialization8BitPerChannel<tChannels>(frame, mask, outlineFrame.
constdata<uint8_t>(), width, height, framePaddingElements, maskPaddingElements, outlineFrame.
paddingElements(), denseContour, tChannels * 35u * 35u));
251 improveMapping8BitPerChannel<tChannels>(frame, mask, outlineFrame.
constdata<uint8_t>(), width, height, framePaddingElements, maskPaddingElements, outlineFrame.
paddingElements(), denseContour, mapping);
256 template <
unsigned int tChannels>
259 static_assert(tChannels != 0u,
"Invalid channel number!");
261 ocean_assert(frame !=
nullptr && mask !=
nullptr);
262 ocean_assert(width != 0u && height != 0u);
263 ocean_assert(denseContour.size() == mapping.size());
264 ocean_assert(boundingBox && boundingBox.
right() < width && boundingBox.
bottom() < height);
266 const unsigned int frameStrideElements = width * tChannels + framePaddingElements;
267 const unsigned int maskStrideElements = width + maskPaddingElements;
271 const unsigned int boundingBoxWidth = boundingBox.
width();
278 uint32_t*
const hole = holeFrame.
data<uint32_t>();
280 const unsigned int maxSqrLength =
sqr(
sqr(width) +
sqr(height));
282 for (
unsigned int n = 0u; n < (
unsigned int)mapping.size(); ++n)
284 const unsigned int sourceIndex = n;
285 const unsigned int targetIndex = mapping[sourceIndex];
288 if (targetIndex >= mapping.size())
293 ocean_assert(sourceIndex < denseContour.size());
294 ocean_assert(targetIndex < denseContour.size());
299 ocean_assert(source.
x() >= boundingBox.
left());
300 ocean_assert(source.
y() >= boundingBox.
top());
301 ocean_assert(target.
x() >= boundingBox.
left());
302 ocean_assert(target.
y() >= boundingBox.
top());
304 const int xSource = int(source.
x() - boundingBox.
left());
305 const int ySource = int(source.
y() - boundingBox.
top());
307 const int xTarget = int(target.
x() - boundingBox.
left());
308 const int yTarget = int(target.
y() - boundingBox.
top());
310 const PixelType sourcePixel = *(
const PixelType*)(frame + source.
y() * frameStrideElements + source.
x() * tChannels);
311 const PixelType targetPixel = *(
const PixelType*)(frame + target.
y() * frameStrideElements + target.
x() * tChannels);
317 unsigned int pixels = 1u;
319 while (x != xTarget || y != yTarget)
333 ocean_assert(maxSqrLength >= sqrLength);
334 const unsigned int weight = maxSqrLength / sqrLength;
336 while (x != xTarget || y != yTarget)
338 ocean_assert(x >= 0 && x <
int(width));
339 ocean_assert(y >= 0 && y <
int(height));
341 if (mask[(y + boundingBox.
top()) * maskStrideElements + x + boundingBox.
left()] == 0x00)
343 const unsigned int t1 = pixels - t;
345 uint32_t* holeLocation = hole + 4u * (y * boundingBoxWidth + x);
347 *holeLocation += weight;
349 for (
unsigned int i = 0u; i < tChannels; ++i)
351 const uint32_t value = uint32_t((((uint8_t*)&sourcePixel)[i] * t1 + ((uint8_t*)&targetPixel)[i] * t) / pixels);
353 holeLocation[i + 1u] += value * weight;
363 for (
unsigned int y = 0u; y < boundingBox.
height(); ++y)
365 const uint32_t * holeLine = hole + 4u * (y * boundingBoxWidth);
367 uint8_t* frameLine = frame + (y + boundingBox.
top()) * frameStrideElements + boundingBox.
left() * tChannels;
368 uint8_t* maskLine = mask + (y + boundingBox.
top()) * maskStrideElements + boundingBox.
left();
370 for (
unsigned int x = 0u; x < boundingBox.
width(); ++x)
374 for (
unsigned int i = 0u; i < tChannels; ++i)
376 frameLine[i] = uint8_t(holeLine[i + 1u] / holeLine[0]);
383 frameLine += tChannels;
389 template <
unsigned int tChannels>
390 Indices32 ContourMapping::mappingInitialization8BitPerChannel(
const uint8_t* frame,
const uint8_t* mask,
const uint8_t* outline,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const unsigned int outlinePaddingElements,
const PixelPositions& denseContour,
const unsigned int appearanceThreshold)
392 static_assert(tChannels != 0u,
"Invalid channel number!");
394 ocean_assert(frame !=
nullptr && mask !=
nullptr && outline !=
nullptr);
395 ocean_assert(width != 0u && height != 0u);
397 const unsigned int contourSize = (
unsigned int)(denseContour.size());
398 ocean_assert(contourSize > 3u);
400 const unsigned int frameStrideElements = width * tChannels + framePaddingElements;
401 const unsigned int maskStrideElements = width + maskPaddingElements;
402 const unsigned int outlineStrideElements = width + outlinePaddingElements;
405 Indices32 mapping(contourSize, (
unsigned int)(-1));
408 for (
unsigned int n = 0u; n < contourSize; ++n)
412 unsigned int minCost = appearanceThreshold;
413 unsigned int minIndex = (
unsigned int)(-1);
415 for (
unsigned int i = 0u; i < contourSize; ++i)
417 if (
ringDistance(n, i, contourSize) > 5u || denseContour[n].sqrDistance(denseContour[i]) > 25u)
421 if (!
isLineOutsideMask(mask, outline, width, height, maskStrideElements, outlineStrideElements, source, target))
423 const unsigned int appearanceCost = directMappingCostAppearance8BitPerChannelKernel3<tChannels>(frame, width, height, frameStrideElements, denseContour, n, i);
425 if (appearanceCost <= appearanceThreshold && appearanceCost < minCost)
427 minCost = appearanceCost;
434 mapping[n] = minIndex;
440 template <
unsigned int tChannels>
441 void ContourMapping::improveMapping8BitPerChannel(
const uint8_t* frame,
const uint8_t* mask,
const uint8_t* outline,
const unsigned int width,
const unsigned int height,
const unsigned int framePaddingElements,
const unsigned int maskPaddingElements,
const unsigned int outlinePaddingElements,
const PixelPositions& denseContour,
Indices32& mapping)
443 static_assert(tChannels != 0u,
"Invalid channel number!");
445 ocean_assert(frame !=
nullptr && mask !=
nullptr && outline !=
nullptr);
446 ocean_assert(width != 0u && height != 0u);
447 ocean_assert(denseContour.size() == mapping.size());
449 const unsigned int frameStrideElements = width * tChannels + framePaddingElements;
450 const unsigned int maskStrideElements = width + maskPaddingElements;
451 const unsigned int outlineStrideElements = width + outlinePaddingElements;
455 const unsigned int contourSize = (
unsigned int)denseContour.size();
457 unsigned int iterations = 0u;
458 unsigned int changedMapping = contourSize;
459 bool firstIteration =
true;
461 while (changedMapping > 5u * contourSize / 100u && iterations < 50u)
467 for (
unsigned int n = 0; n < contourSize + 5u; ++n)
469 const unsigned int sourceIndex = (
unsigned int)
modulo(
int(n), int(contourSize));
470 const unsigned int targetIndexStart = mapping[sourceIndex];
473 unsigned int oldCost = totalForwardCost8BitPerChannel<tChannels>(frame, mask, outline, width, height, frameStrideElements, maskStrideElements, outlineStrideElements, denseContour, mapping, sourceIndex, mapping[sourceIndex], firstIteration);
476 if (oldCost == (
unsigned int)(-1))
478 mapping[sourceIndex] = (
unsigned int)(-1);
483 const unsigned int sourceIndexMinus = (
unsigned int)
modulo(
int(sourceIndex) - 1, int(contourSize));
484 const unsigned int targetIndexMinus = mapping[sourceIndexMinus];
486 if (targetIndexMinus != (
unsigned int)(-1))
490 const unsigned int targetIndexMinusNeighbor = (
unsigned int)
modulo(
int(targetIndexMinus) - 1, int(contourSize));
491 const unsigned int testCost = totalForwardCost8BitPerChannel<tChannels>(frame, mask, outline, width, height, frameStrideElements, maskStrideElements, outlineStrideElements, denseContour, mapping, sourceIndex, targetIndexMinusNeighbor, firstIteration);
492 if (testCost < oldCost)
495 mapping[sourceIndex] = targetIndexMinusNeighbor;
501 const unsigned int testCost = totalForwardCost8BitPerChannel<tChannels>(frame, mask, outline, width, height, frameStrideElements, maskStrideElements, outlineStrideElements, denseContour, mapping, sourceIndex, targetIndexMinus, firstIteration);
502 if (testCost < oldCost)
505 mapping[sourceIndex] = targetIndexMinus;
513 unsigned int minCost = oldCost;
514 unsigned int minTargetIndex = (
unsigned int)(-1);
516 for (
unsigned int i = 0; i < 20u; ++i)
518 const unsigned int testTargetIndex =
RandomI::random(randomGenerator, contourSize - 1u);
519 const unsigned int testCost = totalForwardCost8BitPerChannel<tChannels>(frame, mask, outline, width, height, frameStrideElements, maskStrideElements, outlineStrideElements, denseContour, mapping, sourceIndex, testTargetIndex, firstIteration);
521 if (testCost < minCost)
524 minTargetIndex = testTargetIndex;
528 if (minTargetIndex != (
unsigned int)(-1))
531 mapping[sourceIndex] = minTargetIndex;
537 const unsigned int targetIndex = mapping[sourceIndex];
540 if (targetIndex != (
unsigned int)(-1) && sourceIndex != mapping[targetIndex])
542 const unsigned int oldTargetCost = totalForwardCost8BitPerChannel<tChannels>(frame, mask, outline, width, height, frameStrideElements, maskStrideElements, outlineStrideElements, denseContour, mapping, targetIndex, mapping[targetIndex], firstIteration);
543 const unsigned int testTargetCost = totalForwardCost8BitPerChannel<tChannels>(frame, mask, outline, width, height, frameStrideElements, maskStrideElements, outlineStrideElements, denseContour, mapping, targetIndex, sourceIndex, firstIteration);
545 if (testTargetCost < oldTargetCost)
547 mapping[targetIndex] = sourceIndex;
552 const unsigned int targetIndexEnd = mapping[sourceIndex];
554 if (targetIndexStart != targetIndexEnd)
562 for (
int n = contourSize; n > -5; --n)
564 const unsigned int sourceIndex = (
unsigned int)
modulo(
int(n), int(contourSize));
565 const unsigned int targetIndexStart = mapping[sourceIndex];
568 unsigned int oldCost = totalBackwardCost8BitPerChannel<tChannels>(frame, mask, outline, width, height, frameStrideElements, maskStrideElements, outlineStrideElements, denseContour, mapping, sourceIndex, mapping[sourceIndex], firstIteration);
571 if (oldCost == (
unsigned int)(-1))
573 mapping[sourceIndex] = (
unsigned int)(-1);
578 const unsigned int sourceIndexPlus = (
unsigned int)
modulo(
int(sourceIndex) + 1, int(contourSize));
579 const unsigned int targetIndexPlus = mapping[sourceIndexPlus];
581 if (targetIndexPlus != (
unsigned int)(-1))
585 const unsigned int targetIndexPlusNeighbor = (
unsigned int)
modulo(
int(targetIndexPlus) + 1, int(contourSize));
586 const unsigned int testCost = totalBackwardCost8BitPerChannel<tChannels>(frame, mask, outline, width, height, frameStrideElements, maskStrideElements, outlineStrideElements, denseContour, mapping, sourceIndex, targetIndexPlusNeighbor, firstIteration);
587 if (testCost < oldCost)
590 mapping[sourceIndex] = targetIndexPlusNeighbor;
596 const unsigned int testCost = totalBackwardCost8BitPerChannel<tChannels>(frame, mask, outline, width, height, frameStrideElements, maskStrideElements, outlineStrideElements, denseContour, mapping, sourceIndex, targetIndexPlus, firstIteration);
597 if (testCost < oldCost)
600 mapping[sourceIndex] = targetIndexPlus;
608 unsigned int minCost = oldCost;
609 unsigned int minTargetIndex = (
unsigned int)(-1);
611 for (
unsigned int i = 0; i < 20u; ++i)
613 const unsigned int testTargetIndex =
RandomI::random(randomGenerator, contourSize - 1u);
614 const unsigned int testCost = totalBackwardCost8BitPerChannel<tChannels>(frame, mask, outline, width, height, frameStrideElements, maskStrideElements, outlineStrideElements, denseContour, mapping, sourceIndex, testTargetIndex, firstIteration);
616 if (testCost < minCost)
619 minTargetIndex = testTargetIndex;
623 if (minTargetIndex != (
unsigned int)(-1))
626 mapping[sourceIndex] = minTargetIndex;
632 const unsigned int targetIndex = mapping[sourceIndex];
635 if (targetIndex != (
unsigned int)(-1) && sourceIndex != mapping[targetIndex])
637 const unsigned int oldTargetCost = totalBackwardCost8BitPerChannel<tChannels>(frame, mask, outline, width, height, frameStrideElements, maskStrideElements, outlineStrideElements, denseContour, mapping, targetIndex, mapping[targetIndex], firstIteration);
638 const unsigned int testTargetCost = totalBackwardCost8BitPerChannel<tChannels>(frame, mask, outline, width, height, frameStrideElements, maskStrideElements, outlineStrideElements, denseContour, mapping, targetIndex, sourceIndex, firstIteration);
640 if (testTargetCost < oldTargetCost)
642 mapping[targetIndex] = sourceIndex;
647 const unsigned int targetIndexEnd = mapping[sourceIndex];
649 if (targetIndexStart != targetIndexEnd)
655 firstIteration =
false;
659 template <
unsigned int tChannels>
660 unsigned int ContourMapping::totalForwardCost8BitPerChannel(
const uint8_t* frame,
const uint8_t* mask,
const uint8_t* outline,
const unsigned int width,
const unsigned int height,
const unsigned int frameStrideElements,
const unsigned int maskStrideElements,
const unsigned int outlineStrideElements,
const PixelPositions& denseContour,
const Indices32& mapping,
const unsigned int sourceIndex,
const unsigned int targetIndex,
const bool oneWay)
662 ocean_assert(frame !=
nullptr && mask !=
nullptr && outline !=
nullptr);
663 ocean_assert(width * tChannels < frameStrideElements);
664 ocean_assert(width < maskStrideElements);
665 ocean_assert(width < outlineStrideElements);
667 ocean_assert(sourceIndex != (
unsigned int)(-1));
669 if (targetIndex == (
unsigned int)(-1))
671 return (
unsigned int)(-1);
675 if (
ringDistance(sourceIndex, targetIndex, (
unsigned int)denseContour.size()) <= 5u
676 && denseContour[sourceIndex].sqrDistance(denseContour[targetIndex]) <= 25u)
678 return (
unsigned int)(-1);
682 if (
isLineOutsideMask(mask, outline, width, height, maskStrideElements, outlineStrideElements, denseContour[sourceIndex], denseContour[targetIndex]))
684 return (
unsigned int)(-1);
695 const unsigned int appearanceThreshold = tChannels * 45u * 45u;
697 const unsigned int costAppearance = directMappingCostAppearance8BitPerChannelKernel3<tChannels>(frame, width, height, frameStrideElements, denseContour, sourceIndex, targetIndex);
698 if (costAppearance > appearanceThreshold)
700 return (
unsigned int)(-1);
703 return costAppearance + 100u *
sqr(neighborCost);
706 template <
unsigned int tChannels>
707 unsigned int ContourMapping::totalBackwardCost8BitPerChannel(
const uint8_t* frame,
const uint8_t* mask,
const uint8_t* outline,
const unsigned int width,
const unsigned int height,
const unsigned int frameStrideElements,
const unsigned int maskStrideElements,
const unsigned int outlineStrideElements,
const PixelPositions& denseContour,
const Indices32& mapping,
const unsigned int sourceIndex,
const unsigned int targetIndex,
const bool oneWay)
709 ocean_assert(sourceIndex != (
unsigned int)(-1));
711 if (targetIndex == (
unsigned int)(-1))
713 return (
unsigned int)(-1);
717 if (
ringDistance(sourceIndex, targetIndex, (
unsigned int)denseContour.size()) <= 5u
718 && denseContour[sourceIndex].sqrDistance(denseContour[targetIndex]) <= 25u)
720 return (
unsigned int)(-1);
724 if (
isLineOutsideMask(mask, outline, width, height, maskStrideElements, outlineStrideElements, denseContour[sourceIndex], denseContour[targetIndex]))
726 return (
unsigned int)(-1);
737 const unsigned int appearanceThreshold = tChannels * 45u * 45u;
739 const unsigned int costDirectAppearance = directMappingCostAppearance8BitPerChannelKernel3<tChannels>(frame, width, height, frameStrideElements, denseContour, sourceIndex, targetIndex);
740 if (costDirectAppearance > appearanceThreshold)
742 return (
unsigned int)(-1);
745 return costDirectAppearance + 100u *
sqr(neighborCost);
748 template <
unsigned int tChannels>
751 ocean_assert(frame !=
nullptr);
752 ocean_assert(width != 0u && height != 0u);
753 ocean_assert_and_suppress_unused(width * tChannels <= frameStrideElements, width);
754 ocean_assert(sourceIndex < denseContour.size());
755 ocean_assert(targetIndex < denseContour.size());
757 const unsigned int sourceIndexMinus = (
unsigned int)
modulo(
int(sourceIndex) - 1, int(denseContour.size()));
758 const unsigned int sourceIndexPlus = (
unsigned int)
modulo(
int(sourceIndex) + 1, int(denseContour.size()));
759 ocean_assert(sourceIndexMinus < denseContour.size());
760 ocean_assert(sourceIndexPlus < denseContour.size());
762 const unsigned int targetIndexMinus = (
unsigned int)
modulo(
int(targetIndex) - 1, int(denseContour.size()));
763 const unsigned int targetIndexPlus = (
unsigned int)
modulo(
int(targetIndex) + 1, int(denseContour.size()));
764 ocean_assert(targetIndexMinus < denseContour.size());
765 ocean_assert(targetIndexPlus < denseContour.size());
767 const PixelPosition& sourceMinus = denseContour[sourceIndexMinus];
769 const PixelPosition& sourcePlus = denseContour[sourceIndexPlus];
770 ocean_assert(sourceMinus.
x() < width);
771 ocean_assert_and_suppress_unused(sourceMinus.
y() < height, height);
772 ocean_assert(source.
x() < width);
773 ocean_assert(source.
y() < height);
774 ocean_assert(sourcePlus.
x() < width);
775 ocean_assert(sourcePlus.
y() < height);
777 const PixelPosition& targetMinus = denseContour[targetIndexMinus];
779 const PixelPosition& targetPlus = denseContour[targetIndexPlus];
780 ocean_assert(targetMinus.
x() < width);
781 ocean_assert(targetMinus.
y() < height);
782 ocean_assert(target.
x() < width);
783 ocean_assert(target.
y() < height);
784 ocean_assert(targetPlus.
x() < width);
785 ocean_assert(targetPlus.
y() < height);
787 const uint8_t* frameSourceMinus = frame + sourceMinus.
y() * frameStrideElements + sourceMinus.
x() * tChannels;
788 const uint8_t* frameTargetPlus = frame + targetPlus.
y() * frameStrideElements + targetPlus.
x() * tChannels;
789 const unsigned int ssdMinus = SumSquareDifferencesBase::buffer8BitPerChannelTemplate<tChannels>(frameSourceMinus, frameTargetPlus);
791 const uint8_t* frameSource = frame + source.
y() * frameStrideElements + source.
x() * tChannels;
792 const uint8_t* frameTarget = frame + target.
y() * frameStrideElements + target.
x() * tChannels;
793 const unsigned int ssd = SumSquareDifferencesBase::buffer8BitPerChannelTemplate<tChannels>(frameSource, frameTarget);
795 const uint8_t* frameSourcePlus = frame + sourcePlus.
y() * frameStrideElements + sourcePlus.
x() * tChannels;
796 const uint8_t* frameTargetMinus = frame + targetMinus.
y() * frameStrideElements + targetMinus.
x() * tChannels;
797 const unsigned int ssdPlus = SumSquareDifferencesBase::buffer8BitPerChannelTemplate<tChannels>(frameSourcePlus, frameTargetMinus);
799 if (ssd > 100 && (ssdPlus > 2u * ssd || ssdMinus > 2u * ssd))
801 return (
unsigned int)(-1);
804 return (ssdMinus + 2u * ssd + ssdPlus) / 4u;
809 return value * value;
This class implements bresenham line algorithms.
Definition: Bresenham.h:27
void findNext(int &x, int &y)
Applies one Bresenham step to find the next pixel.
T left() const
Returns the left (including) pixel position of this bounding box.
Definition: PixelBoundingBox.h:416
T right() const
Returns the right (including) pixel position of this bounding box.
Definition: PixelBoundingBox.h:430
T bottom() const
Returns the bottom (including) position of this bounding box.
Definition: PixelBoundingBox.h:444
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
T y() const
Returns the vertical coordinate position of this object.
Definition: PixelPosition.h:470
unsigned int sqrDistance(const PixelPositionT< T > &position) const
Returns the square difference between two pixel positions.
Definition: PixelPosition.h:489
T x() const
Returns the horizontal coordinate position of this object.
Definition: PixelPosition.h:458
This class determines mappings between pixels lying on a contour.
Definition: ContourMapping.h:37
static Indices32 mappingInitialization8BitPerChannel(const uint8_t *frame, const uint8_t *mask, const uint8_t *outline, const unsigned int width, const unsigned int height, const unsigned int framePaddingElements, const unsigned int maskPaddingElements, const unsigned int outlinePaddingElements, const PixelPositions &denseContour, const unsigned int appearanceThreshold)
Determines an initial mapping between all pixel of a contour based on simple geometrical and visual r...
Definition: ContourMapping.h:390
static int distanceInContour(const unsigned int highIndex, const unsigned int lowIndex, const unsigned int size)
Determines the (signed) pixel distance along the contour between two location on the contour.
static unsigned int neighborCostDistance(const Indices32 &mapping, const unsigned int sourceIndex, const unsigned int targetIndex)
Determines the geometric cost between two contour points while both neighbor pixels are included into...
static unsigned int neighborCostDistanceMinus(const Indices32 &mapping, const unsigned int sourceIndex, const unsigned int targetIndex)
Determines the geometric cost between two contour points while the previous neighbor pixel is include...
static unsigned int directMappingCostAppearance8BitPerChannelKernel3(const uint8_t *frame, const unsigned int width, const unsigned int height, const unsigned int frameStrideElements, const PixelPositions &denseContour, const unsigned int sourceIndex, const unsigned int targetIndex)
Returns the appearance cost between two contour points using a [1 2 1] kernel.
Definition: ContourMapping.h:749
static unsigned int totalForwardCost8BitPerChannel(const uint8_t *frame, const uint8_t *mask, const uint8_t *outline, const unsigned int width, const unsigned int height, const unsigned int frameStrideElements, const unsigned int maskStrideElements, const unsigned int outlineStrideElements, const PixelPositions &denseContour, const Indices32 &mapping, const unsigned int sourceIndex, const unsigned int targetIndex, const bool oneWay)
Determines the total cost of a pixel mapping during the forward propagation iteration including appea...
Definition: ContourMapping.h:660
static void improveMapping8BitPerChannel(const uint8_t *frame, const uint8_t *mask, const uint8_t *outline, const unsigned int width, const unsigned int height, const unsigned int framePaddingElements, const unsigned int maskPaddingElements, const unsigned int outlinePaddingElements, const PixelPositions &denseContour, Indices32 &mapping)
Iteratively improves the mapping quality between contour pixels e.g., by propagating an initial mappi...
Definition: ContourMapping.h:441
static Indices32 contour2mapping8BitPerChannel(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 PixelPositions &denseContour)
Determines the mapping between pixels lying on a contour (defined within a frame) based on visual and...
Definition: ContourMapping.h:229
static bool isLineOutsideMask(const uint8_t *mask, const uint8_t *outline, const unsigned int width, const unsigned int height, const unsigned int maskStrideElements, const unsigned int outlineStrideElements, const PixelPosition &start, const PixelPosition &stop)
Returns whether a specified line has at least one pixel outside a specified mask.
static unsigned int neighborCostDistancePlus(const Indices32 &mapping, const unsigned int sourceIndex, const unsigned int targetIndex)
Determines the geometric cost between two contour points while the next neighbor pixel is included in...
static void mappingInterpolation8BitPerChannel(uint8_t *frame, uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int framePaddingElements, const unsigned int maskPaddingElements, const PixelPositions &denseContour, const PixelBoundingBox &boundingBox, const Indices32 &mapping)
Replaces the visual content of a frame within a mask area by using the mapping information of the con...
Definition: ContourMapping.h:257
static unsigned int totalBackwardCost8BitPerChannel(const uint8_t *frame, const uint8_t *mask, const uint8_t *outline, const unsigned int width, const unsigned int height, const unsigned int frameStrideElements, const unsigned int maskStrideElements, const unsigned int outlineStrideElements, const PixelPositions &denseContour, const Indices32 &mapping, const unsigned int sourceIndex, const unsigned int targetIndex, const bool oneWay)
Determines the total cost of a pixel mapping during the backward propagation iteration including appe...
Definition: ContourMapping.h:707
static unsigned int sqr(const int value)
Returns the square value of a given parameter.
Definition: ContourMapping.h:807
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
bool isContinuous() const
Returns whether all planes of this frame have continuous memory and thus do not contain any padding a...
Definition: Frame.h:4276
const T * constdata(const unsigned int planeIndex=0u) const
Returns a pointer to the read-only pixel data of a specific plane.
Definition: Frame.h:4168
T * data(const unsigned int planeIndex=0u)
Returns a pointer to the pixel data of a specific plane.
Definition: Frame.h:4159
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 setValue(const uint8_t value, const unsigned int planeIndex=0u, const bool skipPaddingData=true)
Sets the memory of the frame to a specified byte value (the memory of one plane).
unsigned int paddingElements(const unsigned int planeIndex=0u) const
Returns the optional number of padding elements at the end of each row for a specific plane.
Definition: Frame.h:4042
Definition of a frame type composed by the frame dimension, pixel format and pixel origin.
Definition: Frame.h:30
@ FORMAT_Y8
Pixel format for grayscale images with byte order Y and 8 bits per pixel.
Definition: Frame.h:594
@ ORIGIN_UPPER_LEFT
The first pixel lies in the upper left corner, the last pixel in the lower right corner.
Definition: Frame.h:1050
This class implements a generator for random numbers.
Definition: RandomGenerator.h:42
static unsigned int random(const unsigned int maxValue)
Returns one random integer value with specified maximum value.
T modulo(const T &value, const T &ring)
Returns the modulo value of a given parameter within a ring allowing positive and negative parameters...
Definition: base/Utilities.h:924
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
T ringDistance(const T &value0, const T &value1, const T &ring)
Returns the distance between two values inside defined ring.
Definition: base/Utilities.h:1018
unsigned int sqr(const char value)
Returns the square value of a given value.
Definition: base/Utilities.h:1029
std::vector< PixelPosition > PixelPositions
Definition of a vector holding pixel positions (with positive coordinate values).
Definition: PixelPosition.h:48
PixelContourT< unsigned int > PixelContour
Definition of the default PixelContour object with a data type allowing only positive coordinate valu...
Definition: PixelContour.h:29
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15