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

View source: R/graphics.R

as.raster.ijtiff_imgR Documentation

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 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().

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.

Value

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

Examples

# 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)


ropensci/ijtiff documentation built on July 4, 2025, 3:50 a.m.