Skip to content

Interoperability between SpatialExperiment and EBImage #2

Description

@Bisaloo

I might add more info in the coming weeks but filing this here before I forget.

Initially reported by @sara-bz, with some extra info based on our follow up discussion:

SpatialExperiment contains a imgData slot that contains the image stored as the SpatialImage virtual class.

It could be nice to increase the interoperability with other Bioconductor packages, such as EBImage, by providing an easy way to apply EBImage functions to the SpatialImage objects.

The easiest way to achieve this is probably by providing a method to convert SpatialImage objects from SpatialExperiment into Image objects from EBImage.

In practice, it will likely be necessary to write separate methods for each subclass of SpatialImage:

  • for LoadedSpatialImage:
suppressPackageStartupMessages(library(SpatialExperiment))
example(read10xVisium, echo = FALSE)
#> Warning in read10xVisium(samples, sample_ids, type = "sparse", data = "raw", : 'read10xVisium' is deprecated.
#> Use 'VisiumIO::TENxVisium(List)' instead.
#> See help("Deprecated")
#> Warning in read10xVisium(samples2, sample_ids, type = "sparse", data = "raw", : 'read10xVisium' is deprecated.
#> Use 'VisiumIO::TENxVisium(List)' instead.
#> See help("Deprecated")

img <- getImg(spe)
class(img)
#> [1] "StoredSpatialImage"
#> attr(,"package")
#> [1] "SpatialExperiment"

plot(imgRaster(spe))

rgb_img <- img |> 
  imgRaster() |> 
  grDevices::col2rgb() |> 
  t()
ebimage_img <- array(rgb_img / 256, dim = c(rev(dim(img)), 3)) |> 
  EBImage::Image(colormode = "Color")

plot(ebimage_img)

Created on 2026-03-20 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions