8 #ifndef META_OCEAN_CV_SEGMENTATION_MASK_CREATOR_H
9 #define META_OCEAN_CV_SEGMENTATION_MASK_CREATOR_H
25 namespace Segmentation
65 static inline void triangles2inclusiveMask(uint8_t* mask,
const unsigned int width,
const unsigned int height,
const unsigned int maskPaddingElements,
const Advanced::PixelTriangleT<T>* triangles,
const size_t size,
const uint8_t maskValue,
Worker* worker =
nullptr);
76 static void smoothMask(uint8_t* mask,
const unsigned int width,
const unsigned int height,
const unsigned int maskPaddingElements,
const unsigned int iterations,
const unsigned int incrementValue);
94 static bool contour2inclusiveMaskByTriangulation(uint8_t* mask,
const unsigned int width,
const unsigned int height,
const unsigned int maskPaddingElements,
const PixelContour& simplifiedContour,
const unsigned int maskValue,
Worker* worker =
nullptr,
bool* triangulationForced =
nullptr);
125 static inline void denseContour2inclusiveMask(uint8_t* mask,
const unsigned int width,
const unsigned int height,
const unsigned int maskPaddingElements,
const PixelContour& denseContour,
const uint8_t maskValue);
141 static inline void denseContour2exclusiveMask(uint8_t* mask,
const unsigned int width,
const unsigned int height,
const unsigned int maskPaddingElements,
const PixelContour& denseContour,
const uint8_t maskValue);
155 static inline void denseContour2inclusiveMaskXOR(uint8_t* mask,
const unsigned int width,
const unsigned int height,
const unsigned int maskPaddingElements,
const PixelContour& denseContour,
const uint8_t xorReference = 0xFF);
169 static inline void denseContour2exclusiveMaskXOR(uint8_t* mask,
const unsigned int width,
const unsigned int height,
const unsigned int maskPaddingElements,
const PixelContour& denseContour,
const uint8_t xorReference = 0xFF);
190 static void separation2mask(
const uint32_t* separation,
const unsigned int width,
const unsigned int height,
const unsigned int separationPaddingElements,
const uint32_t
id, uint8_t* mask,
const unsigned int maskPaddingElements,
const uint8_t maskValue = 0x00);
213 static void separations2mask(
const uint32_t* separation,
const unsigned int width,
const unsigned int height,
const unsigned int separationPaddingElements,
const uint8_t* ids,
const size_t numberIds,
const uint8_t maskValue, uint8_t* mask,
const unsigned int maskPaddingElements);
233 static inline void joinMasks(
const uint8_t* mask, uint8_t* target,
const unsigned int width,
const unsigned int height,
const unsigned int maskPaddingElements,
const unsigned int targetPaddingElements,
const uint8_t maskValue = 0x00,
Worker* worker =
nullptr);
320 template <
typename T>
321 static inline void triangles2inclusiveMaskSubset(uint8_t* mask,
const unsigned int width,
const unsigned int height,
const unsigned int maskPaddingElements,
const Advanced::PixelTriangleT<T>* triangles,
const uint8_t maskValue,
const unsigned int firstTriangle,
const unsigned int numberTriangles);
336 static void joinMasksSubset(
const uint8_t* mask, uint8_t* target,
const unsigned int width,
const unsigned int height,
const unsigned int maskPaddingElements,
const unsigned int targetPaddingElements,
const uint8_t maskValue,
const unsigned int firstRow,
const unsigned int numberRows);
342 ocean_assert(mask !=
nullptr && width != 0u && height != 0u);
344 if (triangle.
left() >= width || triangle.
top() >= height)
349 const unsigned int maskStrideElements = width + maskPaddingElements;
351 const unsigned int yMin = triangle.
top();
352 const unsigned int yMax = min(triangle.
bottom(), height - 1u);
358 unsigned int x01, x02, x12;
360 for (
unsigned int y = yMin; y <= yMax; ++y)
362 unsigned int xMin = 0xFFFFFFFF;
363 unsigned int xMax = 0;
367 xMin = min(xMin, x01);
368 xMax = max(xMax, x01);
372 xMin = min(xMin, min(l01.
p0().x(), l01.
p1().x()));
373 xMax = max(xMax, max(l01.
p0().x(), l01.
p1().x()));
379 xMin = min(xMin, x02);
380 xMax = max(xMax, x02);
384 xMin = min(xMin, min(l02.
p0().x(), l02.
p1().x()));
385 xMax = max(xMax, max(l02.
p0().x(), l02.
p1().x()));
391 xMin = min(xMin, x12);
392 xMax = max(xMax, x12);
396 xMin = min(xMin, min(l12.
p0().x(), l12.
p1().x()));
397 xMax = max(xMax, max(l12.
p0().x(), l12.
p1().x()));
403 memset(mask + y * maskStrideElements + xMin, maskValue, xMax - xMin + 1u);
411 ocean_assert(mask && width != 0u && height != 0u);
413 if (triangle.
left() >=
int(width) || triangle.
right() < 0 || triangle.
top() >=
int(height) || triangle.
bottom() < 0)
418 const unsigned int maskStrideElements = width + maskPaddingElements;
420 const int yMin = max(0, triangle.
top());
421 const int yMax = min(triangle.
bottom(),
int(height - 1u));
423 ocean_assert(yMin >= 0 && yMax <
int(height) && yMin < yMax);
431 for (
int y = yMin; y <= yMax; ++y)
438 xMin = min(xMin, x01);
439 xMax = max(xMax, x01);
443 xMin = min(xMin, min(l01.
p0().x(), l01.
p1().x()));
444 xMax = max(xMax, max(l01.
p0().x(), l01.
p1().x()));
450 xMin = min(xMin, x02);
451 xMax = max(xMax, x02);
455 xMin = min(xMin, min(l02.
p0().x(), l02.
p1().x()));
456 xMax = max(xMax, max(l02.
p0().x(), l02.
p1().x()));
462 xMin = min(xMin, x12);
463 xMax = max(xMax, x12);
467 xMin = min(xMin, min(l12.
p0().x(), l12.
p1().x()));
468 xMax = max(xMax, max(l12.
p0().x(), l12.
p1().x()));
477 if (xMax >=
int(width))
479 xMax = int(width) - 1;
484 memset(mask + y * maskStrideElements + xMin, maskValue, xMax - xMin + 1u);
489 template <
typename T>
492 ocean_assert(mask !=
nullptr && width != 0u && height != 0u);
493 ocean_assert(triangles !=
nullptr && size != 0);
497 worker->
executeFunction(
Worker::Function::createStatic(&
MaskCreator::triangles2inclusiveMaskSubset, mask, width, height, maskPaddingElements, triangles, maskValue, 0u, 0u), 0u, (
unsigned int)(size));
507 ocean_assert(mask && width != 0u && height != 0u);
516 ocean_assert(mask && width != 0u && height != 0u);
525 ocean_assert(mask && width != 0u && height != 0u);
534 ocean_assert(mask && width != 0u && height != 0u);
541 inline void MaskCreator::joinMasks(
const uint8_t* mask, uint8_t* target,
const unsigned int width,
const unsigned int height,
const unsigned int maskPaddingElements,
const unsigned int targetPaddingElements,
const uint8_t maskValue,
Worker* worker)
543 ocean_assert(mask !=
nullptr && target !=
nullptr);
544 ocean_assert(width != 0u && height != 0u);
548 worker->
executeFunction(
Worker::Function::createStatic(&
MaskCreator::joinMasksSubset, mask, target, width, height, maskPaddingElements, targetPaddingElements, maskValue, 0u, 0u), 0u, height, 7u, 8u, 20u);
552 joinMasksSubset(mask, target, width, height, maskPaddingElements, targetPaddingElements, maskValue, 0u, height);
556 template <
typename T>
559 ocean_assert(mask && triangles);
561 for (
unsigned int n = firstTriangle; n < firstTriangle + numberTriangles; ++n)
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
T right() const
Returns the most right (including) position of this triangle.
Definition: PixelTriangle.h:259
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
T left() const
Returns the most left (including) position of this triangle.
Definition: PixelTriangle.h:245
This class implements functions allowing to create or to modify masks.
Definition: MaskCreator.h:33
static void denseContour2exclusiveMaskOffsets(const PixelContour &denseDistinctContour, IndexGroups32 &offsetGroups)
Determines the group of horizontal pixel offset locations for a given dense and distinct contour so t...
static void inclusiveMaskOffsets2inclusiveMask(IndexGroups32 &offsetGroups, uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int maskPaddingElements, const uint8_t maskValue)
Creates an (inclusive) 8 bit mask for a given group of horizontal pixel offset locations.
static void separations2mask(const uint32_t *separation, const unsigned int width, const unsigned int height, const unsigned int separationPaddingElements, const uint8_t *ids, const size_t numberIds, const uint8_t maskValue, uint8_t *mask, const unsigned int maskPaddingElements)
Creates an 8 bit mask from a given 1 channel 32 bit separation frame.
static void separation2mask(const uint32_t *separation, const unsigned int width, const unsigned int height, const unsigned int separationPaddingElements, const uint32_t id, uint8_t *mask, const unsigned int maskPaddingElements, const uint8_t maskValue=0x00)
Creates an 8 bit mask from a given 1 channel 32 bit separation frame.
static void denseContour2inclusiveMaskHotizontallyConvex(uint8_t *mask, const unsigned int width, const unsigned int height, const PixelPositions &densePixelPositions, const uint8_t maskValue)
Creates a binary 8 bit horizontally-convex (inclusive) mask from a given dense contour.
static void smoothMask(uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int maskPaddingElements, const unsigned int iterations, const unsigned int incrementValue)
Smooths a given 8 bit mask frame by adding additional outline-4 mask pixels with incrementing values ...
static void triangles2inclusiveMask(uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int maskPaddingElements, const Advanced::PixelTriangleT< T > *triangles, const size_t size, const uint8_t maskValue, Worker *worker=nullptr)
Creates a binary 8 bit mask for several given triangles, actually the triangles will be painted into ...
Definition: MaskCreator.h:490
static bool contour2inclusiveMaskByTriangulation(uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int maskPaddingElements, const PixelContour &simplifiedContour, const unsigned int maskValue, Worker *worker=nullptr, bool *triangulationForced=nullptr)
Creates a binary 8 bit (inclusive) mask for a given sparse or dense contour.
static void exclusiveMaskOffsets2exclusiveMaskXOR(IndexGroups32 &offsetGroups, uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int maskPaddingElements, const uint8_t xorReference)
Creates an (exclusive) 8 bit mask for a given group of horizontal pixel offset locations.
static void denseContour2inclusiveMask(uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int maskPaddingElements, const PixelContour &denseContour, const uint8_t maskValue)
Creates a binary 8 bit (inclusive) mask from a given dense and distinct contour.
Definition: MaskCreator.h:505
static void joinMasksSubset(const uint8_t *mask, uint8_t *target, const unsigned int width, const unsigned int height, const unsigned int maskPaddingElements, const unsigned int targetPaddingElements, const uint8_t maskValue, const unsigned int firstRow, const unsigned int numberRows)
Joins two 8 bit masks with respect to a specific mask value.
static void denseContour2exclusiveMask(uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int maskPaddingElements, const PixelContour &denseContour, const uint8_t maskValue)
Creates a binary 8 bit (exclusive) mask from a given dense and distinct contour.
Definition: MaskCreator.h:523
static void denseContour2exclusiveMaskXOR(uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int maskPaddingElements, const PixelContour &denseContour, const uint8_t xorReference=0xFF)
Creates a binary 8 bit (exclusive) mask from a given dense and distinct contour.
Definition: MaskCreator.h:532
static void exclusiveMaskOffsets2exclusiveMask(IndexGroups32 &offsetGroups, uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int maskPaddingElements, const uint8_t maskValue)
Creates an (exclusive) 8 bit mask for a given group of horizontal pixel offset locations.
static void denseContour2inclusiveMaskXOR(uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int maskPaddingElements, const PixelContour &denseContour, const uint8_t xorReference=0xFF)
Creates a binary 8 bit (inclusive) mask from a given dense and distinct contour.
Definition: MaskCreator.h:514
static void denseContour2inclusiveMaskOffsets(const PixelContour &denseDistinctContour, IndexGroups32 &offsetGroups)
Determines the group of horizontal pixel offset locations for a given dense and distinct contour so t...
static void inclusiveMaskOffsets2inclusiveMaskXOR(IndexGroups32 &offsetGroups, uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int maskPaddingElements, const uint8_t xorReference)
Creates an (inclusive) 8 bit mask for a given group of horizontal pixel offset locations.
static void triangles2inclusiveMaskSubset(uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int maskPaddingElements, const Advanced::PixelTriangleT< T > *triangles, const uint8_t maskValue, const unsigned int firstTriangle, const unsigned int numberTriangles)
Creates a binary 8 bit mask for a subset of several given triangles, actually the triangles will be p...
Definition: MaskCreator.h:557
static void triangle2inclusiveMask(uint8_t *mask, const unsigned int width, const unsigned int height, const unsigned int maskPaddingElements, const Advanced::PixelTriangleT< T > &triangle, const uint8_t maskValue)
Creates a binary 8 bit (inclusive) mask for one given triangle, actually the triangle is painted into...
static void joinMasks(const uint8_t *mask, uint8_t *target, const unsigned int width, const unsigned int height, const unsigned int maskPaddingElements, const unsigned int targetPaddingElements, const uint8_t maskValue=0x00, Worker *worker=nullptr)
Joins two 8 bit masks with respect to a specific mask value.
Definition: MaskCreator.h:541
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
static constexpr T minValue()
Returns the min scalar value.
Definition: Numeric.h:3250
static constexpr T maxValue()
Returns the max scalar value.
Definition: Numeric.h:3244
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.
std::vector< Indices32 > IndexGroups32
Definition of a vector holding 32 bit indices, so we have groups of indices.
Definition: Base.h:102
std::vector< PixelPosition > PixelPositions
Definition of a vector holding pixel positions (with positive coordinate values).
Definition: PixelPosition.h:48
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15