Title: | Read and Write 'ImageJ' Region of Interest (ROI) Files |
---|---|
Description: | Provides functions to read and write 'ImageJ' (<https://imagej.net>) Region of Interest (ROI) files, to plot the ROIs and to convert them to 'spatstat' (<https://spatstat.org/>) spatial patterns. |
Authors: | David C Sterratt [aut, cph, cre], Mikko Vihtakari [aut, cph], Le Gao [aut, cph] |
Maintainer: | David C Sterratt <[email protected]> |
License: | GPL-3 |
Version: | 0.1.3 |
Built: | 2024-12-15 06:47:44 UTC |
Source: | https://github.com/davidcsterratt/rimagejroi |
Converts ijroi
and ijzip
objects to a list of spatstat.geom spatial patterns.
ij2spatstat( X, window = NULL, pattern.type = NULL, unitname = NULL, scale = 1, return.type = FALSE, convert.only = NULL )
ij2spatstat( X, window = NULL, pattern.type = NULL, unitname = NULL, scale = 1, return.type = FALSE, convert.only = NULL )
X |
|
window |
the window for returned spatial patterns. Can be an |
pattern.type |
a character string specifying the desired pattern type to be returned ( |
unitname |
Name of the unit of length for the resulting window(s) (see |
scale |
A numeric value defining the scale of photograph in pixels / |
return.type |
should the type of ROI object(s) be returned in addition to spatstat.geom spatial patterns? Defaults to |
convert.only |
a character vector specifying the |
The function converts ijroi
and ijzip
objects to spatstat.geom spatial patterns for further calculations with the objects. By default, areal types ("rect", "oval", "ELLIPSE", "polygon") are converted to owin
objects. Line types ("line" (including "ARROW"), "freeline", "polyline", "angle", "freehand" (excluding "ELLIPSE")) are converted to psp
objects and "point" types to ppp
objects.
Returns a list of spatstat.geom patterns of approperiate type (see 'Details'). If return.type = TRUE
returns a list with two levels specifying the spatstat.geom pattern and the ROI type.
Mikko Vihtakari
file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "ijzip.zip") x <- read.ijzip(file) ij2spatstat(x)
file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "ijzip.zip") x <- read.ijzip(file) ij2spatstat(x)
Plots ImageJ ROI objects using the 'base' graphics package.
## S3 method for class 'ijroi' plot(x, add = FALSE, xlab = "", ylab = "", main = "", asp = 1, ...)
## S3 method for class 'ijroi' plot(x, add = FALSE, xlab = "", ylab = "", main = "", asp = 1, ...)
x |
The |
add |
Whether to add to an existing plot. |
xlab |
a title for the x axis: |
ylab |
a title for the y axis: |
main |
an overall title for the plot: |
asp |
numeric defining the aspect ratio y/x: see |
... |
Additional parameters. |
ImageJ ROI objects created with following tools are plotted using following graphics commands:
Rectangle tool ("rect") rect
. Plotted based on coordinates.
Oval selections ("oval") polygon
. Plotted based on equation.
Freehand selections ("freehand") lines
. Plotted based on coordinates.
Elliptical selections ("freehand", "ELLIPSE") lines
. Plotted based on equation.
Point Tool and Multi-Point Tool ("point") points
. Plotted based on coordinates.
Straight Line ("line") lines
. Plotted based on coordinates.
Arrow tool ("line", "ARROW") arrows
. Plotted based on coordinates. Stroke width passed to lwd
argument.
Segmented Line ("polyline") lines
. Plotted based on coordinates.
Freehand Line ("freeline") lines
. Plotted based on coordinates.
All graphics allow the additional parameters from appropriate functions. Aspect ratio (asp
) is 1 by default leading to correct representation of ImageJ objects. If correct representation is not important, set asp = NA
to use the R base-graphics default setting.
David Sterratt, Mikko Vihtakari
read.ijroi
, read.ijzip
, plot.ijzip
# type 0 'polygon' ROIs are plotted using lines() file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "polygon.roi") x <- read.ijroi(file) plot(x, col = "red") # type 1 'rect' ROIs are plotted using rect() file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "rect.roi") x <- read.ijroi(file) plot(x, border = "red") # type 2 'oval' ROIs are plotted using polygon() file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "oval.roi") x <- read.ijroi(file) plot(x, border = "red") # type 3 'line' ROIs (among others listed in 'details') are plotted using lines() file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "line.roi") x <- read.ijroi(file) plot(x, col = "red") # type 3 arrows are a subtype of 'line'. Plotted using arrows(). The stroke width is # carried over. To change width, use lwd argument file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "arrow.roi") x <- read.ijroi(file) plot(x, col = "red") # type 4 'freeline' ROIs are plotted using lines() file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "freehand_line.roi") x <- read.ijroi(file) plot(x, col = "red") # type 5 'polyline' ROIs are plotted using lines() file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "segmented_line.roi") x <- read.ijroi(file) plot(x, col = "red") # type 7 'freehand' selection ROIs are plotted using lines() file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "freehand_selection.roi") x <- read.ijroi(file) plot(x, col = "red") # type 7 Objects created using 'Elliptical selections' tool are also saved as # 'freehand', but with subtype 'ELLIPSE'. The coordinates for this type are flawed # and plotting is done using equation for an ellipse file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "elliptical.roi") x <- read.ijroi(file) plot(x, border = "red") lines(x$coords[,1], x$coords[,2]) ## plotted based on coordinates. # type 10 'point' ROIs are plotted using points() file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "multi_point.roi") x <- read.ijroi(file) plot(x, col = "red") # If following is shown as a (round) circle, asp = 1 file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "circle.roi") x <- read.ijroi(file) plot(x, border = "red") # text is stored as type 'rect' with subtype 'TEXT'. Currently # only the outlining rectangle is returned file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "text.roi") x <- read.ijroi(file) plot(x, border = "red")
# type 0 'polygon' ROIs are plotted using lines() file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "polygon.roi") x <- read.ijroi(file) plot(x, col = "red") # type 1 'rect' ROIs are plotted using rect() file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "rect.roi") x <- read.ijroi(file) plot(x, border = "red") # type 2 'oval' ROIs are plotted using polygon() file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "oval.roi") x <- read.ijroi(file) plot(x, border = "red") # type 3 'line' ROIs (among others listed in 'details') are plotted using lines() file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "line.roi") x <- read.ijroi(file) plot(x, col = "red") # type 3 arrows are a subtype of 'line'. Plotted using arrows(). The stroke width is # carried over. To change width, use lwd argument file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "arrow.roi") x <- read.ijroi(file) plot(x, col = "red") # type 4 'freeline' ROIs are plotted using lines() file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "freehand_line.roi") x <- read.ijroi(file) plot(x, col = "red") # type 5 'polyline' ROIs are plotted using lines() file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "segmented_line.roi") x <- read.ijroi(file) plot(x, col = "red") # type 7 'freehand' selection ROIs are plotted using lines() file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "freehand_selection.roi") x <- read.ijroi(file) plot(x, col = "red") # type 7 Objects created using 'Elliptical selections' tool are also saved as # 'freehand', but with subtype 'ELLIPSE'. The coordinates for this type are flawed # and plotting is done using equation for an ellipse file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "elliptical.roi") x <- read.ijroi(file) plot(x, border = "red") lines(x$coords[,1], x$coords[,2]) ## plotted based on coordinates. # type 10 'point' ROIs are plotted using points() file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "multi_point.roi") x <- read.ijroi(file) plot(x, col = "red") # If following is shown as a (round) circle, asp = 1 file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "circle.roi") x <- read.ijroi(file) plot(x, border = "red") # text is stored as type 'rect' with subtype 'TEXT'. Currently # only the outlining rectangle is returned file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "text.roi") x <- read.ijroi(file) plot(x, border = "red")
Plots .zip files containing ImageJ ROI objects using the 'base' graphics package.
## S3 method for class 'ijzip' plot(x, add = FALSE, xlab = "", ylab = "", main = "", asp = 1, ...)
## S3 method for class 'ijzip' plot(x, add = FALSE, xlab = "", ylab = "", main = "", asp = 1, ...)
x |
The |
add |
Whether to add to an existing plot. |
xlab |
a title for the x axis: see |
ylab |
a title for the y axis: see |
main |
an overall title for the plot: see |
asp |
numeric defining the aspect ratio y/x: see |
... |
Arguments to be passed to methods, such as graphical parameters (see |
The function loops plot.ijroi
plotting function over all elements in x
. See plot.ijroi
for further details.
Mikko Vihtakari, David Sterratt
file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "ijzip.zip") x <- read.ijzip(file) plot(x)
file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "ijzip.zip") x <- read.ijzip(file) plot(x)
ijroi
objectsPrint ijroi
objects
## S3 method for class 'ijroi' print(x, all = FALSE, ...)
## S3 method for class 'ijroi' print(x, all = FALSE, ...)
x |
|
all |
logical indicating whether to print all information
from ijroi object as opposed to a subset of relevant information.
Defaults to |
... |
further arguments passed to |
Mikko Vihtakari, David Sterratt
Read an ImageJ ROI file. This returns a structure containing the ImageJ data.
read.ijroi(file, verbose = FALSE)
read.ijroi(file, verbose = FALSE)
file |
Name of ImageJ ROI file to read |
verbose |
Whether to report information |
A structure of class ijroi
containing the ROI information
David Sterratt
plot.ijroi
for plotting single ROI objects.
read.ijzip
for reading several ROI objects from .zip files.
library(png) path <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi") im <- as.raster(readPNG(file.path(path, "imagej-logo.png"))) plot(NA, NA, xlim=c(0, ncol(im)), ylim=c(nrow(im), 0), asp=1) rasterImage(im, 0, nrow(im), ncol(im), 0, interpolate=FALSE) r <- read.ijroi(file.path(path, "rect.roi")) plot(r, TRUE) r <- read.ijroi(file.path(path, "polygon.roi")) plot(r, TRUE) r <- read.ijroi(file.path(path, "oval.roi")) plot(r, TRUE)
library(png) path <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi") im <- as.raster(readPNG(file.path(path, "imagej-logo.png"))) plot(NA, NA, xlim=c(0, ncol(im)), ylim=c(nrow(im), 0), asp=1) rasterImage(im, 0, nrow(im), ncol(im), 0, interpolate=FALSE) r <- read.ijroi(file.path(path, "rect.roi")) plot(r, TRUE) r <- read.ijroi(file.path(path, "polygon.roi")) plot(r, TRUE) r <- read.ijroi(file.path(path, "oval.roi")) plot(r, TRUE)
A wrapper function, which reads a zip file containing ImageJ ROI files using read.ijroi
function.
read.ijzip(file, names = TRUE, list.files = FALSE, verbose = FALSE)
read.ijzip(file, names = TRUE, list.files = FALSE, verbose = FALSE)
file |
zip file containing a collection of ImageJ ROI files |
names |
Logical, indicating whether the ROI file names should be used as names for the elements in the list (see Return). If FALSE a sequence of names specifying the type of ROI is automatically generated. |
list.files |
logical, indicating whether a data.frame of ROI files in |
verbose |
Whether to report information (see |
An object of class ijzip
containing a list of the coordinates and types of ImageJ ROIs. Each element is named after option specified in names
.
Mikko Vihtakari
file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "ijzip.zip") x <- read.ijzip(file) plot(x)
file <- file.path(system.file(package = "RImageJROI"), "extdata", "ijroi", "ijzip.zip") x <- read.ijzip(file) plot(x)
Provides functions to read and write ImageJ (https://imagej.net/) Region of Interest (ROI) files, to plot the ROIs and to convert them as spatstat (https://spatstat.org/) spatial patterns.
ImageJ ROI files can be read into R using the
read.ijroi
and read.ijzip
functions,
resulting in ijroi
and ijzip
objects.
The objects can be plotted using generic
plot
command and converted to
spatstat.geom spatial patterns by using
ij2spatstat
function.
The ijroi
and ijzip
objects can be written to file
using the write.ijroi
and write.ijzip
functions.
Write an ImageJ ROI file.
write.ijroi(file, roi, verbose = TRUE)
write.ijroi(file, roi, verbose = TRUE)
file |
Name of ImageJ ROI file to write |
roi |
A structure of class |
verbose |
Whether to report information |
Le Gao
read.ijroi
for reading an ROI file
Write or add to a zip archive containing ImageJ ROI
files using the write.ijroi
function.
write.ijzip(file, roi, verbose = TRUE)
write.ijzip(file, roi, verbose = TRUE)
file |
zip archive to write that will contain a collection of ImageJ ROI files |
roi |
A list of ROIs |
verbose |
Whether to report information |
Le Gao, David Sterratt