Cubert Camera Data Workflow

R-CMD-check pkgdown CRAN status Codecov test coverage CRAN downloads CRAN downloads total License: MIT Lifecycle: experimental

library(hyperspectR)

Overview

This vignette demonstrates the package’s ENVI and calibration interfaces using synthetic data. Device support tests use fixtures and SDK mocks; real camera sessions remain an external validation requirement. Read wavelength, FWHM, processing mode and acquisition settings from each recording. Do not infer them from a model name or this demonstration’s defaults.

Step 1: Reading ENVI Data

After exporting from CUVIS Export to ENVI format:

# Read the ENVI header + binary pair
cube <- hs_read_envi("path/to/measurement.hdr")

# Or use the auto-detect reader
cube <- hs_read_cube("path/to/measurement.hdr")

For this vignette we use synthetic data:

cube <- hs_simulate_cube(rows = 30, cols = 30, seed = 42)
print(cube)
#> 
#> ── hsi_cube ────────────────────────────────────────────────────────────────────
#> Dimensions: 30 rows x 30 cols x 61 bands
#> Wavelengths: 430-910 nm (61 bands)
#> FWHM: 25 nm (mean)
#> Mask: 900/900 valid pixels (100%)
#> Data range: [0.0198, 0.7306]
#> Metadata: camera, spectral_model, interpretation, processing_mode,
#> acquisition_time, region_map, sto2_ground_truth, seed

Step 2: Calibration

Apply dark current subtraction and white reference normalization:

# Simulate dark and white references
dark_data <- array(0.02, dim(cube$data))
white_data <- array(0.95, dim(cube$data))
dark <- hsi_cube(dark_data, cube$wavelengths)
white <- hsi_cube(white_data, cube$wavelengths)

# Demonstrate the calibration arithmetic (these references are synthetic)
calibrated <- hs_calibrate(cube, dark, white)
range(calibrated$data)
#> [1] 0.000000 0.764044

Step 3: Preprocessing

Apply spectral smoothing to reduce noise:

smoothed <- hs_smooth(calibrated, window = 5, poly = 2)
hs_plot_spectra(smoothed, pixels = "mean", show_sd = TRUE)

Step 4: Computing Indices

hs_plot_clinical(smoothed, indices = c("sto2", "npi", "thi"))

Step 5: Saving Results

# Save processed cube
hs_write_envi(smoothed, "path/to/processed_cube")

# Export index map as PNG
sto2 <- hs_sto2(smoothed)
hs_export_png(sto2, "path/to/sto2_map.png")