
Convert an ijtiff_img object to a raster object for plotting
Source:R/graphics.R
as.raster.ijtiff_img.Rd
This function converts an ijtiff_img object to a raster
object that can
be used with base R graphics functions. The function extracts the first frame
of the image and converts it to an RGB raster representation.
Usage
# S3 method for class 'ijtiff_img'
as.raster(x, ...)
Arguments
- x
An ijtiff_img object. This should be a 4D array with dimensions representing (y, x, channel, frame).
- ...
Passed to
graphics::plot.raster()
.
Value
A raster
object compatible with graphics::plot.raster()
. The
raster will represent the first frame of the input image.
Details
The function performs the following operations:
Extracts the first frame of the image
Checks for invalid values (all NA or negative values)
Determines the appropriate color scaling based on the image bit depth
Creates an RGB representation using the available channels
For single-channel images, a grayscale representation is created. For RGB images (3 channels), a full-color representation is created.
Examples
# Read a TIFF image
img <- read_tif(system.file("img", "Rlogo.tif", package = "ijtiff"))
#> Reading image from /usr/local/lib/R/site-library/ijtiff/img/Rlogo.tif
#> Reading an 8-bit, float image with dimensions 76x100x4x1 (y,x,channel,frame) . . .
# Convert to raster and plot
raster_img <- as.raster(img)
plot(raster_img)