The functions in this section perform various geometrical transformations of 2D images. That is, they do not change the image content, but deform the pixel grid, and map this deformed grid to the destination image. In fact, to avoid sampling artifacts, the mapping is done in the reverse order, from destination to the source. That is, for each pixel
:math:`(x, y)`
of the destination image, the functions compute coordinates of the corresponding "donor" pixel in the source image and copy the pixel value, that is:
The actual implementations of the geometrical transformations, from the most generic
:ref:`Remap`
and to the simplest and the fastest
:ref:`Resize`
, need to solve the 2 main problems with the above formula:
#.
extrapolation of non-existing pixels. Similarly to the filtering functions, described in the previous section, for some
:math:`(x,y)`
one of
:math:`f_x(x,y)`
or
:math:`f_y(x,y)`
, or they both, may fall outside of the image, in which case some extrapolation method needs to be used. OpenCV provides the same selection of the extrapolation methods as in the filtering functions, but also an additional method
``BORDER_TRANSPARENT``
, which means that the corresponding pixels in the destination image will not be modified at all.
#.
interpolation of pixel values. Usually
:math:`f_x(x,y)`
and
:math:`f_y(x,y)`
are floating-point numbers (i.e.
:math:`\left<f_x, f_y\right>`
can be an affine or perspective transformation, or radial lens distortion correction etc.), so a pixel values at fractional coordinates needs to be retrieved. In the simplest case the coordinates can be just rounded to the nearest integer coordinates and the corresponding pixel used, which is called nearest-neighbor interpolation. However, a better result can be achieved by using more sophisticated
:param center:Center of the rotation in the source image
:param angle:The rotation angle in degrees. Positive values mean counter-clockwise rotation (the coordinate origin is assumed to be the top-left corner)
:param scale:Isotropic scale factor
:param mapMatrix:Pointer to the destination :math:`2\times 3` matrix
The values of pixels at non-integer coordinates are retrieved using bilinear interpolation. When the function needs pixels outside of the image, it uses replication border mode to reconstruct the values. Every channel of multiple-channel images is processed independently.
..cfunction:: void cvLogPolar( const CvArr* src, CvArr* dst, CvPoint2D32f center, double M, int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS )
Remaps an image to log-polar space.
:param src:Source image
:param dst:Destination image
:param center:The transformation center; where the output precision is maximal
:param M:Magnitude scale parameter. See below
:param flags:A combination of interpolation methods and the following optional flags:
***CV_WARP_FILL_OUTLIERS** fills all of the destination image pixels. If some of them correspond to outliers in the source image, they are set to zero
***CV_WARP_INVERSE_MAP** See below
The function
``cvLogPolar``
transforms the source image using the following transformation:
Forward transformation (
``CV_WARP_INVERSE_MAP``
is not set):
..math::
dst( \phi , \rho ) = src(x,y)
Inverse transformation (
``CV_WARP_INVERSE_MAP``
is set):
..math::
dst(x,y) = src( \phi , \rho )
where
..math::
\rho = M \cdot \log{\sqrt{x^2 + y^2}} , \phi =atan(y/x)
The function emulates the human "foveal" vision and can be used for fast scale and rotation-invariant template matching, for object tracking and so forth.
Applies a generic geometrical transformation to the image.
:param src:Source image
:param dst:Destination image
:param mapx:The map of x-coordinates (CV _ 32FC1 image)
:param mapy:The map of y-coordinates (CV _ 32FC1 image)
:param flags:A combination of interpolation method and the following optional flag(s):
***CV_WARP_FILL_OUTLIERS** fills all of the destination image pixels. If some of them correspond to outliers in the source image, they are set to ``fillval``
:param fillval:A value used to fill outliers
The function
``cvRemap``
transforms the source image using the specified map:
***CV_INTER_LINEAR** bilinear interpolation (used by default)
***CV_INTER_AREA** resampling using pixel area relation. It is the preferred method for image decimation that gives moire-free results. In terms of zooming it is similar to the ``CV_INTER_NN`` method
***CV_INTER_CUBIC** bicubic interpolation
The function
``cvResize``
resizes an image
``src``
so that it fits exactly into
``dst``
. If ROI is set, the function considers the ROI as supported.
:param flags:A combination of interpolation methods and the following optional flags:
***CV_WARP_FILL_OUTLIERS** fills all of the destination image pixels; if some of them correspond to outliers in the source image, they are set to ``fillval``
***CV_WARP_INVERSE_MAP** indicates that ``matrix`` is inversely
transformed from the destination image to the source and, thus, can be used
directly for pixel interpolation. Otherwise, the function finds
the inverse transform from ``mapMatrix``
:param fillval:A value used to fill outliers
The function
``cvWarpAffine``
transforms the source image using the specified matrix:
..math::
dst(x',y') = src(x,y)
where
..math::
\begin{matrix} \begin{bmatrix} x' \\ y' \end{bmatrix} = \texttt{mapMatrix} \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} & \mbox{if CV\_WARP\_INVERSE\_MAP is not set} \\ \begin{bmatrix} x \\ y \end{bmatrix} = \texttt{mapMatrix} \cdot \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} & \mbox{otherwise} \end{matrix}
The function is similar to
:ref:`GetQuadrangleSubPix`
but they are not exactly the same.
:ref:`WarpAffine`
requires input and output image have the same data type, has larger overhead (so it is not quite suitable for small images) and can leave part of destination image unchanged. While
:ref:`GetQuadrangleSubPix`
may extract quadrangles from 8-bit images into floating-point buffer, has smaller overhead and always changes the whole destination image content.
:param flags:A combination of interpolation methods and the following optional flags:
***CV_WARP_FILL_OUTLIERS** fills all of the destination image pixels; if some of them correspond to outliers in the source image, they are set to ``fillval``
***CV_WARP_INVERSE_MAP** indicates that ``matrix`` is inversely transformed from the destination image to the source and, thus, can be used directly for pixel interpolation. Otherwise, the function finds the inverse transform from ``mapMatrix``
:param fillval:A value used to fill outliers
The function
``cvWarpPerspective``
transforms the source image using the specified matrix:
..math::
\begin{matrix} \begin{bmatrix} x' \\ y' \end{bmatrix} = \texttt{mapMatrix} \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} & \mbox{if CV\_WARP\_INVERSE\_MAP is not set} \\ \begin{bmatrix} x \\ y \end{bmatrix} = \texttt{mapMatrix} \cdot \begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} & \mbox{otherwise} \end{matrix}