Sobel Filter#

Filters an image using a Sobel filter.

Description

This function applies a Sobel filter to the source image with the 3x3 kernel size. Algorithm parameters must be set through the sobel_spec class. The values of border pixels may be assigned in accordance with the border type. The formulae below describe the algorithm for the 3x3 and 5x5 Sobel operators.

../_images/GUID-3491E1C0-BF2D-43A9-8AF4-9E61DD3CD418-low.jpg

3x3 Sobel operator#

../_images/GUID-11D6D318-97A3-4C81-B918-C6A2A929AD4D-low.jpg

5x5 Sobel operator#

where

  • A is the source image

  • * is the 2D convolution operator

  • Gx and Gy are horizontal and vertical magnitude of the source image, respectively

Sobel filter output G, as overall gradient magnitude, shall be generated through L1 and L2 normalization of Gx and Gy.

L1 normalization:

../_images/GUID-FC335369-33F6-4355-9010-204E3C0B4BFA-low.jpg

L2 normalization:

../_images/GUID-F857AF83-9416-4A6C-A37F-BD8218838A35-low.jpg

Headers

oneapi/ipl/filter/sobel.hpp

Syntax

template<typename ComputeT = float, typename SrcImageT, typename DstImageT>
sycl::event oneapi::ipl::sobel_3x3(sycl::queue &queue, SrcImageT &src, DstImageT &dst, const sobel_spec_t<SrcImageT::layout_v, typename SrcImageT::data_t> &spec = {}, const std::vector<sycl::event> &dependencies = {})#

Sobel filtering function.

Template Parameters
  • ComputeT – The type in which all calculations will be performed

  • SrcImageT – Source image type

  • DstImageT – Destination image type

Parameters
  • queue – SYCL queue object

  • src – Source image object

  • dst – Destination image object

  • spec – algorithmic specification

  • dependencies – SYCL event dependencies

Returns

SYCL event

Supported values for ComputeT:

float

double

half

v

v

x

Supported combinations for data types and layouts:

Data types/Layouts

plane

channel3

channel4

plane3

std::uint8_t

v

x

x

x

std::int8_t

v

x

x

x

std::uint16_t

v

x

x

x

std::int16_t

v

x

x

x

std::uint32_t

v

x

x

x

std::int32_t

v

x

x

x

float

v

x

x

x

double

v

x

x

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:

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

repl - Border is replicated from the edge pixels.

template<int NumChannels = 1, typename DataT = std::uint8_t>
class sobel_spec : public oneapi::ipl::border_spec_base<1, std::uint8_t>#

Sobel filter parameters.

Template Parameters
  • NumChannels – number of channels

  • DataT – the type of const border value

Public Types

using native_pixel_t = sycl::vec<DataT, NumChannels>#

Type alias for pixel type.

Public Functions

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 DataT*#

Returns the border value pointer.

Returns

border value pointer

Errors

compile-time layout check

Indicates an error when image layout is not supported (only plane for grayscale format is 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 exception

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 shall be called oneapi::ipl::sobel_3x3:

using namespace oneapi;

sycl::queue                 queue;
ipl::shared_usm_allocator_t allocator{ queue };
const sycl::range<2>        image_size{ height, width };

// Image representing source grayscale image
ipl::image<ipl::layouts::plane, std::uint8_t> src_image{ queue, p_image_data, image_size, allocator };
// Destination image with result of Sobel filtering
ipl::image<ipl::layouts::plane, std::uint8_t> dst_image{ image_size, allocator };

// Apply Sobel filter with 3x3 kernel
auto event = ipl::sobel_3x3(queue, src_image, dst_image);