Simd Library Documentation.

Home | Release Notes | Download | Documentation | Issues | GitHub
Gaussian Blur Filters

Gaussian blur image filters. More...

Functions

SIMD_API void SimdGaussianBlur3x3 (const uint8_t *src, size_t srcStride, size_t width, size_t height, size_t channelCount, uint8_t *dst, size_t dstStride)
 Performs 3x3 Gaussian blur for an 8-bit interleaved image. More...
 
SIMD_API void * SimdGaussianBlurInit (size_t width, size_t height, size_t channels, const float *sigma, const float *epsilon)
 Creates a context for separable Gaussian blurring of an 8-bit interleaved image. More...
 
SIMD_API void SimdGaussianBlurRun (const void *filter, const uint8_t *src, size_t srcStride, uint8_t *dst, size_t dstStride)
 Performs image Gaussian blurring with a context created by SimdGaussianBlurInit. More...
 

Detailed Description

Gaussian blur image filters.

Function Documentation

◆ SimdGaussianBlur3x3()

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

Performs 3x3 Gaussian blur for an 8-bit interleaved image.

The function applies the same separable 3x3 kernel to every channel independently. For every channel c of pixel (x, y):

sx0 = Max(x - 1, 0);
sx1 = x;
sx2 = Min(x + 1, width - 1);
sy0 = Max(y - 1, 0);
sy1 = y;
sy2 = Min(y + 1, height - 1);

dst[x, y, c] = (src[sx0, sy0, c] + 2*src[sx1, sy0, c] + src[sx2, sy0, c] +
              2*(src[sx0, sy1, c] + 2*src[sx1, sy1, c] + src[sx2, sy1, c]) +
                 src[sx0, sy2, c] + 2*src[sx1, sy2, c] + src[sx2, sy2, c] + 8) / 16;

The source and destination images must have the same width, height and number of interleaved 8-bit channels. Valid channel counts are 1, 2, 3 and 4.

Note
This function has a C++ wrapper Simd::GaussianBlur3x3(const View<A>& src, View<A>& dst).
Parameters
[in]src- a pointer to pixels data of source image.
[in]srcStride- a row size of the src image (in bytes).
[in]width- an image width.
[in]height- an image height.
[in]channelCount- a number of 8-bit channels per pixel.
[out]dst- a pointer to pixels data of destination image.
[in]dstStride- a row size of the dst image (in bytes).

◆ SimdGaussianBlurInit()

void * SimdGaussianBlurInit ( size_t  width,
size_t  height,
size_t  channels,
const float *  sigma,
const float *  epsilon 
)

Creates a context for separable Gaussian blurring of an 8-bit interleaved image.

The context stores image parameters and normalized 1D Gaussian coefficients used by SimdGaussianBlurRun:

half = floor(sqrt(-log(epsilon[0])) * sigma[0]);
kernel = 2*half + 1;
weight[kernel];

for(x = -half; x <= half; ++x)
    weight[x + half] = exp(-Square(x/sigma[0])/2);

sum = 0;
for(x = -half; x <= half; ++x)
    sum += weight[x + half];

for(x = -half; x <= half; ++x)
    weight[x + half] /= sum;
Parameters
[in]width- a width of input and output image.
[in]height- a height of input and output image.
[in]channels- a number of 8-bit channels per pixel. Its value must be in range [1..4].
[in]sigma- a pointer to sigma parameter (blur radius). Its value must be greater than or equal to 0.000001.
[in]epsilon- a pointer to epsilon parameter (permissible relative error). Its value must be in range [0.000001..1.0]. Pointer can be NULL and by default value 0.001 is used.
Returns
a pointer to filter context. On error it returns NULL. This pointer is used by SimdGaussianBlurRun and must be released by SimdRelease.

◆ SimdGaussianBlurRun()

void SimdGaussianBlurRun ( const void *  filter,
const uint8_t *  src,
size_t  srcStride,
uint8_t *  dst,
size_t  dstStride 
)

Performs image Gaussian blurring with a context created by SimdGaussianBlurInit.

The function applies the context's normalized 1D kernel horizontally and vertically to every channel independently. Border pixels are handled by nearest-pixel replication:

sum = 0;
for(y = -half; y <= half; ++y)
{
    sy = Min(Max(0, dy + y), height - 1);
    for(x = -half; x <= half; ++x)
    {
        sx = Min(Max(0, dx + x), width - 1);
        sum += src[sx, sy, c]*weight[x + half]*weight[y + half];
    }
}
dst[dx, dy, c] = Round(sum);
Parameters
[in]filter- a filter context. It must be created by function SimdGaussianBlurInit and released by function SimdRelease.
[in]src- a pointer to pixels data of the original input image.
[in]srcStride- a row size (in bytes) of the input image.
[out]dst- a pointer to pixels data of the filtered output image.
[in]dstStride- a row size (in bytes) of the output image.