Gaussian Filter

Filters an image using a Gaussian filter.

Description

This function applies a Gaussian filter to the source image with the specified kernel radius. Algorithm parameters shall be set through the gaussian_spec class. The values of border pixels are assigned in accordance with the border type. The formulae below describe the algorithm to compute kernel.

../_images/cq5dam.web.1280.1280.jpeg

where

  • K is kernel size, K/2 is kernel radius

  • sigma - standard deviation of gaussian distribution

  • Gi,j are gaussian kernel values

Headers

oneapi/ipl/filter/gaussian.hpp

Syntax

template<typename ComputeT = float, formats Format, typename DataT, typename SrcAllocatorT, typename DstAllocatorT>
sycl::event oneapi::ipl::gaussian(sycl::queue &queue, image<Format, DataT, SrcAllocatorT> &src, image<Format, DataT, DstAllocatorT> &dst, const gaussian_spec_t<Format, DataT, ComputeT> &spec, const std::vector<sycl::event> &dependencies = {})

Gaussian filter.

Template Parameters
  • ComputeT – type to perform calculations

  • Format – source/destination image format

  • DataT – source/destination image data type

  • SrcAllocatorT – source image allocator

  • DstAllocatorT – destination image allocator

Parameters
  • queue – SYCL queue

  • src – source image

  • dst – destination image

  • spec – algorithmic spec

  • dependencies – dependencies

Returns

SYCL event

Supported values for ComputeT:

float

double

half

v

v

x

Supported combinations for DataT/Formats:

DataT/Formats

plane

rgb/bgr

rgba/bgra

rgbp

std::uint8_t

v

v

v

x

std::int8_t

v

v

v

x

std::uint16_t

v

v

v

x

std::int16_t

v

v

v

x

std::uint32_t

v

v

v

x

std::int32_t

v

v

v

x

float

v

v

v

x

double

v

v

v

x

Supported values for subsampled Format (only for DataT = std::uint8_t):

nv12

i420

x

x

Parameters

border type support

Type of border. Possible values are:

const_val - Values of all border pixels are set to constant.

repl - Border is replicated from the edge pixels.

mirror - Border is mirrored from the edge pixels.

template<int NumChannels = 1, typename DataT = std::uint8_t, typename ComputeT = float>
class oneapi::ipl::gaussian_spec : public oneapi::ipl::border_spec_base<1, std::uint8_t>

Gaussian filter parameters.

Template Parameters
  • NumChannels – the number of channels in border value vector

  • DataT – the type for constant border value component

  • ComputeT – the type for computations

Public Types

using border_spec_base_t = border_spec_base<NumChannels, DataT>

Type alias for base class of spec with border parameters.

using native_pixel_t = sycl::vec<std::uint8_t, NumChannels>

Type alias for pixel type.

Public Functions

template<int OtherNumChannels, typename OtherDataT, typename OtherComputeT>
gaussian_spec(const gaussian_spec<OtherNumChannels, OtherDataT, OtherComputeT> &other)

Conversion constructor for gaussian specification.

Template Parameters
  • OtherNumChannels – other number of channels

  • OtherDataT – other data type

  • OtherComputeT – the other type for computations

Parameters

other – the other gaussian specification

explicit gaussian_spec(std::size_t radius, border_types border = border_types::repl, crop_types crop = crop_types::on)

Construct gaussian spec by OpenCV formula and given border type and crop flag.

Parameters
  • radius – kernel radius

  • border – border type

  • crop – crop flag

template<int OtherNumChannels, typename OtherDataT>
explicit gaussian_spec(std::size_t radius, const sycl::vec<OtherDataT, OtherNumChannels> &border_val, crop_types crop = crop_types::on)

Construct gaussian spec by OpenCV formula and given value for constant border and crop flag.

Template Parameters
  • OtherNumChannels – other number of channels

  • OtherDataT – other data type

Parameters
  • radius – kernel radius

  • border_val – value for constant border

  • crop – crop flag

template<typename OtherComputeT>
explicit gaussian_spec(std::size_t radius, OtherComputeT sigma, border_types border = border_types::repl, crop_types crop = crop_types::on)

Construct gaussian spec with given radius, sigma, border type and crop flag.

Template Parameters

OtherComputeT – other type for computations

Parameters
  • radius – kernel radius

  • sigma – sigma parameter of gaussian

  • border – border type

  • crop – crop flag

template<int OtherNumChannels, typename OtherDataT, typename OtherComputeT>
explicit gaussian_spec(std::size_t radius, OtherComputeT sigma, const sycl::vec<OtherDataT, OtherNumChannels> &border_val, crop_types crop = crop_types::on)

Construct gaussian spec with given radius, sigma, value for constant border and crop flag.

Template Parameters
  • OtherNumChannels – other number of channels

  • OtherDataT – other data type

  • OtherComputeT – other type for computations

Parameters
  • radius – kernel radius

  • sigma – sigma parameter of gaussian

  • border_val – value for constant border

  • crop – crop flag

std::size_t get_radius() const noexcept

Returns the radius of gaussian filter.

Returns

the radius of gaussian filter

ComputeT get_sigma() const noexcept

Returns the sigma of gaussian filter.

Returns

the sigma of gaussian filter

crop_types get_crop() const noexcept

Returns the crop type.

Returns

crop type

border_types get_border() const noexcept

Returns the border type.

Returns

border type

auto get_border_val() const noexcept -> const native_pixel_t&

Returns the border value.

Returns

border value

auto get_border_val_ptr() const -> const std::uint8_t*

Returns the border value pointer.

Returns

border value pointer

Errors

compile-time format check

Indicates an error when image format is not supported.

compile-time data type check

Indicates an error when image data type is not supported.

compile-time compute data type check

Indicates an error when compute data type is not supported.

invalid_argument

Indicates an error when ROI sizes of the source image and the destination image are not equal.

invalid_argument exception

Indicates an error when one of the pitch values is not divisible by size of component data type in bytes.

unimplemented exception

Indicates an error when border type is not supported.

The code example below demonstrates how to use the oneapi::ipl::gaussian:

// Create queue
sycl::queue queue{};

image<formats::rgba, std::uint8_t> src_image{ src_data_pointer, size };
image<formats::rgba, std::uint8_t> dst_image{ size };

// Create a gaussian arguments (kernel radius = 2, sigma is caluculated)
const gaussian_spec spec{ 2 };

(void)gaussian(queue, src_image, dst_image, spec);