Functions for Affine Warp of images. More...
Enumerations | |
| enum | SimdWarpAffineFlags { SimdWarpAffineDefault = 0 , SimdWarpAffineChannelByte = 0 , SimdWarpAffineChannelMask = 1 , SimdWarpAffineInterpNearest = 0 , SimdWarpAffineInterpBilinear = 2 , SimdWarpAffineInterpMask = 2 , SimdWarpAffineBorderConstant = 0 , SimdWarpAffineBorderTransparent = 4 , SimdWarpAffineBorderMask = 4 } |
Functions | |
| SIMD_API void * | SimdWarpAffineInit (size_t srcW, size_t srcH, size_t srcS, size_t dstW, size_t dstH, size_t dstS, size_t channels, const float *mat, SimdWarpAffineFlags flags, const uint8_t *border) |
| Creates warp affine context. More... | |
| SIMD_API void | SimdWarpAffineRun (const void *context, const uint8_t *src, uint8_t *dst) |
| Performs warp affine transformation for current image. More... | |
| template<template< class > class A> | |
| SIMD_INLINE void | WarpAffine (const View< A > &src, const float *mat, View< A > &dst, SimdWarpAffineFlags flags=(SimdWarpAffineFlags)(SimdWarpAffineChannelByte|SimdWarpAffineInterpBilinear|SimdWarpAffineBorderConstant), const uint8_t *border=NULL) |
| Performs warp affine transformation of an 8-bit image. More... | |
| SIMD_INLINE bool | InvertAffineTransform (const float *src, float *dst) |
| Inverts a 2x3 affine transform matrix. More... | |
Detailed Description
Functions for Affine Warp of images.
Enumeration Type Documentation
◆ SimdWarpAffineFlags
| enum SimdWarpAffineFlags |
Describes bit flags used by SimdWarpAffineInit.
Values are grouped into independent bit fields for channel type, interpolation method and border handling. Combine one value from each field with bitwise OR. Current implementations support 8-bit channels, nearest or bilinear interpolation, and constant or transparent border handling.
Function Documentation
◆ SimdWarpAffineInit()
| void * SimdWarpAffineInit | ( | size_t | srcW, |
| size_t | srcH, | ||
| size_t | srcS, | ||
| size_t | dstW, | ||
| size_t | dstH, | ||
| size_t | dstS, | ||
| size_t | channels, | ||
| const float * | mat, | ||
| SimdWarpAffineFlags | flags, | ||
| const uint8_t * | border | ||
| ) |
Creates warp affine context.
The input matrix describes forward affine transformation from source coordinates to destination coordinates:
dstX = srcX*mat[0] + srcY*mat[1] + mat[2]; dstY = srcX*mat[3] + srcY*mat[4] + mat[5];
The context stores inverse matrix and, during SimdWarpAffineRun, samples source image for every destination pixel. Supported data type is 8-bit unsigned channels, supported channel count is 1..4, and supported interpolation methods are nearest and bilinear. With SimdWarpAffineBorderConstant, pixels outside the source image are filled by border color (zero color when border is NULL). With SimdWarpAffineBorderTransparent, destination pixels outside transformed source area are left unchanged.
An using example (for BGR image):
float mat[2][3] = { { 1.0f, -1.0f, 0.0f }, { 1.0f, 1.0f, 0.0f } };
SimdWarpAffineFlags flags = SimdWarpAffineChannelByte | SimdWarpAffineInterpBilinear | SimdWarpAffineBorderConstant;
void* context = SimdWarpAffineInit(srcW, srcH, srcS, dstW, dstH, dstS, 3, mat, flags, NULL);
if (context)
{
SimdWarpAffineRun(context, src, dst);
SimdRelease(context);
}
- Note
- This function has a C++ wrapper Simd::WarpAffine(const View& src, const float * mat, View& dst, SimdWarpAffineFlags flags = SimdWarpAffineInterpBilinear | SimdWarpAffineBorderConstant, const uint8_t* border = NULL).
- Parameters
-
[in] srcW - a width of input image. [in] srcH - a height of input image. [in] srcS - a row size (in bytes) of the input image. [in] dstW - a width of output image. [in] dstH - a height of output image. [in] dstS - a row size (in bytes) of the output image. [in] channels - a channel number of input and output image. Its value must be in range [1..4]. [in] mat - a pointer to 2x3 matrix with coefficients of forward affine transformation. [in] flags - flags of algorithm parameters (channel type, interpolation method and border method). [in] border - a pointer to the array with color of border. The size of the array must be equal to channels. This parameter is actual for SimdWarpAffineBorderConstant flag. It can be NULL.
- Returns
- a pointer to warp affine context. On error it returns NULL. This pointer is used in functions SimdWarpAffineRun. It must be released with using of function SimdRelease.
◆ SimdWarpAffineRun()
| void SimdWarpAffineRun | ( | const void * | context, |
| const uint8_t * | src, | ||
| uint8_t * | dst | ||
| ) |
Performs warp affine transformation for current image.
The function uses parameters and precomputed data from the context created by SimdWarpAffineInit. If transparent border mode is used, destination image has to contain the background values before calling this function.
- Note
- This function has a C++ wrapper Simd::WarpAffine(const View& src, const float * mat, View& dst, SimdWarpAffineFlags flags = SimdWarpAffineInterpBilinear | SimdWarpAffineBorderConstant, const uint8_t* border = NULL).
- Parameters
-
[in] context - a warp affine context. It must be created by function SimdWarpAffineInit and released by function SimdRelease. [in] src - a pointer to pixels data of the original input image. [out] dst - a pointer to pixels data of the transformed output image.
◆ WarpAffine()
| void WarpAffine | ( | const View< A > & | src, |
| const float * | mat, | ||
| View< A > & | dst, | ||
| SimdWarpAffineFlags | flags = (SimdWarpAffineFlags)(SimdWarpAffineChannelByte | SimdWarpAffineInterpBilinear | SimdWarpAffineBorderConstant), |
||
| const uint8_t * | border = NULL |
||
| ) |
Performs warp affine transformation of an 8-bit image.
Input and output images must have the same pixel format with 8-bit channels (channel count 1..4). The input matrix describes forward affine transformation from source coordinates to destination coordinates:
dstX = srcX*mat[0] + srcY*mat[1] + mat[2]; dstY = srcX*mat[3] + srcY*mat[4] + mat[5];
The function inverts this matrix and samples the source image for every destination pixel. Supported interpolation methods are nearest and bilinear. With SimdWarpAffineBorderConstant, pixels outside the source image are filled by border color (zero color when border is NULL). With SimdWarpAffineBorderTransparent, destination pixels outside transformed source area are left unchanged, so dst must already contain the background values in that case.
- Note
- This function is a C++ wrapper for functions SimdWarpAffineInit and SimdWarpAffineRun.
- Parameters
-
[in] src - an input image with 8-bit channels. [in] mat - a pointer to 2x3 matrix with coefficients of forward affine transformation. [in,out] dst - an output image with the same format as src. It is also an input image when transparent border mode is used. [in] flags - flags of algorithm parameters (channel type, interpolation method and border method). By default is equal to SimdWarpAffineChannelByte | SimdWarpAffineInterpBilinear | SimdWarpAffineBorderConstant. [in] border - a pointer to the array with color of border. The size of the array must be equal to channel count. This parameter is actual for SimdWarpAffineBorderConstant flag. It can be NULL. By default is equal to NULL.
◆ InvertAffineTransform()
| bool InvertAffineTransform | ( | const float * | src, |
| float * | dst | ||
| ) |
Inverts a 2x3 affine transform matrix.
The input matrix describes forward affine transformation:
dstX = srcX*src[0] + srcY*src[1] + src[2]; dstY = srcX*src[3] + srcY*src[4] + src[5];
The output matrix dst contains coefficients of the inverse transform of the same form. If the determinant src[0]*src[4] - src[1]*src[3] is zero, the function returns false and fills dst with zeros.
- Parameters
-
[in] src - a pointer to input 2x3 matrix with coefficients of forward affine transform. [out] dst - a pointer to output 2x3 matrix with coefficients of inverse affine transform.
- Returns
- true if the matrix was inverted successfully; false if the matrix is singular.