Median Filter#

Filters an image using a median filter.

Description

This function applies a median filter to the source image with the specified kernel radius. Algorithm parameters are set through the median_spec class. The values of border pixels are determined by the border type. The median filter kernel sets each pixel in the destination buffer as the median value of all source pixel values from the neighborhood of the processed pixel.

Headers

oneapi/ipl/filter/median.hpp

Syntax

template<typename ComputeT = float, typename SrcImageT, typename DstImageT>
sycl::event oneapi::ipl::median(sycl::queue &queue, SrcImageT &src, DstImageT &dst, const median_spec &spec, const typename SrcImageT::pixel_t &border_val = {}, const std::vector<sycl::event> &dependencies = {})#

Median 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

  • border_val – border value

  • dependencies – dependencies

Returns:

SYCL event

Supported values for ComputeT:

float

double

half

Supported combinations for DataT/Layouts:

DataT/Layouts

plane

channel3

channel4

plane3

std::uint8_t

std::int8_t

std::uint16_t

std::int16_t

std::uint32_t

std::int32_t

float

double

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

sub420

sub420i

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.

class median_spec#

Median filter parameters.

Public Functions

median_spec(const median_spec &other)#

Conversion constructor for Median filter specification.

Parameters:

other – the other Median filter specification

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

Construct Median filter spec from given radius, border type and crop flag.

Parameters:
  • radius – kernel radius

  • border – border type

  • crop – crop flag

std::size_t get_radius() const noexcept#

Returns the radius of Median filter.

Returns:

the radius of Median filter

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 the image data type is not supported.

compile-time compute data type check

Indicates an error when the compute data type is not supported.

invalid_argument exception

Indicates an error when the 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 the size of the component data type in bytes.

invalid_argument exception

Indicates an error when the median kernel radius is equal to zero.

unimplemented exception

Indicates an error when border type is not supported.

The code example below demonstrates how oneapi::ipl::median is called:

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::median_spec spec{ 2 };

// Median filter with kernel radius = 2
auto event = ipl::median(queue, src_image, dst_image, spec);