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 based on absolute value and direction of Sobel's filter along y and y axis. 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 contour metrics based on absolute value and direction of Sobel's filter along y and y axis with using mask. 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)
 Extract contour anchors from 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 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 has 8-bit gray format, output image must has 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 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]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).

◆ 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 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 has 8-bit gray format, output image must has 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 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]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]indexMin- a mask minimal permissible index.
[out]dst- a pointer to pixels data of the output 16-bit image.
[in]dstStride- a row size of the output image (in bytes).

◆ 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 
)

Extract contour anchors from contour metrics.

All images must have the same width and height. Input image must has 16-bit integer format, output image must has 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 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]width- an image width.
[in]height- an image height.
[in]step- a row step (to skip some rows).
[in]threshold- a threshold of anchor creation.
[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 has 8-bit gray format, output image must has 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 has 8-bit gray format, output image must has 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 has 16-bit integer format, output image must has 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.