Affine Warp¶
Functions to apply affine transformations on 2D images.
-
enum
augpy
::
WarpScaleMode
¶ Enum whether to scale relative to the shortest or longest side of the image.
Values:
-
enumerator
WARP_SCALE_SHORTEST
¶ Scaling is relative to the shortest side of the image.
-
enumerator
WARP_SCALE_LONGEST
¶ Scaling is relative to the longest side of the image.
-
enumerator
-
int
augpy
::
make_affine_matrix
(py::buffer out, size_t source_height, size_t source_width, size_t target_height, size_t target_width, float angle, float scale, float aspect, float shifty, float shiftx, float sheary, float shearx, bool hmirror, bool vmirror, WarpScaleMode scale_mode, int max_supersampling)¶ Create a \(2 \times 3\) matrix for a set of affine transformations. This matrix is compatible with the warpAffine function of OpenCV with the WARP_INVERSE_MAP flag set.
Transforms are applied in the following order:
shear
scale & aspect ratio
horizontal & vertical mirror
rotation
horizontal & vertical shift
- Return
recommended supersampling factor for the warp
- Parameters
out
: output buffer that matrix is written to; must be a writeable \(2 \times 3\)float
buffersource_height
: \(h_s\) height of the image in pixelssource_width
: \(w_s\) width of the image in pixelstarget_height
: \(h_t\) height of the output canvas in pixelstarget_width
: \(w_t\) width of the output canvas in pixelsangle
: clockwise angle in degrees with image center as rotation axisscale
: scale factor relative to output size; 1 means fill target height or width wise depending onscale_mode
and whichever is longest/shortest; larger values will crop, smaller values leave empty space in the output canvasaspect
: controls the aspect ratio; 1 means same as input, values greater 1 increase the width and reduce the heightshifty
: shift the image in y direction (vertical); 0 centers the image on the output canvas; -1 means shift up as much as possible; 1 means shfit down as much as possible; the maximum distance to shift is \( max(scale \cdot h_s - h_t, h_t - scale \cdot h_s) \)shiftx
: same asshifty
, but in x direction (horizontal)sheary
: controls up/down shear; for every pixel in the x direction movesheary
pixels in y directionshearx
: same assheary
but controls left/right shearhmirror
: iftrue
flip image horizontallyvmirror
: iftrue
flip image verticallyscale_mode
: if WARP_SCALE_SHORTEST scale is relative to shortest side; this fills the output canvas, cropping the image if necessary; if WARP_SCALE_LONGEST scale is relative to longest side; this ensures the image is contained inside the output canvas, but leaves empty spacemax_supersampling
: upper limit for recommended supersampling
-
void
augpy
::
warp_affine
(CudaTensor *src, CudaTensor *dst, py::buffer matrix, CudaTensor *background, int supersampling)¶ Takes an image in channels-last format \( (H, W, C) \) and affine warps it into a given output tensor in channels-first format \( (C, H, W) \). Any blank canvas is filled with a background color. The warp is performed with bi-linear and supersampling.
- Parameters
src
: image tensordst
: target tensormatrix
: \(2 \times 3\)float
transformation matrix, see make_affine_matrix for detailsbackground
: background color to fill empty canvassupersampling
: supersampling factor, e.g., 3 means 9 samples are taken in a \(3 \times 3\) grid