Skip to contents

warpAffine applies an affine transformation to an image.

Usage

warpAffine(
  image,
  warp_matrix,
  interp_mode = "linear",
  inverse_map = TRUE,
  border_type = "constant",
  border_color = "black",
  target = "new",
  output_size = dim(image)[1:2]
)

Arguments

image

An Image object.

warp_matrix

A 2x3 numeric matrix.

interp_mode

A character string indicating the interpolation method to be used. It can be any of the following:

  • "nearest":nearest neighbor interpolation.

  • "linear" (the default):bilinear interpolation.

  • "cubic":bicubic interpolation.

  • "area":resampling using pixel area relation. It may be a preferred method for image decimation, as it gives moiré-free results, but when the image is zoomed, it is similar to the nearest neighbor method.

  • "lanczos4":Lanczos interpolation over 8x8 neighborhood.

  • "linear_exact":bit exact bilinear interpolation.

inverse_map

A logical. TRUE if warp_matrix represents an inverse transformation. If FALSE, warp_matrix will be inverted.

border_type

A character string indicating the extrapolation method to use when filling empty pixels created during the transformation. It can be any of the following:

  • "constant" (the default):iiiiii|abcdefgh|iiiiii with i specified by border_value.

  • "replicate":aaaaaa|abcdefgh|hhhhhh.

  • "reflect":fedcba|abcdefgh|hgfedc.

  • "wrap":cdefgh|abcdefgh|abcdef.

  • "reflect_101":gfedcb|abcdefgh|gfedcb.

  • "transparent":uvwxyz|abcdefgh|ijklmn.

border_color

A value or vector of any kind of R color specification compatible with col2bgr representing the color of the border (default: "black").

target

The location where the results should be stored. It can take 3 values:

  • "new":a new Image object is created and the results are stored inside (the default).

  • "self":the results are stored back into image (faster but destructive).

  • An Image object:the results are stored in another existing Image object. This is fast and will not replace the content of image but will replace that of target. Note that target must have the same bit depth and number of channels as image but can have different dimensions.

output_size

If target="new", a 2-elements vector indicating the number of rows and columns of the output image (defaults to the dimensions of image).

Value

If target="new", the function returns an Image

object. If target="self", the function returns nothing and modifies

image in place. If target is an Image object, the function returns nothing and modifies that Image object in place.

Author

Simon Garnier, garnier@njit.edu

Examples

file1 <- system.file("sample_img/balloon1.png", package = "Rvision")
file2 <- system.file("sample_img/balloon2.png", package = "Rvision")
balloon1 <- changeColorSpace(image(file1), "GRAY")
balloon2 <- changeColorSpace(image(file2), "GRAY")
ecc <- findTransformORB(balloon1, balloon2)
balloon2_transformed <- warpAffine(balloon2, ecc)