Skip to contents

Reads an image from a TIFF file/content into a numeric array or list.

Usage

read_tif(path, frames = "all", list_safety = "error", msg = TRUE)

tif_read(path, frames = "all", list_safety = "error", msg = TRUE)

Arguments

path

A string. The path to the tiff file to read.

frames

Which frames do you want to read. Default all. To read the 2nd and 7th frames, use frames = c(2, 7).

list_safety

A string. This is for type safety of this function. Since returning a list is unlikely and probably unexpected, the default is to error. You can instead opt to throw a warning (list_safety = "warning") or to just return the list quietly (list_safety = "none").

msg

Print an informative message about the image being read?

Value

An object of class ijtiff_img or a list of ijtiff_imgs.

Details

TIFF files have the capability to store multiple images, each having multiple channels. Typically, these multiple images represent the sequential frames in a time-stack or z-stack of images and hence each of these images has the same dimension. If this is the case, they are all read into a single 4-dimensional array img where img is indexed as img[y, x, channel, frame] (where we have y, x to comply with the conventional row, col indexing of a matrix - it means that images displayed as arrays of numbers in the R console will have the correct orientation). However, it is possible that the images in the TIFF file have varying dimensions (most people have never seen this), in which case they are read in as a list of images, where again each element of the list is a 4-dimensional array img, indexed as img[y, x, channel, frame].

A (somewhat random) set of TIFF tags are attributed to the read image. These are IMAGEDEPTH, BITSPERSAMPLE, SAMPLESPERPIXEL, SAMPLEFORMAT, PLANARCONFIG, COMPRESSION, THRESHHOLDING, XRESOLUTION, YRESOLUTION, RESOLUTIONUNIT, INDEXED and ORIENTATION. More tags should be added in a subsequent version of this package. You can read about TIFF tags at https://www.awaresystems.be/imaging/tiff/tifftags.html.

TIFF images can have a wide range of internal representations, but only the most common in image processing are supported (8-bit, 16-bit and 32-bit integer and 32-bit float samples).

Note

  • 12-bit TIFFs are not supported.

  • There is no standard for packing order for TIFFs beyond 8-bit so we assume big-endian packing

.

See also

Author

Simon Urbanek wrote most of this code for the 'tiff' package. Rory Nolan lifted it from there and changed it around a bit for this 'ijtiff' package. Credit should be directed towards Lord Urbanek.

Examples

img <- read_tif(system.file("img", "Rlogo.tif", package = "ijtiff"))
#> Reading Rlogo.tif: an 8-bit, 76x100 pixel image of unsigned
#> integer type. Reading 4 channels and 1 frame . . .
#> Done.