Functions for image resizing. More...
Functions | |
| SIMD_API void | SimdReduceColor2x2 (const uint8_t *src, size_t srcWidth, size_t srcHeight, size_t srcStride, uint8_t *dst, size_t dstWidth, size_t dstHeight, size_t dstStride, size_t channelCount) |
| Reduces a multi-channel 8-bit image by two using a 2x2 averaging window. More... | |
| SIMD_API void | SimdReduceGray2x2 (const uint8_t *src, size_t srcWidth, size_t srcHeight, size_t srcStride, uint8_t *dst, size_t dstWidth, size_t dstHeight, size_t dstStride) |
| Reduces an 8-bit gray image by two using a 2x2 averaging window. More... | |
| SIMD_API void | SimdReduceGray3x3 (const uint8_t *src, size_t srcWidth, size_t srcHeight, size_t srcStride, uint8_t *dst, size_t dstWidth, size_t dstHeight, size_t dstStride, int compensation) |
| Reduces an 8-bit gray image by two using a separable 3x3 Gaussian window. More... | |
| SIMD_API void | SimdReduceGray4x4 (const uint8_t *src, size_t srcWidth, size_t srcHeight, size_t srcStride, uint8_t *dst, size_t dstWidth, size_t dstHeight, size_t dstStride) |
| Reduces an 8-bit gray image by two using a separable 4x4 Gaussian-like window. More... | |
| SIMD_API void | SimdReduceGray5x5 (const uint8_t *src, size_t srcWidth, size_t srcHeight, size_t srcStride, uint8_t *dst, size_t dstWidth, size_t dstHeight, size_t dstStride, int compensation) |
| Reduces an 8-bit gray image by two using a separable 5x5 Gaussian window. More... | |
| SIMD_API void * | SimdResizerInit (size_t srcX, size_t srcY, size_t dstX, size_t dstY, size_t channels, SimdResizeChannelType type, SimdResizeMethodType method) |
| Creates a reusable image resize context. More... | |
| SIMD_API void | SimdResizerRun (const void *resizer, const uint8_t *src, size_t srcStride, uint8_t *dst, size_t dstStride) |
| Resizes one image using a context created by SimdResizerInit. More... | |
| SIMD_API void | SimdStretchGray2x2 (const uint8_t *src, size_t srcWidth, size_t srcHeight, size_t srcStride, uint8_t *dst, size_t dstWidth, size_t dstHeight, size_t dstStride) |
| Stretches an 8-bit gray image by two in both dimensions using pixel replication. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | ReduceGray2x2 (const View< A > &src, View< A >const &dst) |
| Performs reducing (in 2 times) and Gaussian blurring a 8-bit gray image with using window 2x2. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | ReduceGray3x3 (const View< A > &src, View< A > &dst, bool compensation=true) |
| Performs reducing (in 2 times) and Gaussian blurring a 8-bit gray image with using window 3x3. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | ReduceGray4x4 (const View< A > &src, View< A > &dst) |
| Performs reducing (in 2 times) and Gaussian blurring a 8-bit gray image with using window 4x4. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | ReduceGray5x5 (const View< A > &src, View< A > &dst, bool compensation=true) |
| Performs reducing (in 2 times) and Gaussian blurring a 8-bit gray image with using window 5x5. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | ReduceGray (const View< A > &src, View< A > &dst, ::SimdReduceType reduceType, bool compensation=true) |
| Performs reducing (in 2 times) and Gaussian blurring a 8-bit gray image. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | Reduce2x2 (const View< A > &src, View< A > &dst) |
| Performs reducing of image (in 2 times). More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | Resize (const View< A > &src, View< A > &dst, ::SimdResizeMethodType method=::SimdResizeMethodBilinear) |
| Performs resizing of image. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | Resize (const View< A > &src, View< A > &dst, const Point< ptrdiff_t > &size, ::SimdResizeMethodType method=::SimdResizeMethodBilinear) |
| Performs resizing of image. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | StretchGray2x2 (const View< A > &src, View< A > &dst) |
| Stretches input 8-bit gray image in two times. More... | |
Detailed Description
Functions for image resizing.
Enumeration Type Documentation
◆ SimdResizeChannelType
◆ SimdResizeMethodType
| enum SimdResizeMethodType |
Describes methods used in order to resize image.
| Enumerator | |
|---|---|
| SimdResizeMethodNearest | Nearest method. |
| SimdResizeMethodNearestPytorch | Nearest Pytorch compatible method. |
| SimdResizeMethodBilinear | Bilinear method. |
| SimdResizeMethodBilinearCaffe | Bilinear Caffe compatible method. It is relevant only for SimdResizeChannelFloat (32-bit float channel type). |
| SimdResizeMethodBilinearPytorch | Bilinear Pytorch compatible method. It is relevant only for SimdResizeChannelFloat (32-bit float channel type). |
| SimdResizeMethodBilinearOpenCv | Bilinear OpenCV compatible method. It is relevant only for SimdResizeChannelByte (8-bit integer channel type). |
| SimdResizeMethodBicubic | Bicubic method. |
| SimdResizeMethodArea | Area method. |
| SimdResizeMethodAreaFast | Area method for previously reduced in 2 times image. |
Function Documentation
◆ SimdReduceColor2x2()
| void SimdReduceColor2x2 | ( | const uint8_t * | src, |
| size_t | srcWidth, | ||
| size_t | srcHeight, | ||
| size_t | srcStride, | ||
| uint8_t * | dst, | ||
| size_t | dstWidth, | ||
| size_t | dstHeight, | ||
| size_t | dstStride, | ||
| size_t | channelCount | ||
| ) |
Reduces a multi-channel 8-bit image by two using a 2x2 averaging window.
The output size must be: dstWidth = (srcWidth + 1)/2, dstHeight = (srcHeight + 1)/2. The channel count must be 1, 2, 3 or 4. Border pixels are replicated when the source width or height is odd.
For all points:
sx0 = 2*x; sx1 = Min(2*x + 1, srcWidth - 1);
sy0 = 2*y; sy1 = Min(2*y + 1, srcHeight - 1);
dst[x, y, c] = (src[sx0, sy0, c] + src[sx1, sy0, c] +
src[sx0, sy1, c] + src[sx1, sy1, c] + 2)/4;
- Note
- This function has a C++ wrapper: Simd::Reduce2x2(const View<A>& src, View<A>& dst).
- Parameters
-
[in] src - a pointer to pixels data of the original input image. [in] srcWidth - a width of the input image. [in] srcHeight - a height of the input image. [in] srcStride - a row size of the input image. [out] dst - a pointer to pixels data of the reduced output image. [in] dstWidth - a width of the output image. [in] dstHeight - a height of the output image. [in] dstStride - a row size of the output image. [in] channelCount - a number of channels for input and output images.
◆ SimdReduceGray2x2()
| void SimdReduceGray2x2 | ( | const uint8_t * | src, |
| size_t | srcWidth, | ||
| size_t | srcHeight, | ||
| size_t | srcStride, | ||
| uint8_t * | dst, | ||
| size_t | dstWidth, | ||
| size_t | dstHeight, | ||
| size_t | dstStride | ||
| ) |
Reduces an 8-bit gray image by two using a 2x2 averaging window.
The output size must be: dstWidth = (srcWidth + 1)/2, dstHeight = (srcHeight + 1)/2. Border pixels are replicated when the source width or height is odd.
For all points:
sx0 = 2*x; sx1 = Min(2*x + 1, srcWidth - 1); sy0 = 2*y; sy1 = Min(2*y + 1, srcHeight - 1); dst[x, y] = (src[sx0, sy0] + src[sx1, sy0] + src[sx0, sy1] + src[sx1, sy1] + 2)/4;
- Note
- This function has a C++ wrapper: Simd::ReduceGray2x2(const View<A>& src, View<A>& dst).
- Parameters
-
[in] src - a pointer to pixels data of the original input image. [in] srcWidth - a width of the input image. [in] srcHeight - a height of the input image. [in] srcStride - a row size of the input image. [out] dst - a pointer to pixels data of the reduced output image. [in] dstWidth - a width of the output image. [in] dstHeight - a height of the output image. [in] dstStride - a row size of the output image.
◆ SimdReduceGray3x3()
| void SimdReduceGray3x3 | ( | const uint8_t * | src, |
| size_t | srcWidth, | ||
| size_t | srcHeight, | ||
| size_t | srcStride, | ||
| uint8_t * | dst, | ||
| size_t | dstWidth, | ||
| size_t | dstHeight, | ||
| size_t | dstStride, | ||
| int | compensation | ||
| ) |
Reduces an 8-bit gray image by two using a separable 3x3 Gaussian window.
The output size must be: dstWidth = (srcWidth + 1)/2, dstHeight = (srcHeight + 1)/2. The filter uses kernel [1 2 1] horizontally and vertically. Source coordinates outside the image are clamped to the nearest valid pixel. If compensation is non-zero, the sum is rounded by adding 8 before division by 16; otherwise it is truncated.
For every point:
k = [1, 2, 1]; sx(i) = Clamp(2*x + i - 1, 0, srcWidth - 1); sy(j) = Clamp(2*y + j - 1, 0, srcHeight - 1); sum = Sum(k[i]*k[j]*src[sx(i), sy(j)]), 0 <= i,j < 3; dst[x, y] = (sum + (compensation ? 8 : 0)) / 16;
- Note
- This function has a C++ wrapper: Simd::ReduceGray3x3(const View<A>& src, View<A>& dst, bool compensation).
- Parameters
-
[in] src - a pointer to pixels data of the original input image. [in] srcWidth - a width of the input image. [in] srcHeight - a height of the input image. [in] srcStride - a row size of the input image. [out] dst - a pointer to pixels data of the reduced output image. [in] dstWidth - a width of the output image. [in] dstHeight - a height of the output image. [in] dstStride - a row size of the output image. [in] compensation - a flag to enable rounding compensation before division.
◆ SimdReduceGray4x4()
| void SimdReduceGray4x4 | ( | const uint8_t * | src, |
| size_t | srcWidth, | ||
| size_t | srcHeight, | ||
| size_t | srcStride, | ||
| uint8_t * | dst, | ||
| size_t | dstWidth, | ||
| size_t | dstHeight, | ||
| size_t | dstStride | ||
| ) |
Reduces an 8-bit gray image by two using a separable 4x4 Gaussian-like window.
The output size must be: dstWidth = (srcWidth + 1)/2, dstHeight = (srcHeight + 1)/2. The filter uses kernel [1 3 3 1] horizontally and vertically and rounds by adding 32 before division by 64. Source coordinates outside the image are clamped to the nearest valid pixel.
For every point:
k = [1, 3, 3, 1]; sx(i) = Clamp(2*x + i - 1, 0, srcWidth - 1); sy(j) = Clamp(2*y + j - 1, 0, srcHeight - 1); sum = Sum(k[i]*k[j]*src[sx(i), sy(j)]), 0 <= i,j < 4; dst[x, y] = (sum + 32) / 64;
- Note
- This function has a C++ wrapper: Simd::ReduceGray4x4(const View<A>& src, View<A>& dst).
- Parameters
-
[in] src - a pointer to pixels data of the original input image. [in] srcWidth - a width of the input image. [in] srcHeight - a height of the input image. [in] srcStride - a row size of the input image. [out] dst - a pointer to pixels data of the reduced output image. [in] dstWidth - a width of the output image. [in] dstHeight - a height of the output image. [in] dstStride - a row size of the output image.
◆ SimdReduceGray5x5()
| void SimdReduceGray5x5 | ( | const uint8_t * | src, |
| size_t | srcWidth, | ||
| size_t | srcHeight, | ||
| size_t | srcStride, | ||
| uint8_t * | dst, | ||
| size_t | dstWidth, | ||
| size_t | dstHeight, | ||
| size_t | dstStride, | ||
| int | compensation | ||
| ) |
Reduces an 8-bit gray image by two using a separable 5x5 Gaussian window.
The output size must be: dstWidth = (srcWidth + 1)/2, dstHeight = (srcHeight + 1)/2. The filter uses kernel [1 4 6 4 1] horizontally and vertically. Source coordinates outside the image are clamped to the nearest valid pixel. If compensation is non-zero, the sum is rounded by adding 128 before division by 256; otherwise it is truncated.
For every point:
k = [1, 4, 6, 4, 1]; sx(i) = Clamp(2*x + i - 2, 0, srcWidth - 1); sy(j) = Clamp(2*y + j - 2, 0, srcHeight - 1); sum = Sum(k[i]*k[j]*src[sx(i), sy(j)]), 0 <= i,j < 5; dst[x, y] = (sum + (compensation ? 128 : 0)) / 256;
- Note
- This function has a C++ wrapper: Simd::ReduceGray5x5(const View<A>& src, View<A>& dst, bool compensation).
- Parameters
-
[in] src - a pointer to pixels data of the original input image. [in] srcWidth - a width of the input image. [in] srcHeight - a height of the input image. [in] srcStride - a row size of the input image. [out] dst - a pointer to pixels data of the reduced output image. [in] dstWidth - a width of the output image. [in] dstHeight - a height of the output image. [in] dstStride - a row size of the output image. [in] compensation - a flag to enable rounding compensation before division.
◆ SimdResizerInit()
| void * SimdResizerInit | ( | size_t | srcX, |
| size_t | srcY, | ||
| size_t | dstX, | ||
| size_t | dstY, | ||
| size_t | channels, | ||
| SimdResizeChannelType | type, | ||
| SimdResizeMethodType | method | ||
| ) |
Creates a reusable image resize context.
The context stores source size, destination size, channel count, channel type and resize method. It precomputes interpolation indices and coefficients used by SimdResizerRun. Supported combinations are selected from real implementations: nearest methods for all channel types; bilinear for byte, short, float and BFloat16 channels; OpenCV-compatible bilinear, bicubic and area methods for byte channels; Caffe and PyTorch bilinear variants for float and BFloat16 channels. Unsupported combinations return NULL.
Usage example (resize of RGBA64 image):
void * resizer = SimdResizerInit(srcX, srcY, dstX, dstY, 4, SimdResizeChannelShort, SimdResizeMethodBilinear);
if (resizer)
{
SimdResizerRun(resizer, (uint8_t*)src, srcStride, (uint8_t*)dst, dstStride);
SimdRelease(resizer);
}
- Parameters
-
[in] srcX - a width of the input image. [in] srcY - a height of the input image. [in] dstX - a width of the output image. [in] dstY - a height of the output image. [in] channels - a number of channels in input and output images. [in] type - a type of input and output image channel (see SimdResizeChannelType). [in] method - a resize method (see SimdResizeMethodType).
- Returns
- a pointer to resize context. On error or unsupported parameter combination it returns NULL. This pointer is used by function SimdResizerRun. It must be released with function SimdRelease.
◆ SimdResizerRun()
| void SimdResizerRun | ( | const void * | resizer, |
| const uint8_t * | src, | ||
| size_t | srcStride, | ||
| uint8_t * | dst, | ||
| size_t | dstStride | ||
| ) |
Resizes one image using a context created by SimdResizerInit.
The input and output images must have the sizes, channel count, channel type and resize method stored in resizer. Strides are specified in bytes. The context can be reused for multiple images with the same geometry and format parameters.
- Parameters
-
[in] resizer - a resize context. It must be created by function SimdResizerInit and released by function SimdRelease. [in] src - a pointer to pixels data of the original input image. [in] srcStride - a row size (in bytes) of the input image. [out] dst - a pointer to pixels data of the resized output image. [in] dstStride - a row size (in bytes) of the output image.
◆ SimdStretchGray2x2()
| void SimdStretchGray2x2 | ( | const uint8_t * | src, |
| size_t | srcWidth, | ||
| size_t | srcHeight, | ||
| size_t | srcStride, | ||
| uint8_t * | dst, | ||
| size_t | dstWidth, | ||
| size_t | dstHeight, | ||
| size_t | dstStride | ||
| ) |
Stretches an 8-bit gray image by two in both dimensions using pixel replication.
The output size must be exactly: dstWidth = 2*srcWidth, dstHeight = 2*srcHeight. For every source pixel:
dst[2*x + 0, 2*y + 0] = src[x, y]; dst[2*x + 1, 2*y + 0] = src[x, y]; dst[2*x + 0, 2*y + 1] = src[x, y]; dst[2*x + 1, 2*y + 1] = src[x, y];
- Note
- This function has a C++ wrappers: Simd::StretchGray2x2(const View<A>& src, View<A>& dst).
- Parameters
-
[in] src - a pointer to pixels data of the original input image. [in] srcWidth - a width of the input image. [in] srcHeight - a height of the input image. [in] srcStride - a row size of the input image in bytes. [out] dst - a pointer to pixels data of the stretched output image. [in] dstWidth - a width of the output image. [in] dstHeight - a height of the output image. [in] dstStride - a row size of the output image in bytes.
◆ ReduceGray2x2()
Performs reducing (in 2 times) and Gaussian blurring a 8-bit gray image with using window 2x2.
For input and output image must be performed: dst.width = (src.width + 1)/2, dst.height = (src.height + 1)/2.
For all points:
dst[x, y] = (src[2*x, 2*y] + src[2*x, 2*y + 1] + src[2*x + 1, 2*y] + src[2*x + 1, 2*y + 1] + 2)/4;
- Note
- This function is a C++ wrapper for function SimdReduceGray2x2.
- Parameters
-
[in] src - an original input image. [out] dst - a reduced output image.
◆ ReduceGray3x3()
Performs reducing (in 2 times) and Gaussian blurring a 8-bit gray image with using window 3x3.
For input and output image must be performed: dst.width = (src.width + 1)/2, dst.height = (src.height + 1)/2.
For every point:
dst[x, y] = (src[2*x-1, 2*y-1] + 2*src[2*x, 2*y-1] + src[2*x+1, 2*y-1] +
2*(src[2*x-1, 2*y] + 2*src[2*x, 2*y] + src[2*x+1, 2*y]) +
src[2*x-1, 2*y+1] + 2*src[2*x, 2*y+1] + src[2*x+1, 2*y+1] + compensation ? 8 : 0) / 16;
- Note
- This function is a C++ wrapper for function SimdReduceGray3x3.
- Parameters
-
[in] src - an original input image. [out] dst - a reduced output image. [in] compensation - a flag of compensation of rounding. It is equal to 'true' by default.
◆ ReduceGray4x4()
Performs reducing (in 2 times) and Gaussian blurring a 8-bit gray image with using window 4x4.
For input and output image must be performed: dst.width = (src.width + 1)/2, dst.height = (src.height + 1)/2.
For every point:
dst[x, y] = (src[2*x-1, 2*y-1] + 3*src[2*x, 2*y-1] + 3*src[2*x+1, 2*y-1] + src[2*x+2, 2*y-1]
3*(src[2*x-1, 2*y] + 3*src[2*x, 2*y] + 3*src[2*x+1, 2*y] + src[2*x+2, 2*y]) +
3*(src[2*x-1, 2*y+1] + 3*src[2*x, 2*y+1] + 3*src[2*x+1, 2*y+1] + src[2*x+2, 2*y+1]) +
src[2*x-1, 2*y+2] + 3*src[2*x, 2*y+2] + 3*src[2*x+1, 2*y+2] + src[2*x+2, 2*y+2] + 32) / 64;
- Note
- This function is a C++ wrapper for function SimdReduceGray4x4.
- Parameters
-
[in] src - an original input image. [out] dst - a reduced output image.
◆ ReduceGray5x5()
Performs reducing (in 2 times) and Gaussian blurring a 8-bit gray image with using window 5x5.
For input and output image must be performed: dst.width = (src.width + 1)/2, dst.height = (src.height + 1)/2.
For every point:
dst[x, y] = (
src[2*x-2, 2*y-2] + 4*src[2*x-1, 2*y-2] + 6*src[2*x, 2*y-2] + 4*src[2*x+1, 2*y-2] + src[2*x+2, 2*y-2] +
4*(src[2*x-2, 2*y-1] + 4*src[2*x-1, 2*y-1] + 6*src[2*x, 2*y-1] + 4*src[2*x+1, 2*y-1] + src[2*x+2, 2*y-1]) +
6*(src[2*x-2, 2*y] + 4*src[2*x-1, 2*y] + 6*src[2*x, 2*y] + 4*src[2*x+1, 2*y] + src[2*x+2, 2*y]) +
4*(src[2*x-2, 2*y+1] + 4*src[2*x-1, 2*y+1] + 6*src[2*x, 2*y+1] + 4*src[2*x+1, 2*y+1] + src[2*x+2, 2*y+1]) +
src[2*x-2, 2*y+2] + 4*src[2*x-1, 2*y+2] + 6*src[2*x, 2*y+2] + 4*src[2*x+1, 2*y+2] + src[2*x+2, 2*y+2] +
compensation ? 128 : 0) / 256;
- Note
- This function is a C++ wrapper for function SimdReduceGray5x5.
- Parameters
-
[in] src - an original input image. [out] dst - a reduced output image. [in] compensation - a flag of compensation of rounding. It is equal to 'true' by default.
◆ ReduceGray()
| void ReduceGray | ( | const View< A > & | src, |
| View< A > & | dst, | ||
| ::SimdReduceType | reduceType, | ||
| bool | compensation = true |
||
| ) |
Performs reducing (in 2 times) and Gaussian blurring a 8-bit gray image.
For input and output image must be performed: dst.width = (src.width + 1)/2, dst.height = (src.height + 1)/2.
- Parameters
-
[in] src - an original input image. [out] dst - a reduced output image. [in] reduceType - a type of function used for image reducing. [in] compensation - a flag of compensation of rounding. It is relevant only for SimdReduce3x3 and SimdReduce5x5. It is equal to 'true' by default.
◆ Reduce2x2()
Performs reducing of image (in 2 times).
For input and output image must be performed: dst.width = (src.width + 1)/2, dst.height = (src.height + 1)/2.
- Parameters
-
[in] src - an original input image. [out] dst - a reduced output image.
◆ Resize() [1/2]
| void Resize | ( | const View< A > & | src, |
| View< A > & | dst, | ||
| ::SimdResizeMethodType | method = ::SimdResizeMethodBilinear |
||
| ) |
Performs resizing of image.
All images must have the same format.
- Parameters
-
[in] src - an original input image. [out] dst - a resized output image. [in] method - a resizing method. By default it is equal to SimdResizeMethodBilinear.
◆ Resize() [2/2]
| void Resize | ( | const View< A > & | src, |
| View< A > & | dst, | ||
| const Point< ptrdiff_t > & | size, | ||
| ::SimdResizeMethodType | method = ::SimdResizeMethodBilinear |
||
| ) |
Performs resizing of image.
- Parameters
-
[in] src - an original input image. [out] dst - a resized output image. The input image can be the output. [in] size - a size of output image. [in] method - a resizing method. By default it is equal to SimdResizeMethodBilinear.
◆ StretchGray2x2()
Stretches input 8-bit gray image in two times.
- Note
- This function is a C++ wrapper for function SimdStretchGray2x2.
- Parameters
-
[in] src - an original input image. [out] dst - a stretched output image.