Simd Library Documentation.

Home | Release Notes | Download | Documentation | Issues | GitHub

Functions for image segmentation. More...

Functions

SIMD_API void SimdSegmentationChangeIndex (uint8_t *mask, size_t stride, size_t width, size_t height, uint8_t oldIndex, uint8_t newIndex)
 Replaces one segmentation index with another inside a mask. More...
 
SIMD_API void SimdSegmentationFillSingleHoles (uint8_t *mask, size_t stride, size_t width, size_t height, uint8_t index)
 Fills isolated single-pixel holes in a segmentation mask. More...
 
SIMD_API void SimdSegmentationPropagate2x2 (const uint8_t *parent, size_t parentStride, size_t width, size_t height, uint8_t *child, size_t childStride, const uint8_t *difference, size_t differenceStride, uint8_t currentIndex, uint8_t invalidIndex, uint8_t emptyIndex, uint8_t differenceThreshold)
 Propagates a segmentation index from a parent mask pyramid level to a child level. More...
 
SIMD_API void SimdSegmentationShrinkRegion (const uint8_t *mask, size_t stride, size_t width, size_t height, uint8_t index, ptrdiff_t *left, ptrdiff_t *top, ptrdiff_t *right, ptrdiff_t *bottom)
 Shrinks a rectangular region to the bounding box of a mask index. More...
 
template<template< class > class A>
SIMD_INLINE void SegmentationChangeIndex (View< A > &mask, uint8_t oldIndex, uint8_t newIndex)
 Changes certain index in mask. More...
 
template<template< class > class A>
SIMD_INLINE void SegmentationFillSingleHoles (View< A > &mask, uint8_t index)
 Fill single holes in mask. More...
 
template<template< class > class A>
SIMD_INLINE void SegmentationPropagate2x2 (const View< A > &parent, View< A > &child, const View< A > &difference, uint8_t currentIndex, uint8_t invalidIndex, uint8_t emptyIndex, uint8_t differenceThreshold)
 Propagates mask index from parent (upper) to child (lower) level of mask pyramid with using 2x2 scan window. More...
 
template<template< class > class A>
SIMD_INLINE void SegmentationShrinkRegion (const View< A > &mask, uint8_t index, Rectangle< ptrdiff_t > &rect)
 Finds actual region of mask index location. More...
 

Detailed Description

Functions for image segmentation.

Function Documentation

◆ SimdSegmentationChangeIndex()

void SimdSegmentationChangeIndex ( uint8_t *  mask,
size_t  stride,
size_t  width,
size_t  height,
uint8_t  oldIndex,
uint8_t  newIndex 
)

Replaces one segmentation index with another inside a mask.

The mask must have 8-bit gray pixel format. Only pixels equal to oldIndex are modified; all other pixels keep their values.

For every point:

if(mask[i] == oldIndex)
    mask[i] = newIndex;
Note
This function has a C++ wrappers: Simd::SegmentationChangeIndex(View<A> & mask, uint8_t oldIndex, uint8_t newIndex).
Parameters
[in,out]mask- a pointer to pixels data of 8-bit gray mask image.
[in]stride- a row size of the mask image in bytes.
[in]width- a mask width.
[in]height- a mask height.
[in]oldIndex- an index value to replace.
[in]newIndex- a replacement index value.

◆ SimdSegmentationFillSingleHoles()

void SimdSegmentationFillSingleHoles ( uint8_t *  mask,
size_t  stride,
size_t  width,
size_t  height,
uint8_t  index 
)

Fills isolated single-pixel holes in a segmentation mask.

The mask must have 8-bit gray pixel format. Only inner pixels are tested; border pixels are not changed. An inner pixel is set to index when its upper, lower, left and right neighbors are all equal to index.

For every inner point:

if(mask[x, y - 1] == index && mask[x, y + 1] == index &&
   mask[x - 1, y] == index && mask[x + 1, y] == index)
    mask[x, y] = index;
Note
This function has a C++ wrappers: Simd::SegmentationFillSingleHoles(View<A> & mask, uint8_t index).
Parameters
[in,out]mask- a pointer to pixels data of 8-bit gray mask image.
[in]stride- a row size of the mask image in bytes.
[in]width- a mask width.
[in]height- a mask height.
[in]index- a mask index used to fill single-pixel holes.

◆ SimdSegmentationPropagate2x2()

void SimdSegmentationPropagate2x2 ( const uint8_t *  parent,
size_t  parentStride,
size_t  width,
size_t  height,
uint8_t *  child,
size_t  childStride,
const uint8_t *  difference,
size_t  differenceStride,
uint8_t  currentIndex,
uint8_t  invalidIndex,
uint8_t  emptyIndex,
uint8_t  differenceThreshold 
)

Propagates a segmentation index from a parent mask pyramid level to a child level.

The parent and child sizes must satisfy: parentWidth = (childWidth + 1)/2, parentHeight = (childHeight + 1)/2. All images must have 8-bit gray pixel format, and the difference image must have the same size as the child image. The function scans each 2x2 parent window and updates the corresponding inner 2x2 child pixels. A child pixel is updated only when its current value is less than invalidIndex. It becomes currentIndex when all four parent pixels equal currentIndex, or when at least one parent pixel equals currentIndex and the corresponding difference pixel is greater than differenceThreshold. Otherwise it becomes emptyIndex.

