Img-set-SpatialExperiment-method: Image setter

Img<-,SpatialExperiment-methodR Documentation

Image setter

Description

Modify or replace images stored in a SpatialExperiment object. This is different from addImg which adds the image from files and can't replace existing images, which is there to be consistent with SpatialExperiment. This setter here can replace existing images with another object that inherits from VirtualSpatialImage, including SpatRasterImage, BioFormatsImage, and ExtImage.

Usage

## S4 replacement method for signature 'SpatialExperiment'
Img(x, sample_id = 1L, image_id, scale_fct = 1) <- value

Arguments

x

A SpatialExperiment object, which includes SFE.

sample_id

Which sample the image is associated with. Use sampleIDs to get sample IDs present in the SFE object.

image_id

Image ID, such as "lowres" and "hires" for Visium data and "DAPI" and "PolyT" for Vizgen MERFISH data.

scale_fct

Scale factor to convert pixels in lower resolution to those in the full resolution. Only relevant to image classes implemented in SpatialExperiment but not SpatialFeatureExperiment because the spatial extent of images in SFE takes precedence.

value

New version of image to add, must inherit from VirtualSpatialImage.

Value

SFE object with the new image added.

Examples

library(EBImage)
library(SFEData)
library(RBioFormats)
fp <- tempfile()
fn <- XeniumOutput("v2", file_path = fp)
# Weirdly the first time I get the null pointer error
try(sfe <- readXenium(fn))
sfe <- readXenium(fn)
img <- getImg(sfe) |> toExtImage(resolution = 1L)
img <- img[,,1] > 500
Img(sfe, image_id = "mask") <- img
imageIDs(sfe)
unlink(fn, recursive = TRUE)


pachterlab/SpatialFeatureExperiment documentation built on Dec. 20, 2024, 3:41 a.m.