Normalization

Normalization of an image.

Description

This function applies a normalization operation to the source image with the specified subtrahend and divisor with vector size corresponding to the number of image channels. Algorithm to compute kernel is described by formula below:

../_images/normalize.png

where

  • d is divisor

  • s is subtrahend

  • Ii,j is image pixel

  • INi,j is normalized image pixel

Headers

oneapi/ipl/misc/normalize.hpp

Syntax

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

Normalize image.

Uses a normalization with 2 arguments from spec parameter - sub and div: data[i] = (data[i] - sub) / div

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

  • Format – Source and destination image format

  • SrcDataT – Source image data type

  • DstDataT – Destination image data type

  • SrcAllocatorT – Source image allocator type

  • DstAllocatorT – Destination image allocator type

Parameters
  • queue – SYCL queue

  • src – source image

  • dst – destination image

  • spec – algorithm parameters

  • dependencies – dependencies

Returns

SYCL event

Supported values for ComputeT/DstDataT:

float

double

half

v

v

x

Supported combinations for SrcDataT/Formats:

SrcDataT/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 SrcDataT = std::uint8_t):

nv12

i420

x

x

Parameters

template<int NumChannels, typename ComputeT = float>
class oneapi::ipl::normalize_spec

Normalize parameters.

Uses a normalization with 2 arguments - sub and div: data[i] = (data[i] - sub) / div If the sub is normalized then the order of operations is inversed data[i] = data[i] / div - sub

Template Parameters
  • NumChannels – number of channels

  • ComputeT – the type for computations

Public Types

using value_t = sycl::vec<ComputeT, NumChannels>

Type alias for pixel value type.

Public Functions

normalize_spec() = default

Construct empty Normalize specification.

normalize_spec(const value_t &sub, const value_t &div)

Construct Normalize specification based on parameters.

Parameters
  • sub – subtrahend of normalization

  • div – divisor of nomalization

inline sycl::buffer<value_t, 1> &get_values() noexcept

Returns the reference to buffer with normalize parameters which can be passed to another kernel.

Returns

the reference to buffer with normalize parameters

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 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.

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

template <typename DataT>
using rgba_image_t = image<formats::rgba, DataT>;

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

rgba_image_t<std::uint8_t> src_image{ src_data_pointer, src_size };
rgba_image_t<std::uint8_t> dst_image{ src_size };
rgba_image_t<float>        norm_image{ src_size };
rgba_image_t<float>        denorm_image{ src_size };

sycl::float4 sub{ 127.5f };
sycl::float4 div{ 127.5f };

// Create a normalize arguments (buffer of 2 elements: 1st is sub, 2nd is div)
normalize_spec norm_spec{ sub, div };

// Create a de-normalize arguments (buffer of 2 elements: 1st is sub, 2nd is div)
normalize_spec denorm_spec{ -sub / div, sycl::float4{ 1.f } / div };

// Normalize image
(void)normalize(queue, src_image, norm_image, norm_spec);

// Denormalize image
(void)normalize(queue, norm_image, denorm_image, denorm_spec);

// Convert image
(void)copy(queue, denorm_image, dst_image);