Learn R Programming

ijtiff (version 3.1.3)

as.raster.ijtiff_img: Convert an ijtiff_img object to a raster object for plotting

Description

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 ijtiff_img
as.raster(x, ...)

Value

A raster object compatible with graphics::plot.raster(). The raster will represent the first frame of the input image.

Arguments

x

An ijtiff_img object. This should be a 4D array with dimensions representing (y, x, channel, frame).

...

Passed to graphics::plot.raster().

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

Run this code
# Read a TIFF image
img <- read_tif(system.file("img", "Rlogo.tif", package = "ijtiff"))

# Convert to raster and plot
raster_img <- as.raster(img)
plot(raster_img)

Run the code above in your browser using DataLab