resizeImage: Resize image

resizeImageR Documentation

Resize image

Description

Saves the instructions to use and store the resized version of an image to optimize resolution and memory usage.

Usage

resizeImage(object, ...)

## S4 method for signature 'SPATA2'
resizeImage(
  object,
  img_name,
  resize_fct,
  img_name_new = "{img_name}_{resize_fct}",
  apply_to_transl = TRUE,
  overwrite = FALSE,
  verbose = NULL
)

## S4 method for signature 'SpatialData'
resizeImage(
  object,
  img_name,
  resize_fct,
  img_name_new = "{img_name}_{resize_fct}",
  apply_to_transl = TRUE,
  overwrite = FALSE,
  verbose = TRUE,
  ...
)

## S4 method for signature 'HistoImage'
resizeImage(object, resize_fct, apply_to_transl = TRUE, verbose = TRUE, ...)

Arguments

object

An object of class SPATA2 or, in case of S4 generics, objects of classes for which a method has been defined.

...

Used to absorb deprecated arguments or functions.

img_name

Character value. The image to be resized.

resize_fct

The value should be a positive number between 0 and 1, representing the proportion by which the image should be resized. For example, 0.5 will resize the image to 50% of its original dimensions.

img_name_new

A character string or glue instruction, specifying the name for the resized image. If character, a new, additional image is registered. Set to FALSE if you want the resized image to be registered under the original image name.

Defaults to ⁠img_name_new = {img_name}_{resize_fct}⁠.

apply_to_transl

Logical. If TRUE, the resizing will also be applied to instructions on how to translate the image as set with alignImage() and/or alignImageInteractive(). (If you have not conducted any alignment so far, this won't have an effect.)

overwrite

Logical value. Must be TRUE to allow overwriting.

verbose

Logical. If TRUE, informative messages regarding the computational progress will be printed.

(Warning messages will always be printed.)

Details

This function sets instructions on how to deal with the size of the image. By default, any image registered in the SPATA2 object manually or during initiation with, for instance, initiateSpataObjectVisium() is registered with the original size (width x height) as stored on the disk on your device. R is not particularly efficient when it comes to handling images of a certain size. This resizing functionality allows you to adjust the size in which the image is handled when used in order to optimize the ratio between image resolution and computational performance.

Value

The updated input object, containing the added, removed or computed results.

See Also

loadImage(), writeImage()

Examples


library(SPATA2)
library(SPATAData)

object <- downloadSpataObject("UKF313T")

# contains two images
getImageNames(object)

# Resize the "hires" image by a factor of 0.5 and update the object
object <- resizeImage(object, img_name = "hires", resize_with = 0.5)

# Now the object contains three images
getImageNames(object)

# Note how both 'registered images' draw from the same directory
# This is possible since the instruction to resize the image is applied
# during loadImage()

getImageDir(object, img_name = "lowres") # dir 1
getImageDir(object, img_name = "hires") # dir 2
getImageDir(object, img_name = "hires_0.5") # dir 2

# ---> Check out writeImage() to store information of downloaded SPATA2 objects on your disk

# Show the results: plot the original and resized image
plotImage(object, img_name = "hires") +
plotImage(object, img_name = "hires_0.5") # by default, resized images are renamed


theMILOlab/SPATA2 documentation built on Feb. 8, 2025, 11:41 p.m.