An experimental tool for hyperspectral seed image analysis
Project description
Hyperseed ๐ฑ
An experimental Python tool for hyperspectral seed image analysis. Inspired by (Reddy, et.al 2023, Sensors)[https://pmc.ncbi.nlm.nih.gov/articles/PMC9961513/]
๐ Features
- 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 with parallel support
- Flexible Configuration: YAML-based configuration system
- User-Friendly CLI: Intuitive command-line interface with rich output
๐ Requirements
- Python 3.10 or higher
- 8GB+ RAM recommended
- Optional: GPU with Metal (macOS) or CUDA support for acceleration
๐ Installation
From Source
# Clone the repository
git clone [repository-url]
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]"
Using pip from Github Source
pip install --no-cache-dir --force-reinstall https://github.com/nishad/hyperseed/archive/main.zip
๐ Quick Start
Basic Usage
Analyze a single hyperspectral dataset:
hyperseed analyze dataset/sample_001 --output results.csv --export-plots
Recommended Usage
# Optimal settings for seed analysis with visualizations
hyperseed analyze dataset/sample_data \
--output results.csv \
--min-pixels 50 \
--preprocess minimal \
--export-plots
Advanced Usage
# Batch process multiple datasets in parallel
hyperseed batch dataset/ \
--output-dir results/ \
--min-pixels 50 \
--parallel 4
# 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.yaml
๐ Expected Data Structure
Hyperseed 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
โ๏ธ Configuration
Create a configuration file to customize the analysis pipeline:
# config.yaml
calibration:
apply_calibration: true
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: 2000
output:
format: csv
include_plots: true
include_coordinates: true
๐ Output Format
The tool generates multiple outputs:
CSV Spectra File
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,...
Visualization Plots (when using --export-plots)
*_distribution.png: Spatial and area distribution of seeds*_segmentation.png: Numbered seed visualization with boundaries*_spectra.png: Individual and mean spectral curves*_spectra_statistics.png: Statistical analysis of spectral variability
๐ฌ Processing Pipeline
- 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
Command-Line Documentation
For detailed usage instructions, see the CLI Documentation.
๐ ๏ธ Development
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=hyperseed
# Run specific test module
pytest tests/test_preprocessing.py -v
Code Quality
# Format code
black hyperseed/
# Check code style
ruff check hyperseed/
# Type checking
mypy hyperseed/
๐ API Usage
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")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hyperseed-0.1.0a3.tar.gz.
File metadata
- Download URL: hyperseed-0.1.0a3.tar.gz
- Upload date:
- Size: 81.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
320e61c0bfc522412407eec4f934d2a799e68ceead316a66da68e6836a43ef50
|
|
| MD5 |
39fea8539f8ac2de1bc383d6cfc6148e
|
|
| BLAKE2b-256 |
58f198e52113e0742379683e21332234b667c05f1332286ecb75a72b6b979556
|
File details
Details for the file hyperseed-0.1.0a3-py3-none-any.whl.
File metadata
- Download URL: hyperseed-0.1.0a3-py3-none-any.whl
- Upload date:
- Size: 101.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad2bc4b6bffe79bae359fde40d6b1f5c34c37bf2a11b9a418a2d8339647ec5d7
|
|
| MD5 |
830338ed24156ba6ac034ef5c7715ae0
|
|
| BLAKE2b-256 |
8330b3248479544db1bcd07a813169e8f5e96e9924519dfa83c41a48e15c5c49
|