cuvis.r provides R bindings to the Cubert CUVIS C SDK for reading, processing, and exporting hyperspectral imaging data from Cubert snapshot cameras. It mirrors the API of cuvis.python.
CUVIS_SDK environment variable to the SDK
install directoryThe SDK may be initialised only once per R process. Keep it active
for the whole batch, then shut down once. Restart R before another batch
after shutdown. macOS supports stub installation, not the vendor
runtime. Exports require a new or empty directory unless
overwrite = TRUE is explicitly requested.
Every cuvis.r session begins with cuvis_init() and ends
with cuvis_shutdown():
Cubert cameras store measurements in .cu3s session
files. Load one with cuvis_session():
Session files contain one or more measurements. Access them by index (1-based):
The hyperspectral data cube is returned as a 3D R array
[rows, cols, bands] with wavelength metadata attached:
# First, process to generate the cube
ctx <- cuvis_processing_context(session)
cuvis_reprocess(ctx, mesu, mode = "raw")
cube <- cuvis_get_cube(mesu)
dim(cube) # e.g., c(100, 100, 61)
attr(cube, "wavelengths") # wavelengths in nmYou can subset bands, compute means, or use standard R array operations:
# Mean value per band: the spectrum averaged over the whole image
band_means <- apply(cube, 3, mean, na.rm = TRUE)
# Extract a single band (e.g., band 30)
band <- 30
single_band <- cube[, , band]
# Show it as an image. The cube is indexed [row, col, band] and row 1 is the
# first image line, whereas image() draws the first index of a matrix along
# the x axis, starting at the bottom. Transpose the band and reverse the row
# axis so the picture is not rotated or mirrored; asp = 1 keeps pixels square.
# Yellow marks high values, dark purple low values (viridis).
image(
x = seq_len(ncol(single_band)), y = seq_len(nrow(single_band)),
z = t(single_band),
ylim = c(nrow(single_band) + 0.5, 0.5), asp = 1,
col = hcl.colors(64, "viridis"),
axes = FALSE, xlab = "", ylab = "",
main = sprintf("Band %d (%.0f nm)", band, attr(cube, "wavelengths")[band])
)vignette("cuvis-r-calibration") for the full
calibration workflow (dark/white references, reflectance
conversion)