Resize with Bicubic Interpolation#

Changes an image size using interpolation with two-parameter cubic filters.

Description

This function changes an image size using interpolation with two-parameter cubic filters. The image size may be either reduced or increased in each direction, depending on the destination image size. This method must use source image intensities at sixteen pixels in the neighborhood of the point in the source image.

The two-parameter family of cubic filters have kernels of the form:

\[\begin{split}k(x) = {\dfrac {1}{6}}{ \begin{cases} (12 - 9B - 6C)|x|^{3} + (-18 + 12B + 6C)|x|^{2} + (6 - 2B) &\qquad {\text{, if }} |x| < 1 \\ (-B - 6C)|x|^{3} + (6B + 30C)|x|^{2} + (-12B - 48C)|x| + (8B + 24C) &\qquad {\text{, if }} 1 \leq |x| < 2 \\ 0 &\qquad {\text{otherwise}} \end{cases}}\end{split}\]

where B and C are two parameters; their variations give different approximation.

These interpolation methods additionally filter the output to improve quality of an image. To get more information about how B and C values affect the result, refer to ([Mitchell88]).

The filters can be replaced by a series of interpolations with the one-dimensional filter by calculating the color value P(d) from the color values of the four neighboring pixels P0, P1, P2, P3 using the follwing formula ([WikiMitchell23]):

\[\begin{split}P(d) = &\left((-{\dfrac {1}{6}}B - C)P_{0} + (-{\dfrac {3}{2}}B - C + 2)P_{1} + ({\dfrac {3}{2}}B + C - 2)P_{2} + ({\dfrac {1}{6}}B + C)P_{3}\right)d^{3} \\ + &\left(({\dfrac {1}{2}}B + 2C)P_{0} + (2B + C - 3)P_{1} + (-{\dfrac {5}{2}}B - 2C + 3)P_{2} - CP_{3}\right)d^{2} \\ + &\left((-{\dfrac {1}{2}}B - C)P_{0} + ({\dfrac {1}{2}}B + C)P_{2}\right)d \\ + &{\dfrac {1}{6}}BP_{0} + (-{\dfrac {1}{3}}B + 1)P_{1} + {\dfrac {1}{6}}BP_{2}\end{split}\]

where P lies between P1 and P2; d is the distance between P1 and P.

Cubic filter parameters B and C must be set through the factors b_factor and c_factor in the resize_bicubic_spec class.

The border pixels are processed in accordance with the border type. This function can operate with ROI (see Image Regions of Interest).

Headers

oneapi/ipl/transform/resize_bicubic.hpp

Syntax

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

Resize with the Bicubic interpolation method.

Template Parameters:
  • ComputeT – type to perform calculations

  • SrcImageT – Source image type

  • DstImageT – Destination image type

Parameters:
  • queue[in] SYCL queue

  • src[in] source image

  • dst[out] destination image

  • spec[in] algorithmic specification

  • dependencies[in] other events dependencies

Returns:

SYCL event, that represents a status of an operation it associated with

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 layout (only for std::uint8_t data type):

sub420

sub420i

Parameters

border type support

Type of border. Possible values are:

repl - Border is replicated from the edge pixels.

bicubic filter parameters support

Different combinations of b and c factors. Typical values are:

b_factor

c_factor

Cubic spline

0

0.5

Catmull-Rom spline

0

0.75

Unnamed

1/3

1/3

Mitchell-Netravali

1

0

B-spline

0.5

0.3

Special Two-Parameters Filter

template<typename ComputeT = float>
class resize_bicubic_spec#

Bicubic resize parameters.

Template Parameters:

ComputeT – the type for computations

Public Functions

resize_bicubic_spec() = default#

Construct bicubic resize specification with default values for Cumull-Rom ( \(b=0\), \(c=0.5\)) spline.

explicit resize_bicubic_spec(ComputeT b_factor, ComputeT c_factor, border_types border = border_types::repl, crop_types crop = crop_types::on)#

Construct bicubic resize specification.

Parameters:
  • b_factor – b factor of bicubic filter

  • c_factor – c factor of bicubic filter

  • border – border type

  • crop – crop flag

template<typename OtherComputeT>
resize_bicubic_spec(const resize_bicubic_spec<OtherComputeT> &other)#

Conversion constructor for bicubic resize specification.

Template Parameters:

OtherComputeT – the other type for computations

Parameters:

other – the other bicubic resize specification

explicit resize_bicubic_spec(border_types border, crop_types crop = crop_types::on)#

Construct bicubic resize specification from border type and crop flag.

Parameters:
  • border – border type

  • crop – crop flag

ComputeT get_b_factor() const noexcept#

Returns the b factor of bicubic filter.

Returns:

the b factor of bicubic filter

ComputeT get_c_factor() const noexcept#

Returns the c factor of bicubic filter.

Returns:

the c factor of bicubic 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 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 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.

unimplemented exception

Indicates an error when bicubic filter factors are not supported.

The code example below demonstrates how oneapi::ipl::resize_bicubic shall be 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 with x2 size
ipl::image<ipl::layouts::channel4, std::uint8_t> dst_image{ image_size * 2, allocator };

constexpr float                b_factor{ 0.0 };
constexpr float                c_factor{ 0.5 };
const ipl::resize_bicubic_spec spec{ b_factor, c_factor };

auto event = ipl::resize_bicubic(queue, src_image, dst_image, spec);