WarpAffineNearest
Performs affine transformation on an image using the nearest-neighbor interpolation algorithm.
Before calling the WarpAffineNearest function, you need to call Init for initialization and call Set to initialize the destination image. Then call the main function of the WarpAffineNearest function, and finally call Release to release the related space.
The function interface is declared as follows:
- Initialization functions:
HmppResult HMPPI_WarpAffineNearestInit(HmppiSize srcSize, HmppiSize dstSize, double coeffs[2][3], double xCenter, double yCenter, double angle, HmppiWarpDirection direction, HmppiBorderType borderType, double borderValue, int smoothEdge, HmppiWarpPolicy** pSpec);
HmppResult HMPPI_Set_64f_C1R(double value, double *dst, HmppiSize dstSize);
- Main function:
HmppResult HMPPI_WarpAffineNearest_64f_C1R(const double *src, int srcStep, double *dst, int dstStep, HmppiPoint dstRoiOffset, HmppiSize dstRoiSize, const HmppiWarpPolicy *pSpec);
- Release function:
HmppResult HMPPI_WarpAffineNearestRelease_32f(HmppiWarpPolicy *policy);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the source image ROI |
The value cannot be NULL. |
Input |
srcStep |
Distance between starts of consecutive lines in the source image, in bytes |
The value must be zero or a positive integer. |
Input |
srcSize |
Size of the source image block |
Positive integer |
Input |
dst |
Pointer to the destination image ROI |
The value cannot be NULL. |
Input/Output |
dstStep |
Distance between starts of consecutive lines in the destination image, in bytes |
The value must be zero or a positive integer. |
Input |
dstRoiOffset |
Offset of the destination image block |
The value must be zero or a positive integer. |
Input |
dstRoiSize |
Size of the destination image block |
Positive integer |
Input |
coeffs |
Affine transformation coefficient |
The value cannot be NULL. |
Input |
xCenter |
X-coordinate of the rotation center |
Within the range of srcSize |
Input |
yCenter |
Y-coordinate of the rotation center |
Within the range of srcSize |
Input |
angle |
Rotation angle |
(-180, 180) |
Input |
direction |
Transformation direction |
HMPP_WARP_FORWARD: forward transformation HMPP_WARP_BACKWARD: backward transformation |
Input |
smoothEdge |
Edge smoothing flag |
0: Edge smoothing is not supported. |
Input |
borderType |
Border handling algorithm |
The following algorithms are supported: HMPPI_BORDER_REPL HMPPI_BORDER_IN_MEM HMPPI_BORDER_CONST HMPPI_BORDER_TRANSP |
Input |
borderValue |
Border value |
Border value when border is set to HMPPI_BORDER_CONST |
Input |
pSpec |
Pointer to the special structure |
The value cannot be NULL. |
Input/Output |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NO_OPERATION |
This is an alarm and no operation is performed. The width or height in srcSize and dstSize is 0. |
HMPP_STS_NULL_PTR_ERR |
A null pointer exists. |
HMPP_STS_MALLOC_FAILED |
Failed to allocate memory during pSpec initialization. |
HMPP_STS_SIZE_ERR |
The width or height in srcSize and dstSize is a negative value. |
Example
void WarpAffineNearestExample()
{
double angle = 45;
int xCenter = 1;
int yCenter = 1;
HmppiSize srcSize = {4, 4};
HmppiSize dstSize = {6, 6};
double src[] = {808.744309, 27255.923492, 14949.586917, 64065.764086, 59420.504942, 54345.804493, 2688.871018, 29176.134957, 35684.298050, 52137.708563, 15309.428011, 31545.366991, 9154.513170, 54118.967098, 34390.819908, 57073.143379};
int dstLen = dstSize.width * dstSize.height;
double *dst = HMPPS_Malloc_32f(dstLen);
HmppiPoint dstOffset = {0, 0};
HmppiWarpPolicy *pSpec = (HmppiWarpPolicy *)malloc(sizeof(HmppiWarpPolicy));
double pborder = src[0];
int smoothEdge = 0;
double coeffs[2][3];
HmppiWarpDirection direction = HMPP_WARP_FORWARD;
HmppiBorderType borderType = HMPPI_BORDER_REPL;
HmppResult result = HMPPI_WarpAffineNearestInit(srcSize, dstSize, coeffs, xCenter, yCenter, angle, direction, borderType, pborder, smoothEdge, pSpec);
printf("result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
result = HMPPI_Set_64f_C1R(0., dst, dstSize);
printf("result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
result = HMPPI_WarpAffineNearest_64f_C1R(src, srcSize.width, dst, dstSize.width, dstOffset, dstSize, pSpec);
printf("result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
for (int i = 0; i < dstLen; i++){
printf("%f ", dst[i]);
}
HMPPI_ResizeLinearRelease_32f(pSpec);
}
Output:
result = 0 result = 0 result = 0 27255.923492 14949.586917 2688.871018 31545.366991 31545.366991 57073.143379 808.744309 54345.804493 15309.428011 15309.428011 57073.143379 57073.143379 59420.504942 35684.29805 52137.708563 34390.819908 34390.819908 57073.143379 35684.29805 35684.29805 9154.51317 54118.967098 34390.819908 34390.819908 35684.29805 9154.51317 9154.51317 9154.51317 54118.967098 34390.819908 9154.51317 9154.51317 9154.51317 9154.51317 9154.51317 54118.967098