Gaussian Filter
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.
where
K is kernel size, K/2 is kernel radius
sigmax, sigmay - standard deviations of gaussian distribution by X, Y directions
Gi,j are gaussian kernel values
Headers
oneapi/ipl/filter/gaussian.hpp
Syntax
-
template<typename ComputeT = float, typename SrcImageT, typename DstImageT>
sycl::event oneapi::ipl::gaussian(sycl::queue &queue, SrcImageT &src, DstImageT &dst, const gaussian_spec_t<SrcImageT::layout_v, typename SrcImageT::data_t, ComputeT> &spec, const std::vector<sycl::event> &dependencies = {})# Gaussian filter.
- Template Parameters
ComputeT – type to perform calculations
SrcImageT – Source image type
DstImageT – Destination image type
- 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/Layouts:
DataT/Layouts |
plane |
channel3 |
channel4 |
plane3 |
---|---|---|---|---|
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 layout (only for std::uint8_t
data type):
sub420 |
sub420i |
---|---|
x |
x |
Parameters
border type support |
Type of border. Possible values are:
|
-
template<int NumChannels = 1, typename DataT = std::uint8_t, typename ComputeT = float>
class 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<DataT, 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 (same for both X and Y directions), border type and crop flag.
- Template Parameters
OtherComputeT – other type for computations
- Parameters
radius – kernel radius
sigma – sigma parameter of Gaussian filter
border – border type
crop – crop flag
-
template<typename OtherComputeT>
explicit gaussian_spec(std::size_t radius, const sigma_t<OtherComputeT> &sigma, border_types border = border_types::repl, crop_types crop = crop_types::on)# Construct Gaussian spec with given radius, 2-component sigma, border type, and crop flag.
- Template Parameters
OtherComputeT – other type for computations
- Parameters
radius – kernel radius
sigma – 2-component sigma parameter of Gaussian filter
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 (same for both X and Y directions), 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 filter
border_val – value for constant border
crop – crop flag
-
template<int OtherNumChannels, typename OtherDataT, typename OtherComputeT>
explicit gaussian_spec(std::size_t radius, const sigma_t<OtherComputeT> &sigma, const sycl::vec<OtherDataT, OtherNumChannels> &border_val, crop_types crop = crop_types::on)# Construct Gaussian spec with given radius, 2-component 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 – 2-component sigma parameter of Gaussian filter
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
-
const sigma_t<ComputeT> &get_sigma() const noexcept#
Returns 2-component sigma of Gaussian filter.
- Returns
the 2-component 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
Errors
compile-time memory layout check |
Indicates an error when image memory layout 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. |
|
Indicates an error when ROI sizes of the source image and the destination image are not equal. |
|
Indicates an error when one of the pitch values is not divisible by size of component data type in bytes. |
|
Indicates an error when border type is not supported. |
The code example below demonstrates how shall be called
oneapi::ipl::gaussian
:
using namespace oneapi;
sycl::queue queue;
ipl::shared_usm_allocator_t allocator{ queue };
const sycl::range<2> image_size{ height, width };
// Source 4-channel image data
ipl::image<ipl::layouts::channel4, std::uint8_t> src_image{ queue, p_image_data, image_size, allocator };
// Destination 4-channel image data
ipl::image<ipl::layouts::channel4, std::uint8_t> dst_image{ image_size, allocator };
const ipl::gaussian_spec spec{ 2 };
// Gaussian filter with kernel radius = 2 and sigma calculated
auto event = ipl::gaussian(queue, src_image, dst_image, spec);