read_caim | R Documentation |
Reads a born-digital image (typically RGB-JPEG or RGB-TIFF) using
terra::rast()
and returns a terra::SpatRaster object. Optionally, it can
extract a rectangular region of interest (ROI) specified by the user.
read_caim(path = NULL, upper_left = NULL, width = NULL, height = NULL)
path |
character vector of length one. Path to an image file, including
extension. If |
upper_left |
numeric vector of length two. Pixel coordinates of the
upper-left corner of the ROI, in the format |
width , height |
numeric vector of length one. Size (in pixels) of the rectangular ROI to read. |
This function is intended for importing color hemispherical photographs, such
as those obtained with digital cameras equipped with fisheye lenses. For raw
image files (e.g., NEF, CR2), see read_caim_raw()
.
Internally, this is a wrapper around terra::rast()
, so support for image
formats depends on the capabilities of the terra
package.
If no arguments are provided, a sample image will be returned.
Numeric terra::SpatRaster, typically with layers named "Red"
,
"Green"
, and "Blue"
. If the file format or metadata prevents automatic
layer naming, names will be inferred and a warning may be issued.
To load a specific subregion from the image, use the arguments upper_left
,
width
, and height
. These are expressed in raster coordinates, similar to
a spreadsheet layout: columns first, then rows. In other words, specify
coordinates as c(column, row)
, not c(row, column)
, which is typical
in data.frame
objects.
While any image editor can be used to obtain these values, this function was tested with ImageJ, particularly the Fiji distribution. A recommended workflow:
Open the image in Fiji.
Draw a rectangular selection.
Go to Edit > Selection > Specify... to read upper_left
, width
, and height
.
The example image was created from a raw photograph taken with a Nikon Coolpix 5700 and a FC-E9 auxiliary lens, processed with the following code:
zenith_colrow <- c(1290, 988)/2 diameter <- 756 z <- zenith_image(diameter, lens("Nikon_FCE9")) a <- azimuth_image(z) m <- !is.na(z) caim <- read_caim_raw("DSCN4606.NEF") caim <- crop_caim(caim, zenith_colrow - diameter/2, diameter, diameter) caim <- correct_vignetting(caim, z, c(0.0638, -0.101)) caim <- c(mean(caim$Y, caim$M), caim$G, caim$C) caim <- fisheye_to_equidistant(caim, z, a, m, radius = 300, k = 1) write_caim(caim, "example.tif", 16)
write_caim()
path <- system.file("external/DSCN4500.JPG", package = "rcaiman")
zenith_colrow <- c(1276, 980)
diameter <- 756*2
caim <- read_caim(path, zenith_colrow - diameter/2, diameter, diameter)
plot(caim$Blue)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.