1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/imgData-methods.R
\name{imgData-methods}
\alias{imgData-methods}
\alias{getImg}
\alias{addImg}
\alias{rmvImg}
\alias{getImg,SpatialExperiment-method}
\alias{addImg,SpatialExperiment-method}
\alias{rmvImg,SpatialExperiment-method}
\alias{imgRaster,SpatialExperiment-method}
\alias{imgSource,SpatialExperiment-method}
\alias{rotateImg,SpatialExperiment-method}
\alias{mirrorImg,SpatialExperiment-method}
\title{Methods for handling image-related data}
\usage{
\S4method{getImg}{SpatialExperiment}(x, sample_id = NULL, image_id = NULL)
\S4method{addImg}{SpatialExperiment}(x, imageSource, scaleFactor, sample_id, image_id, load = TRUE)
\S4method{rmvImg}{SpatialExperiment}(x, sample_id = NULL, image_id = NULL)
\S4method{imgSource}{SpatialExperiment}(x, sample_id = NULL, image_id = NULL, path = FALSE)
\S4method{imgRaster}{SpatialExperiment}(x, sample_id = NULL, image_id = NULL)
\S4method{rotateImg}{SpatialExperiment}(x, sample_id = NULL, image_id = NULL, degrees = 90)
\S4method{mirrorImg}{SpatialExperiment}(x, sample_id = NULL, image_id = NULL, axis = c("h", "v"))
}
\arguments{
\item{x}{a \code{\link{SpatialExperiment}}}
\item{sample_id}{character string, \code{TRUE} or \code{NULL} specifying
sample/image identifier(s); here, \code{TRUE} is equivalent to all
samples/images and \code{NULL} specifies the first available entry (see details)}
\item{image_id}{see \code{sample_id}}
\item{imageSource}{a character string specifying an image file name
(.png, .jpg or .tif) or URL to source the image from}
\item{scaleFactor}{single numeric scale factor used to rescale spatial
coordinates according to the image's resolution}
\item{load}{logical; should the image(s) be
loaded into memory as a \code{raster} object?
if \code{FALSE}, will store the path/URL instead}
\item{path}{logical; for \code{RemoteSpatialImage}s, TRUE
returns the path to the image's cached file, and FALSE its URL.
For \code{Stored/LoadedSpatialImage}s, a path/NA is returned,
irrespective of \code{path}.}
\item{degrees}{single numeric
in +/-[0,90,...,360] specifying how many degrees to rotate.
A negative/positive value corresponds to counter-/clockwise rotation}
\item{axis}{character string specifying whether to mirror
horizontally (\code{"h"}) or vertically (\code{"v"})}
}
\value{
\code{getImg()} returns a single or list of \code{SpatialImage}(s).
\code{add/rmvImg()} return a \code{\link{SpatialExperiment}}
with modified \code{imgData}; specifically, they create/remove
an image entry (row) in the \code{imgData} \code{DataFrame}.
\code{imgRaster/Source()} access relevant data in the
\code{SpatialImage}(s) stored inside the \code{imgData}'s \code{data}
field. Depending on whether or not multiple entries are accessed,
a character string or vector is returned by \code{imgSource()}, and a
single or list of \code{raster} object(s) is returned by \code{imgRaster()}.
\code{rotate/mirrorImg()} return a \code{Loaded\link{SpatialImage}}
with modified a \code{raster} matrix.
}
\description{
The set of functions described below is designed to handle
the image-related data stored inside a \code{SpatialExperiment}'s
\code{imgData} \code{int_metadata} field. These include:
\itemize{
\item \code{getImg}, \code{addImg}, \code{rmvImg}
to retrieve/add/remove an image entry to/from
the \code{imgData} \code{DataFrame}
\item \code{imgSource}, \code{imgRaster}
to retrieve the path/URL and \code{raster} object,
respectively, associated with an image or set of images
}
}
\examples{
example(read10xVisium)
# 'SpatialImage' accession
(spi <- getImg(spe))
plot(imgRaster(spi))
# remove an image
imgData(spe)
spe <- rmvImg(spe,
sample_id = "section1",
image_id = "lowres")
imgData(spe)
# add an image
url <- "https://i.redd.it/3pw5uah7xo041.jpg"
spe <- addImg(spe,
sample_id = "section1",
image_id = "pomeranian",
imageSource = url,
scaleFactor = NA_real_,
load = FALSE)
# extract image
img <- imgRaster(spe,
sample_id = "section1",
image_id = "pomeranian")
plot(img)
###################
# transformations #
###################
# clockwise rotation
spe1 <- rotateImg(spe,
degrees = 90) # first image
spe2 <- rotateImg(spe,
sample_id = TRUE,
image_id = TRUE,
degrees = 90) # all images
par(mfrow = c(1, 3))
plot(imgRaster(spe))
plot(imgRaster(spe1))
plot(imgRaster(spe2))
# horizontal/vertical mirroring
spe1 <- mirrorImg(spe, axis = "h")
spe2 <- mirrorImg(spe, axis = "v")
par(mfrow = c(1, 3))
plot(imgRaster(spe))
plot(imgRaster(spe1))
plot(imgRaster(spe2))
}
\author{
Helena L. Crowell
}
|