resize {EBImage} | R Documentation

## Spatial linear transformations

### Description

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

### Usage

    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)

### Arguments

`x` | An `Image` object or an array.
`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 `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.
`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 `TRUE`, perform bilinear sampling at image edges using `bg.col`.
`...` | Arguments to be passed to `affine`, such as `filter`, `output.dim`, `bg.col` or `antialias`.

### Details

`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.

### Value

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

### Author(s)

Gregoire Pau, 2012

### See Also

`transpose`

### Examples

      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) )

[Package EBImage version 4.20.1 Index]