
Apply translations
ImageTranslate.Rd
This function takes an magick-image
object as input and applies translations
defined by the xy_offset
argument. The output image dimensions will remain the same
as the input image dimensions, meaning that the transformation might result in cropping
the image.
Arguments
- im
An image of class
magick-image
- xy_offset
A numeric vector of length 2 providing the offsets along the x- and y-axis given as pixels. These values should not exceed the image dimensions.
See also
Other transforms:
CoordAndImageTransform()
,
CoordMirror()
,
CoordTransform()
,
RigidTransformImages()
,
RunAlignment()
Examples
library(magick)
library(semla)
lowresimagefile <- system.file("extdata/mousebrain/spatial",
"tissue_lowres_image.jpg",
package = "semla")
im <- image_read(lowresimagefile)
# move image 100 pixels to the right and 100 pixels down
im_transformed <- ImageTranslate(im, xy_offset = c(100, 100))
im_transformed
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 png 565 600 sRGB TRUE 0 +72x+72
# move image 100 pixels to the left and 20 pixels up
im_transformed <- ImageTranslate(im, xy_offset = c(-100, 20))
im_transformed
#> # A tibble: 1 × 7
#> format width height colorspace matte filesize density
#> <chr> <int> <int> <chr> <lgl> <int> <chr>
#> 1 png 565 600 sRGB TRUE 0 +72x+72