write_tif: Write images in TIFF format

Description Usage Arguments Value Author(s) See Also Examples

View source: R/write.R

Description

Write images into a TIFF file.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
write_tif(
  img,
  path,
  bits_per_sample = "auto",
  compression = "none",
  overwrite = FALSE,
  msg = TRUE
)

tif_write(
  img,
  path,
  bits_per_sample = "auto",
  compression = "none",
  overwrite = FALSE,
  msg = TRUE
)

Arguments

img

An array representing the image.

  • For a single-plane, grayscale image, use a matrix img[y, x].

  • For a multi-plane, grayscale image, use a 3-dimensional array img[y, x, plane].

  • For a multi-channel, single-plane image, use a 4-dimensional array with a redundant 4th slot img[y, x, channel, ] (see ijtiff_img 'Examples' for an example).

  • For a multi-channel, multi-plane image, use a 4-dimensional array img[y, x, channel, plane].

path

file name or a raw vector

bits_per_sample

number of bits per sample (numeric scalar). Supported values are 8, 16, and 32. The default "auto" automatically picks the smallest workable value based on the maximum element in img. For example, if the maximum element in img is 789, then 16-bit will be chosen because 789 is greater than 2 ^ 8 - 1 but less than or equal to 2 ^ 16 - 1.

compression

A string, the desired compression algorithm. Must be one of "none", "LZW", "PackBits", "RLE", "JPEG", "deflate" or "Zip". If you want compression but don't know which one to go for, I recommend "Zip", it gives a large file size reduction and it's lossless. Note that "deflate" and "Zip" are the same thing. Avoid using "JPEG" compression in a TIFF file if you can; I've noticed it can be buggy.

overwrite

If writing the image would overwrite a file, do you want to proceed?

msg

Print an informative message about the image being written?

Value

The input img (invisibly).

Author(s)

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.

See Also

read_tif()

Examples

1
2
3
4
5
6
img <- read_tif(system.file("img", "Rlogo.tif", package = "ijtiff"))
temp_dir <- tempdir()
write_tif(img, paste0(temp_dir, "/", "Rlogo"))
img <- matrix(1:4, nrow = 2)
write_tif(img, paste0(temp_dir, "/", "tiny2x2"))
list.files(temp_dir, pattern = "tif$")

Example output

Reading Rlogo.tif: an 8-bit, 76x100 pixel image of unsigned
integer type. Reading 4 channels and 1 frame . . .
 Done.
Writing Rlogo.tif: an 8-bit, 76x100 pixel image of unsigned
integer type with 4 channels and 1 frame . . .
 Done.
Writing tiny2x2.tif: an 8-bit, 2x2 pixel image of unsigned
integer type with 1 channel and 1 frame . . .
 Done.
[1] "Rlogo.tif"   "tiny2x2.tif"

ijtiff documentation built on June 28, 2021, 9:07 a.m.