An experimental Python tool for hyperspectral seed image analysis. Inspired by (Reddy, et.al 2023, Sensors)[https://pmc.ncbi.nlm.nih.gov/articles/PMC9961513/]
- ENVI Format Support: Read and process ENVI format hyperspectral data from Specim SWIR cameras
- Automatic Calibration: White/dark reference correction with automatic bad pixel interpolation
- Intelligent Outlier Removal: Automatically detect and remove reference objects, calibration targets, and anomalies
- Advanced Preprocessing: Multiple spectral preprocessing methods (SNV, derivatives, baseline correction, etc.)
- Smart Segmentation: Multiple algorithms for accurate seed detection and isolation
- Spectral Extraction: Extract average spectral signatures from individual seeds
- Spatial Preservation: Maintain seed coordinates and morphological properties
- Comprehensive Visualizations: Auto-generate distribution, segmentation, and spectral plots
- Batch Processing: Process multiple datasets efficiently
- Flexible Configuration: YAML-based configuration system
- User-Friendly CLI: Intuitive command-line interface with rich output
- Python 3.10 or higher
- 8GB+ RAM recommended
pip install hyperseedpip install --no-cache-dir --force-reinstall https://github.com/nishad/hyperseed/archive/main.zip# Clone the repository
git clone https://github.com/nishad/hyperseed
cd hyperseed
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode
pip install -e ".[dev]"Analyze a single hyperspectral dataset:
hyperseed analyze dataset/sample_001 --output results.csv --export-plots# Optimal settings for seed analysis with visualizations
hyperseed analyze dataset/sample_data \
--output results.csv \
--min-pixels 50 \
--preprocess minimal \
--export-plots# Batch process multiple datasets
hyperseed batch dataset/ \
--output-dir results/ \
--min-pixels 50
# Disable outlier removal if needed
hyperseed analyze dataset/sample \
--output results.csv \
--no-outlier-removal
# Generate and use custom configuration
hyperseed config --output my_config.yaml --preset minimal
hyperseed analyze dataset/sample --config my_config.yamlHyperseed expects hyperspectral data in the following directory structure:
dataset/
βββ capture/
β βββ data.raw # Main hyperspectral data
β βββ data.hdr # ENVI header file
β βββ WHITEREF_data.raw # White reference
β βββ WHITEREF_data.hdr
β βββ DARKREF_data.raw # Dark reference
β βββ DARKREF_data.hdr
βββ calibrations/bpr/ # Optional bad pixel maps
β βββ bprmap.bpr
β βββ bprmap.hdr
βββ metadata/ # Optional metadata
βββ data.xml
Create a configuration file to customize the analysis pipeline:
# config.yaml
calibration:
clip_negative: true
clip_max: 1.0
preprocessing:
method: minimal # Options: minimal, standard, advanced, none
snv: false
smoothing: true
smoothing_window: 11
baseline_correction: false
segmentation:
algorithm: watershed # Options: threshold, watershed, connected, combined
min_pixels: 50
reject_overlapping: true
remove_outliers: true # Automatic outlier removal (enabled by default)
outlier_min_area: 50
outlier_max_area: 2000The tool generates multiple outputs:
seed_id,index,centroid_y,centroid_x,area,eccentricity,solidity,band_1000nm,band_1005nm,...
1,0,234.5,156.2,435,0.34,0.92,0.234,0.237,...
2,1,345.6,234.1,421,0.28,0.94,0.229,0.232,...*_distribution.png: Spatial and area distribution of seeds*_segmentation.png: Numbered seed visualization with boundaries*_spectra.png: Individual and mean spectral curves
- Data Loading: Read ENVI format hyperspectral data
- Calibration: Apply white/dark reference correction with bad pixel interpolation
- Preprocessing: Apply spectral preprocessing methods (minimal recommended for segmentation)
- Segmentation: Detect and isolate individual seeds using smart algorithms
- Validation: Filter seeds based on size and shape criteria
- Outlier Removal: Automatically remove reference objects and anomalies
- Extraction: Extract average spectrum for each valid seed
- Export: Save results with comprehensive spatial and spectral information
For detailed usage instructions, see the CLI Documentation.
# Run all tests
pytest
# Run with coverage
pytest --cov=hyperseed
# Run specific test module
pytest tests/test_preprocessing.py -v# Format code
black hyperseed/
# Check code style
ruff check hyperseed/
# Type checking
mypy hyperseed/from hyperseed import ENVIReader, Settings
from hyperseed.core.calibration import ReflectanceCalibrator
from hyperseed.core.preprocessing import PreprocessingPipeline
from hyperseed.core.segmentation import SeedSegmenter
from hyperseed.core.extraction import SpectralExtractor
# Load data
reader = ENVIReader("path/to/data.hdr")
data = reader.read_data()
wavelengths = reader.get_wavelengths()
# Calibrate (automatically handles bad pixel correction)
calibrator = ReflectanceCalibrator(clip_negative=True, clip_max=1.0)
calibrated, reader = calibrator.calibrate_from_directory("path/to/dataset")
# Preprocess
settings = Settings()
preprocessor = PreprocessingPipeline(settings.preprocessing)
processed = preprocessor.fit_transform(calibrated)
# Segment
segmenter = SeedSegmenter(settings.segmentation)
mask, n_seeds = segmenter.segment(processed)
# Extract spectra
extractor = SpectralExtractor()
results = extractor.extract(calibrated, mask, wavelengths)
# Save results
extractor.save_csv("results.csv")Logo icon "Sprouting Seed" by 4urbrand from The Noun Project, used under Creative Commons license.