--- title: "Synthetic Regional Spectral Comparison" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Synthetic Regional Spectral Comparison} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- [![R-CMD-check](https://github.com/CTTIR/hyperspectR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/CTTIR/hyperspectR/actions/workflows/R-CMD-check.yaml) [![pkgdown](https://github.com/CTTIR/hyperspectR/actions/workflows/pkgdown.yaml/badge.svg)](https://cttir.github.io/hyperspectR/) [![CRAN status](https://www.r-pkg.org/badges/version/hyperspectR)](https://CRAN.R-project.org/package=hyperspectR) [![Codecov test coverage](https://codecov.io/gh/CTTIR/hyperspectR/branch/main/graph/badge.svg)](https://app.codecov.io/gh/CTTIR/hyperspectR?branch=main) [![CRAN downloads](https://cranlogs.r-pkg.org/badges/hyperspectR)](https://cran.r-project.org/package=hyperspectR) [![CRAN downloads total](https://cranlogs.r-pkg.org/badges/grand-total/hyperspectR)](https://cran.r-project.org/package=hyperspectR) [![License: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) ```{r, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 5 ) ``` ```{r setup} library(hyperspectR) ``` ## Scope This example compares regions in a synthetic image. The package has not been validated to diagnose compartment syndrome, detect ischemia, or replace clinical assessment. No clinical threshold is defined by these simulated outputs. ## Simulating a Demonstration Scene The region parameters vary synthetic spectral shapes. Their assigned values are simulation inputs, not established tissue oxygenation ground truth. ```{r} cube <- hs_simulate_cube(rows = 50, cols = 50, n_regions = 4, sto2_range = c(0.15, 0.9), seed = 123) ``` ## Tissue Oxygenation Mapping ```{r} sto2 <- hs_sto2(cube) hs_plot_index(sto2, title = "Research Hb fraction (%)", palette = "sto2") ``` The fitted fractions may disagree with simulation parameters because the simulator and reference inversion use different models. ## Perfusion Assessment ```{r} npi <- hs_npi(cube) hs_plot_index(npi, title = "NIR ratio (dimensionless)", palette = "perfusion") ``` ## Research Panel Overview ```{r fig.width=10, fig.height=4} hs_plot_clinical(cube, indices = c("sto2", "npi", "thi")) ``` ## ROI Comparison: Affected vs. Unaffected ```{r} roi_affected <- hs_roi_rect(cube, x_range = c(30, 50), y_range = c(30, 50)) roi_normal <- hs_roi_rect(cube, x_range = c(1, 20), y_range = c(1, 20)) stats_aff <- hs_roi_stats(cube, roi_affected) stats_norm <- hs_roi_stats(cube, roi_normal) library(ggplot2) ggplot() + geom_line(data = stats_norm, aes(x = wavelength, y = mean, color = "Normal"), linewidth = 0.8) + geom_line(data = stats_aff, aes(x = wavelength, y = mean, color = "Affected"), linewidth = 0.8) + scale_color_manual(values = c(Normal = "#2E86AB", Affected = "#E41A1C")) + labs(x = "Wavelength (nm)", y = "Reflectance", title = "Spectral Comparison: Normal vs. Affected Tissue", color = "") + theme_hsi() ``` This plot describes within-image spectral variation. Pixel SD is not a confidence interval for a population effect. For repeated measurements, define subjects as independent groups and use `hs_group_summary()` on prespecified ROI summaries.