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.

3x3 Sobel operator¶

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:
L2 normalization:
Headers
oneapi/ipl/filter/sobel.hpp
Syntax
-
template<typename ComputeT = float, formats Format, typename SrcDataT, typename SrcAllocatorT, typename DstDataT, typename DstAllocatorT>
sycl::event oneapi::ipl::sobel_3x3(sycl::queue &queue, image<Format, SrcDataT, SrcAllocatorT> &src, image<Format, DstDataT, DstAllocatorT> &dst, const sobel_spec_t<Format, SrcDataT> &spec = {}, const std::vector<sycl::event> &dependencies = {})¶ Sobel filtering function.
- Template Parameters
ComputeT – The type in which all calculations will be performed
Format – Source and destination image format
SrcDataT – Source image data type
SrcAllocatorT – Source image allocator type
DstDataT – Destination image data type
DstAllocatorT – Destination image allocator 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 SrcDataT/DstDataT/Formats:
SrcDataT/DstDataT/Formats |
plane |
rgb/bgr |
rgba/bgra |
rgbp |
---|---|---|---|---|
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 Format (only for SrcDataT/DstDataT = std::uint8_t
):
nv12 |
i420 |
---|---|
x |
x |
Parameters
border type support |
Type of border. Possible values are:
|
-
template<int NumChannels = 1, typename DataT = std::uint8_t>
class oneapi::ipl::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<std::uint8_t, 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 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 (only 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. |
|
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 to use the
oneapi::ipl::sobel_3x3
:
using image_t = image<formats::plane, std::uint8_t>;
// Create queue
sycl::queue queue{};
// Create allocator
shared_usm_allocator_t allocator{ queue };
// Image representing source grayscale image
image_t src_image{ queue, src_data_pointer, src_size, allocator };
// Destination image with result of Sobel filtering
image_t sobel_image{ src_size, allocator };
// Apply Sobel filter to whole image
// Sobel filter will use replicated border handling by default since explicit border specialization wasn't provided
(void)sobel_3x3(queue, src_image, sobel_image);