EBImage (version 4.14.2)

resize: Spatial linear transformations


The following functions perform all spatial linear transforms: reflection, rotation, translation, resizing, and general affine transform.


flip(x) flop(x) rotate(x, angle, filter = "bilinear", output.dim, ...) translate(x, v, filter = "none", ...) resize(x, w, h, filter = "bilinear", output.dim = c(w, h), output.origin = c(0, 0), antialias = FALSE, ...)
affine(x, m, filter = c("bilinear", "none"), output.dim, bg.col = "black", antialias = TRUE)


An Image object or an array.
A numeric specifying the image rotation angle in degrees.
A vector of 2 numbers denoting the translation vector in pixels.
w, h
Width and height of the resized image. One of these arguments can be missing to enable proportional resizing.
A character string indicating the interpolating sampling filter. Valid values are 'none' or 'bilinear'. See Details.
A vector of 2 numbers indicating the dimension of the output image. For affine and translate the default is dim(x), for resize it equals c(w, h), and for rotate it defaults to the bounding box size of the rotated image.
A vector of 2 numbers indicating the output coordinates of the origin in pixels. Default is c(0, 0).
A 3x2 matrix describing the affine transformation. See Details.
Color used to fill the background pixels. The default is "black".
If TRUE, perform bilinear sampling at image edges using bg.col.
Arguments to be passed to the affine function, such as output.dim, bg.col or atialias.


An Image object or an array, containing the transformed version of x.


flip mirrors x around the image horizontal axis (vertical reflection). flop mirrors x around the image vertical axis (horizontal reflection).

rotate rotates the image clockwise by the specified angle around the origin. The rotation origin defaults to the center of the input image and can by changed by modifying the argument output.origin. resize resizes the image x to desired dimensions. Resizing center is changed by modifying the argument output.origin. Zooming, without changing the output dimension, is achieved by setting the arguments w and h to values different from output.dim.

affine returns the affine transformation of x, where pixels coordinates, denoted by the matrix px, are transformed to cbind(px, 1)%*%m.

All spatial transformations except flip and flop are based on the general affine transformation. Spatial interpolation can be one of the following types: none, also called nearest neighbor, where the interpolated pixel value equals to the closest pixel value, or bilinear, where the interpolated pixel value is computed by bilinear approximation of the 4 neighboring pixels. The bilinear filter gives smoother results.

See Also



Run this code
  x <- readImage(system.file("images", "sample.png", package="EBImage"))

  display( flip(x) )
  display( flop(x) ) 
  display( resize(x, 128) )
  display( rotate(x, 30) )
  display( translate(x, c(120, -20)) )

  m <- matrix(c(0.6, 0.2, 0, -0.2, 0.3, 300), nrow=3)
  display( affine(x, m) )

Run the code above in your browser using DataCamp Workspace