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, output.origin, ...) translate(x, v, filter = "none", ...) resize(x, w, h, 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)
x |
An |
angle |
A numeric specifying the image rotation angle in degrees. |
v |
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. |
filter |
A character string indicating the interpolating sampling filter. Valid values are 'none' or 'bilinear'. See Details. |
output.dim |
A vector of 2 numbers indicating the dimension of the output image.
For |
output.origin |
A vector of 2 numbers indicating the output coordinates of the origin in pixels. |
m |
A 3x2 matrix describing the affine transformation. See Details. |
bg.col |
Color used to fill the background pixels, defaults to "black". In the case of multi-frame images the value is recycled, and individual background for each frame can be specified by providing a vector. |
antialias |
If |
... |
Arguments to be passed to |
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 given angle around the
origin specified in output.origin
. If no output.origin
is
provided, the result will be centered in a recalculated bounding box unless
output.dim
is provided.
resize
scales the image x
to the desired dimensions.
The transformation origin can be specified in output.origin
.
For example, zooming about the output.origin
can be achieved by setting
output.dim
to a value different from c(w, h)
.
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 either
none
, also called nearest neighbor, where the resulting pixel value equals to
the closest pixel value, or bilinear
, where the new
pixel value is computed by bilinear approximation of the 4 neighboring pixels. The
bilinear
filter gives smoother results.
An Image
object or an array, containing the transformed version
of x
.
Gregoire Pau, 2012
x <- readImage(system.file("images", "sample.png", package="EBImage")) display(x) 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) )
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.