read_bin: Write and read binarized images

View source: R/write_bin.R

read_binR Documentation

Write and read binarized images

Description

Wrapper functions around terra::rast() to read and write binary masks.

Usage

read_bin(path)

write_bin(bin, path)

Arguments

path

character vector of length one. File path to read or write. See examples.

bin

logical terra::SpatRaster with a single layer.

Details

write_bin() multiplies the input logical raster by 255 and writes the result as a GeoTIFF (GTiff) with datatype INT1U. Both write_bin() and read_bin() set the raster extent to terra::ext(0, ncol(r), 0, nrow(r)) and the CRS to EPSG:7589.

Value

See Functions

Functions

write_bin

Write a one-layer logical terra::SpatRaster to disk as a GeoTIFF (GTiff, INT1U). No return value.

read_bin

Read a file with values 255 and/or 0, such as the one produced by write_bin (see Details), and return a logical terra::SpatRaster (TRUE for 255, FALSE for 0).

See Also

read_caim(), write_caim().

Examples

## Not run: 
z <- zenith_image(1000, lens())
m <- !is.na(z)
my_file <- file.path(tempdir(), "mask.tif")
write_bin(m, my_file)
m_from_disk <- read_bin(my_file)
plot(m - m_from_disk)

## End(Not run)

rcaiman documentation built on Sept. 9, 2025, 5:42 p.m.