Grapes — MATLAB workflows for hyperspectral modelling, LODO robustness, VIP interpretation, and multispectral design
This repository contains the MATLAB workflows used to support the manuscript:
From hyperspectral modeling to multispectral design for grape maturity screening under date-wise validation
Zenodo DOI (all versions): 10.5281/zenodo.19105660
The code is organised as a sequence of reproducible objectives that follows the analytical logic of the study:
- berry-level spectral extraction from hyperspectral images;
- statistical analysis of chemical reference measurements;
- exploratory spectral structure analysis;
- supervised PLS-R modelling;
- date-aware robustness analysis under strict leave-one-date-out evaluation with minimal daily recalibration;
- VIP-based interpretability analysis;
- translation from hyperspectral models to deployable multispectral filter-set proposals.
The repository is intended to document the MATLAB-side analytical workflow underlying the manuscript, from image-derived berry spectra to model simplification and multispectral design.
matlab/
obj0_hsi_berry_extraction/
fx10_batch_berry_extraction_surgical_precision.m
fx17_batch_berry_extraction_hsv_sam_fullroi_compile.m
read_envi_cube.m
read_envi_info.m
README.md
obj1_chemical_responses/
obj1_chemical_ground_truth_statistics_lmm.m
README.md
obj2_exploratory_pca/
obj2_exploratory_pca.m
README.md
obj3_supervised_models/
obj3_plsr_berry_composition.m
README.md
obj4_lodo_robustness/
obj4_lodo_strict_kanchors.m
README.md
obj5_vip_interpretability/
obj5_vip_interpretability.m
README.md
obj6_multispectral_design/
obj6_multispectral_filterset_design.m
README.md
Each objective folder contains:
- one principal MATLAB script;
- one folder-specific
README.mddescribing purpose, inputs, outputs, and usage.
Scripts for extracting berry-level mean reflectance spectra from calibrated hyperspectral image cubes acquired with:
- Specim FX10 (VIS–NIR)
- Specim FX17 (SWIR)
This stage performs image-based berry segmentation, region selection, spectral extraction, and export of berry-level and sample-level spectral tables.
Statistical analysis of chemical ground-truth variables using linear mixed models and manuscript-oriented summaries.
Exploratory analysis of spectral structure across sensors and preprocessing strategies.
PLS-R modelling of berry-composition endpoints across sensor configurations and preprocessing pipelines.
Strict date-wise validation and minimal recalibration analysis using leave-one-date-out (LODO) evaluation and k-anchor intercept updating.
Trait-specific VIP-profile computation for selected deployable endpoints, including Top-5 VIP windows and manuscript-oriented figures.
Reduction of hyperspectral models to simulated multispectral filter sets using VIP-derived candidate bands, greedy subset selection, and repeated outer evaluation.
The repository is modular, but the intended analytical order is:
obj0 -> obj1 -> obj2 -> obj3 -> obj4 -> obj5 -> obj6
obj0generates the spectral inputs used downstream.obj1analyses the chemical reference data.obj2explores spectral structure.obj3fits the supervised models.obj4stress-tests selected models under date-wise validation.obj5computes VIP profiles for selected traits.obj6uses Objective 5 outputs to derive multispectral proposals.
The repository combines two input layers:
Used in Objective 0, with sample folders containing ENVI files (.hdr, .raw) and sample-specific white/dark references.
Used in Objectives 1–6, especially:
Matriz_CHEM_HSI_MASTER_96.xlsx
Depending on the objective, additional required worksheets or upstream files are described in the local README.md inside each folder.
Objective 6 requires the VIP workbook generated in Objective 5:
O5_VIP_Profiles_SelectedTraits.xlsx
The workflows were developed in MATLAB and require a standard desktop MATLAB installation.
Depending on the objective, the following MATLAB toolboxes are required:
- Image Processing Toolbox
- Statistics and Machine Learning Toolbox
- Signal Processing Toolbox
Objective 0 also requires:
- Image Processing Toolbox Model for Segment Anything Model (
imsegsam)
Objective 0 relies on the helper functions:
read_envi_info.mread_envi_cube.m
These are included in obj0_hsi_berry_extraction/.
Each objective is designed to be run from its own folder, with the necessary input files available in the current working directory or in the expected local structure described in the corresponding README.md.
Open MATLAB in the relevant objective folder and run the main script, for example:
obj3_plsr_berry_compositionor
obj5_vip_interpretabilityThe exact input expectations, output folders, and special notes are documented in the folder-specific README of each objective.
Most scripts create their own output folders automatically. In several objectives, output folder names intentionally preserve the historical project naming used during manuscript development.
For example, some scripts write results under directories such as:
Objetivo_3Objetivo_4Objetivo_5Objetivo_6
This is expected behaviour and reflects the original project workflow.
- The repository is structured around one principal script per objective.
- Folder-specific documentation is provided for all objectives.
- Objectives 3–6 are aligned with the manuscript’s modelling, robustness, interpretability, and multispectral-design sections.
- Objective 0 preserves the original operational extraction logic while exposing the workflow in a public-facing repository structure.
Because some workflows depend on project-specific file structures and naming conventions, the folder-level README.md files should be read before execution.
This repository supports the computational and analytical workflow behind the manuscript by linking:
- hyperspectral berry extraction,
- chemical ground-truth analysis,
- exploratory spectral analysis,
- supervised PLS-R modelling,
- date-aware robustness assessment,
- VIP-based interpretation,
- and multispectral simplification.
In that sense, the repository is not a generic hyperspectral toolbox, but a study-specific, publication-oriented workflow package.
For readers interested in reproducing the study logic rather than executing the full pipeline immediately, the recommended order is:
- read this main
README.md; - open the
README.mdinside each objective folder; - inspect
obj3,obj4,obj5, andobj6first if the main interest is modelling and deployment logic; - inspect
obj0first if the main interest is image-to-spectrum extraction.
If you use or adapt these workflows, please cite the current software version as:
Alonso, J. (2026). Grapes: MATLAB workflows for hyperspectral modelling, LODO robustness, VIP interpretability, and multispectral design (v1.0.2) [Computer software]. Zenodo. https://doi.org/10.5281/zenodo.19106485
For a repository-level citation covering all versions, use the concept DOI: https://doi.org/10.5281/zenodo.19105660
The associated publication citation can be added once formally available.
This repository was organised as a manuscript-oriented analytical package. Folder names, script names, and README files were cleaned for public-facing reproducibility while preserving the validated analytical logic used in the study.