Simd Library Documentation.

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

Contour extraction functions for accelerating of Simd::ContourDetector. More...

Functions

SIMD_API void SimdContourMetrics (const uint8_t *src, size_t srcStride, size_t width, size_t height, uint8_t *dst, size_t dstStride)
 Calculates contour metrics from horizontal and vertical Sobel derivatives. More...
 
SIMD_API void SimdContourMetricsMasked (const uint8_t *src, size_t srcStride, size_t width, size_t height, const uint8_t *mask, size_t maskStride, uint8_t indexMin, uint8_t *dst, size_t dstStride)
 Calculates masked contour metrics from horizontal and vertical Sobel derivatives. More...
 
SIMD_API void SimdContourAnchors (const uint8_t *src, size_t srcStride, size_t width, size_t height, size_t step, int16_t threshold, uint8_t *dst, size_t dstStride)
 Extracts contour anchor points from packed contour metrics. More...
 
template<template< class > class A>
SIMD_INLINE void ContourMetrics (const View< A > &src, View< A > &dst)
 Calculates contour metrics based on absolute value and direction of Sobel's filter along y and y axis. More...
 
template<template< class > class A>
SIMD_INLINE void ContourMetrics (const View< A > &src, const View< A > &mask, uint8_t indexMin, View< A > &dst)
 Calculates contour metrics based on absolute value and direction of Sobel's filter along y and y axis with using mask. More...
 
template<template< class > class A>
SIMD_INLINE void ContourAnchors (const View< A > &src, size_t step, int16_t threshold, View< A > &dst)
 Extract contour anchors from contour metrics. More...
 

Detailed Description

Contour extraction functions for accelerating of Simd::ContourDetector.

Function Documentation

◆ SimdContourMetrics()

void SimdContourMetrics ( const uint8_t *  src,
size_t  srcStride,
size_t  width,
size_t  height,
uint8_t *  dst,
size_t  dstStride 
)

Calculates contour metrics from horizontal and vertical Sobel derivatives.

Input image must have 8-bit gray format, output image must have 16-bit integer format. All images must have the same width and height, and width must be greater than 1. At image borders the nearest valid source row or column is reused. The output value packs contour magnitude and dominant direction: the high bits contain dx + dy, and the low bit is 0 when dx >= dy and 1 otherwise. This function is used for contour extraction.

For every point:

x0 = Max(x - 1, 0); x2 = Min(x + 1, width - 1);
y0 = Max(y - 1, 0); y2 = Min(y + 1, height - 1);
dx = Abs((src[x2, y0] + 2*src[x2, y] + src[x2, y2]) -
         (src[x0, y0] + 2*src[x0, y] + src[x0, y2]));
dy = Abs((src[x0, y2] + 2*src[x, y2] + src[x2, y2]) -
         (src[x0, y0] + 2*src[x, y0] + src[x2, y0]));
dst[x, y] = (dx + dy)*2 + (dx >= dy ? 0 : 1);
Note
This function has a C++ wrappers: Simd::ContourMetrics(const View<A>& src, View<A>& dst).
Parameters
[in]src- a pointer to pixels data of the gray 8-bit input image.
[in]srcStride- a row size of the input image in bytes.
[in]width- an image width.
[in]height- an image height.
[out]dst- a pointer to pixels data of the output 16-bit image.
[in]dstStride- a row size of the output image in bytes. It must be a multiple of sizeof(uint16_t).

◆ SimdContourMetricsMasked()

void SimdContourMetricsMasked ( const uint8_t *  src,
size_t  srcStride,
size_t  width,
size_t  height,
const uint8_t *  mask,
size_t  maskStride,
uint8_t  indexMin,
uint8_t *  dst,
size_t  dstStride 
)

Calculates masked contour metrics from horizontal and vertical Sobel derivatives.

Input and mask images must have 8-bit gray format, output image must have 16-bit integer format. All images must have the same width and height, and width must be greater than 1. At image borders the nearest valid source row or column is reused. Pixels with mask value lower than indexMin get zero output; other pixels use the same packed metric as SimdContourMetrics. This function is used for contour extraction.

For every point:

x0 = Max(x - 1, 0); x2 = Min(x + 1, width - 1);
y0 = Max(y - 1, 0); y2 = Min(y + 1, height - 1);
dx = Abs((src[x2, y0] + 2*src[x2, y] + src[x2, y2]) -
         (src[x0, y0] + 2*src[x0, y] + src[x0, y2]));
dy = Abs((src[x0, y2] + 2*src[x, y2] + src[x2, y2]) -
         (src[x0, y0] + 2*src[x, y0] + src[x2, y0]));
dst[x, y] = mask[x, y] < indexMin ? 0 : (dx + dy)*2 + (dx >= dy ? 0 : 1);
Note
This function has a C++ wrappers: Simd::ContourMetrics(const View<A>& src, const View<A>& mask, uint8_t indexMin, View<A>& dst).
Parameters
[in]src- a pointer to pixels data of the gray 8-bit input image.
[in]srcStride- a row size of the input image in bytes.
[in]width- an image width.
[in]height- an image height.
[in]mask- a pointer to pixels data of the mask 8-bit image.
[in]maskStride- a row size of the mask image in bytes.
[in]indexMin- a minimal mask index that enables metric calculation.
[out]dst- a pointer to pixels data of the output 16-bit image.
[in]dstStride- a row size of the output image in bytes. It must be a multiple of sizeof(uint16_t).