Note
This function has a C++ wrappers: Simd::SegmentationPropagate2x2(const View<A> & parent, View<A> & child, const View<A> & difference, uint8_t currentIndex, uint8_t invalidIndex, uint8_t emptyIndex, uint8_t thresholdDifference).
Parameters
[in]parent- a pointer to pixels data of 8-bit gray parent mask image.
[in]parentStride- a row size of the parent mask image in bytes.
[in]width- a parent mask width. It must be at least 2.
[in]height- a parent mask height. It must be at least 2.
[in,out]child- a pointer to pixels data of 8-bit gray child mask image.
[in]childStride- a row size of the child mask image in bytes.
[in]difference- a pointer to pixels data of 8-bit gray difference image.
[in]differenceStride- a row size of the difference image in bytes.
[in]currentIndex- a mask index to propagate.
[in]invalidIndex- a minimum value of child pixels that must not be overwritten.
[in]emptyIndex- an index written when propagation condition is false.
[in]differenceThreshold- a threshold for conditional propagation by difference image.

◆ SimdSegmentationShrinkRegion()

void SimdSegmentationShrinkRegion ( const uint8_t *  mask,
size_t  stride,
size_t  width,
size_t  height,
uint8_t  index,
ptrdiff_t *  left,
ptrdiff_t *  top,
ptrdiff_t *  right,
ptrdiff_t *  bottom 
)

Shrinks a rectangular region to the bounding box of a mask index.

The mask must have 8-bit gray pixel format. The input rectangle is passed through left, top, right and bottom. The function searches only inside this rectangle and replaces it with the minimal half-open rectangle [left, right) x [top, bottom) that contains all pixels equal to index. If the index is not found, all four rectangle coordinates are set to 0.

Note
This function has a C++ wrappers: Simd::SegmentationShrinkRegion(const View<A> & mask, uint8_t index, Rectangle<ptrdiff_t> & rect).
Parameters
[in]mask- a pointer to pixels data of 8-bit gray mask image.
[in]stride- a row size of the mask image in bytes.
[in]width- a mask width.
[in]height- a mask height.
[in]index- a mask index to search for.
[in,out]left- a pointer to the left side of the search/result rectangle.
[in,out]top- a pointer to the top side of the search/result rectangle.
[in,out]right- a pointer to the right side of the search/result rectangle.
[in,out]bottom- a pointer to the bottom side of the search/result rectangle.

◆ SegmentationChangeIndex()

void SegmentationChangeIndex ( View< A > &  mask,
uint8_t  oldIndex,
uint8_t  newIndex 
)

Changes certain index in mask.

Mask must have 8-bit gray pixel format.

For every point:

if(mask[i] == oldIndex)
    mask[i] = newIndex;
Note
This function is a C++ wrapper for function SimdSegmentationChangeIndex.
Parameters
[in,out]mask- a 8-bit gray mask image.
[in]oldIndex- a mask old index.
[in]newIndex- a mask new index.

◆ SegmentationFillSingleHoles()

void SegmentationFillSingleHoles ( View< A > &  mask,
uint8_t  index 
)

Fill single holes in mask.

Mask must have 8-bit gray pixel format.

Note
This function is a C++ wrapper for function SimdSegmentationFillSingleHoles.
Parameters
[in,out]mask- a 8-bit gray mask image.
[in]index- a mask index.

◆ SegmentationPropagate2x2()

void SegmentationPropagate2x2 ( const View< A > &  parent,
View< A > &  child,
const View< A > &  difference,
uint8_t  currentIndex,
uint8_t  invalidIndex,
uint8_t  emptyIndex,
uint8_t  differenceThreshold 
)

Propagates mask index from parent (upper) to child (lower) level of mask pyramid with using 2x2 scan window.

For parent and child image must be performed: parent.width = (child.width + 1)/2, parent.height = (child.height + 1)/2. All images must have 8-bit gray pixel format. Size of different image is equal to child image.

Note
This function is a C++ wrapper for function SimdSegmentationPropagate2x2.
Parameters
[in]parent- a 8-bit gray parent mask image.
[in,out]child- a 8-bit gray child mask image.
[in]difference- a 8-bit gray difference image.
[in]currentIndex- propagated mask index.
[in]invalidIndex- invalid mask index.
[in]emptyIndex- empty mask index.
[in]differenceThreshold- a difference threshold for conditional index propagating.

◆ SegmentationShrinkRegion()

void SegmentationShrinkRegion ( const View< A > &  mask,
uint8_t  index,
Rectangle< ptrdiff_t > &  rect 
)

Finds actual region of mask index location.

Mask must have 8-bit gray pixel format.

Note
This function is a C++ wrapper for function SimdSegmentationShrinkRegion.
Parameters
[in]mask- a 8-bit gray mask image.
[in]index- a mask index.
[in,out]rect- a region bounding box rectangle.