GetBilinearTransform
Computes bilinear transform coefficients to map the source ROI to the quadrangle with the specified vertex coordinates.
Syntax
IppStatus ippiGetBilinearTransform(IppiRect
srcRoi
, const double
quad
[4][2], double
coeffs
[2][4]
);
Include Files
ippi.h
Domain Dependencies
Headers:
ippcore.h
,
ippvm.h
,
ipps.h
Libraries:
ippcore.lib
,
ippvm.lib
,
ipps.lib
Parameters
- srcRoi
- Region of interest in the source image (of theIppiRecttype).
- quad
- Vertex coordinates of the quadrangle, to which the source ROI is mapped by the bilinear transform function.
- coeffs
- Output array. Contains the target bilinear transform coefficients.
Description
This function operates with ROI (see ROI Processing in Geometric Transforms).
This function is used as a support function for
ippiWarpBilinear
. It computes the coefficientscoeffs
of thebilinear transform that maps the source rectangular ROI to the quadrangle with the specified vertex coordinates quad
.The first dimension [4] of the array
quad
[4][2] is equal to the number of vertices, and the second dimension [2] means x
and y
coordinates of the vertex. Quadrangle vertices have the following meaning:quad
[0] corresponds to the transformed top-left corner of the source ROI, quad
[1] corresponds to the transformed top-right corner of the source ROI, quad
[2] corresponds to the transformed bottom-right corner of the source ROI, quad
[3] corresponds to the transformed bottom-left corner of the source ROI.Return Values
- ippStsNoErr
- Indicates no error. Any other value indicates an error.
- ippStsSizeErr
- Indicates an error condition ifsrcRoihas a size field with zero or negative value.
- ippStsCoeffErr
- Indicates an error condition if coefficient values are invalid.
- ippStsRectErr
- Indicates an error condition if width or height of thesrcRoiis less than or equal to 1.
Example
/*******************************************************************************
* Copyright 2015-2021 Intel Corporation.
*
* This software and the related documents are Intel copyrighted materials, and
* your use of them is governed by the express license under which they were
* provided to you (License). Unless the License provides otherwise, you may not
* use, modify, copy, publish, distribute, disclose or transmit this software or
* the related documents without Intel's prior written permission.
*
* This software and the related documents are provided as is, with no express
* or implied warranties, other than those that are expressly stated in the
* License.
*******************************************************************************/
// A simple example of performing bilinear warping of an image
// using Intel(R) Integrated Primitives (Intel(R) IPP) functions:
// ippiWarpBilinearGetBufferSize
// ippiGetBilinearTransform
// ippiWarpBilinear_32f_C1R
// ippiWarpBilinearBack_32f_C1R
#include <stdio.h>
#include "ipp.h"
#define WIDTH 8 /* source image width */
#define HEIGHT 8 /* source image height */
/* Next two defines are created to simplify code reading and understanding */
#define EXIT_MAIN exitLine: /* Label for Exit */
#define check_sts(st) if((st) != ippStsNoErr) goto exitLine; /* Go to Exit if Intel(R) IPP function returned status different from ippStsNoErr */
static Ipp32f pSrc[WIDTH*HEIGHT] =/* Pointers to source images */
{
1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f,
1.f, 1.f, 1.f, 5.f, 5.f, 1.f, 1.f, 1.f,
1.f, 1.f, 5.f, 5.f, 5.f, 5.f, 1.f, 1.f,
1.f, 5.f, 5.f, 5.f, 5.f, 5.f, 5.f, 1.f,
1.f, 5.f, 5.f, 5.f, 5.f, 5.f, 5.f, 1.f,
1.f, 1.f, 5.f, 5.f, 5.f, 5.f, 1.f, 1.f,
1.f, 1.f, 1.f, 5.f, 5.f, 1.f, 1.f, 1.f,
1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f };
static const double quad[4][2] = /* Vertex coordinates of the quadrangle */
{
{ 1.0, 1.0 },
{ 8.0, 0.0 },
{ 6.0, 8.0 },
{ 2.0, 6.0 } };
/* Results of ippMalloc() are not validated because Intel(R) IPP functions perform bad arguments check and will return an appropriate status */
int main(void)
{
IppStatus status = ippStsNoErr;
IppiSize srcSize = { WIDTH, HEIGHT }; /* Size of source ROI in pixels */
IppiRect srcRoi = { 0, 0, WIDTH, HEIGHT };/* Region of interest in the source image */
int srcStep = WIDTH * sizeof(Ipp32f), dstStep = srcStep, dstbStep = srcStep; /* Steps, in bytes, through the source/destination/back destination images */
Ipp32f pDst[WIDTH*HEIGHT], pDstB[WIDTH*HEIGHT];/* Pointers to destination/back destination images */
IppiSize dstSize = { WIDTH, HEIGHT };
IppiRect dstbRoi = { 0, 0, WIDTH, HEIGHT }; /* Region of interest in the back destination image */
IppiRect dstRoi = { 0, 0, WIDTH, HEIGHT }; /* Region of interest in the destination image */
double coeffs[2][4] = {0};
int bufSize = 0, bufSizeB = 0; /* Work buffers size */
Ipp8u* pBuffer = NULL,*pBufferB = NULL;
check_sts( status = ippiSet_32f_C1R(2, pDst, srcStep, srcSize) )
check_sts( status = ippiSet_32f_C1R(3, pDstB, srcStep, srcSize) )
/* Computes bilinear transform matrix */
check_sts( status = ippiGetBilinearTransform(srcRoi, quad, (double(*)[4])coeffs) )
/* Computes the size of external buffer for bilinear transform */
check_sts( status = ippiWarpBilinearGetBufferSize(srcSize, srcRoi, dstRoi, ippWarpForward, coeffs, IPPI_INTER_NN, &bufSize) )
/* Computes the size of external buffer for Back bilinear transform */
check_sts( status = ippiWarpBilinearGetBufferSize(dstSize, dstRoi, dstbRoi, ippWarpBackward, coeffs, IPPI_INTER_NN, &bufSizeB) )
pBuffer = ippsMalloc_8u(bufSize);
pBufferB = ippsMalloc_8u(bufSizeB);
/* Performs bilinear warping of an image */
check_sts( status = ippiWarpBilinear_32f_C1R(pSrc, srcSize, srcStep, srcRoi, pDst, dstStep, dstRoi, coeffs, IPPI_INTER_NN, pBuffer) )
/* Performs an inverse bilinear warping of an image */
check_sts( status = ippiWarpBilinearBack_32f_C1R(pDst, dstSize, dstStep, dstRoi, pDstB, dstbStep, dstbRoi, coeffs, IPPI_INTER_NN, pBuffer) )
EXIT_MAIN
ippsFree(pBuffer);
ippsFree(pBufferB);
printf("Exit status %d (%s)\n", (int)status, ippGetStatusString(status));
return (int)status;
}