◆ SimdContourAnchors()

void SimdContourAnchors ( const uint8_t *  src,
size_t  srcStride,
size_t  width,
size_t  height,
size_t  step,
int16_t  threshold,
uint8_t *  dst,
size_t  dstStride 
)

Extracts contour anchor points from packed contour metrics.

Input image must have 16-bit integer format produced by SimdContourMetrics or SimdContourMetricsMasked, output image must have 8-bit gray format. All images must have the same width and height. The first and last rows are cleared to zero. For processed inner rows, the first and last columns are also set to zero. Rows are processed with increment step beginning at row 1. Input image with metrics can be estimated by using SimdContourMetrics or SimdContourMetricsMasked functions. This function is used for contour extraction.

For every processed inner point:

a[x, y] = src[x, y] >> 1;
if(src[x, y] & 1)
    dst[x, y] = a[x, y] > 0 && (a[x, y] - a[x + 1, y] >= threshold) && (a[x, y] - a[x - 1, y] >= threshold) ? 255 : 0;
else
    dst[x, y] = a[x, y] > 0 && (a[x, y] - a[x, y + 1] >= threshold) && (a[x, y] - a[x, y - 1] >= threshold) ? 255 : 0;
Note
This function has a C++ wrappers: Simd::ContourAnchors(const View<A>& src, size_t step, int16_t threshold, View<A>& dst).
Parameters
[in]src- a pointer to pixels data of the 16-bit input image.
[in]srcStride- a row size of the input image in bytes. It must be a multiple of sizeof(uint16_t).
[in]width- an image width.
[in]height- an image height.
[in]step- a row step for anchor extraction.
[in]threshold- a minimal metric difference required to create an anchor.
[out]dst- a pointer to pixels data of the output 8-bit gray image.
[in]dstStride- a row size of the output image in bytes.

◆ ContourMetrics() [1/2]

void ContourMetrics ( const View< A > &  src,
View< A > &  dst 
)

Calculates contour metrics based on absolute value and direction of Sobel's filter along y and y axis.

All images must have the same width and height. Input image must have 8-bit gray format, output image must have 16-bit integer format. This function is used for contour extraction.

For every point:

dy = abs((src[x-1,y+1] + 2*src[x, y+1] + src[x+1, y+1]) - (src[x-1,y-1] + 2*src[x, y-1] + src[x+1, y-1]));
dx = abs((src[x+1,y-1] + 2*src[x+1, y] + src[x+1, y+1]) - (src[x-1,y-1] + 2*src[x-1, y] + src[x-1, y+1]));
dst[x, y] = (dx + dy)*2 + (dx >= dy ? 0 : 1);
Note
This function is a C++ wrapper for function SimdContourMetrics.
Parameters
[in]src- a gray 8-bit input image.
[out]dst- an output 16-bit image.

◆ ContourMetrics() [2/2]

void ContourMetrics ( const View< A > &  src,
const View< A > &  mask,
uint8_t  indexMin,
View< A > &  dst 
)

Calculates contour metrics based on absolute value and direction of Sobel's filter along y and y axis with using mask.

All images must have the same width and height. Input image must have 8-bit gray format, output image must have 16-bit integer format. This function is used for contour extraction.

For every point:

dy = abs((src[x-1,y+1] + 2*src[x, y+1] + src[x+1, y+1]) - (src[x-1,y-1] + 2*src[x, y-1] + src[x+1, y-1]));
dx = abs((src[x+1,y-1] + 2*src[x+1, y] + src[x+1, y+1]) - (src[x-1,y-1] + 2*src[x-1, y] + src[x-1, y+1]));
dst[x, y] = mask[x, y] < indexMin ? 0 : (dx + dy)*2 + (dx >= dy ? 0 : 1);
Note
This function is a C++ wrapper for function SimdContourMetricsMasked.
Parameters
[in]src- a gray 8-bit input image.
[in]mask- a mask 8-bit image.
[in]indexMin- a mask minimal permissible index.
[out]dst- an output 16-bit image.

◆ ContourAnchors()

void ContourAnchors ( const View< A > &  src,
size_t  step,
int16_t  threshold,
View< A > &  dst 
)

Extract contour anchors from contour metrics.

All images must have the same width and height. Input image must have 16-bit integer format, output image must have 8-bit gray format. Input image with metrics can be estimated by using SimdContourMetrics or SimdContourMetricsMasked functions. This function is used for contour extraction.

For every point (except border):

a[x, y] = src[x, y] >> 1.
if(src[x, y] & 1)
    dst[x, y] = a[x, y] > 0 && (a[x, y] - a[x + 1, y] >= threshold) && (a[x, y] - a[x - 1, y] >= threshold) ? 255 : 0;
else
    dst[x, y] = a[x, y] > 0 && (a[x, y] - a[x, y + 1] >= threshold) && (a[x, y] - a[x, y - 1] >= threshold) ? 255 : 0;
Note
This function is a C++ wrapper for function SimdContourAnchors.
Parameters
[in]src- a 16-bit input image.
[in]step- a row step (to skip some rows).
[in]threshold- a threshold of anchor creation.
[out]dst- an output 8-bit gray image.