高光谱图像分类与分析工具包
一个全面的高光谱图像处理、分类和光谱分析工具包,具有GUI就绪架构。
🌟 功能特性
🔬 光谱分析
- 光谱指数计算: 计算各种植被、矿物和水体指数
- 自定义公式支持: 定义和计算自定义光谱指数
- 多格式支持: 处理CSV、ENVI(.hdr/.dat)和其他光谱数据格式
🤖 机器学习模型
- 传统模型: 线性回归、岭回归、LASSO、弹性网络、贝叶斯岭回归
- 集成方法: 随机森林、梯度提升、XGBoost、LightGBM、AdaBoost
- 神经网络: MLP、LSTM、GRU(支持TensorFlow/PyTorch)
- 专业模型: 支持向量回归、高斯过程、KNN
🖼️ 图像处理
- 空间滤波: 均值、中值、高斯和双边滤波
- 形态学滤波: 开运算、闭运算、腐蚀、膨胀等
- 多波段支持: 处理单个波段或整个高光谱数据立方体
- 格式保持: 保持原始数据类型和数值范围
📊 降维分析
- 主成分分析 (PCA): 最大化方差的线性降维
- 独立成分分析 (ICA): 基于统计独立的信号分离
- 因子分析 (FA): 基于潜在因子的降维方法
- 线性判别分析 (LDA): 有监督的类别可分性最大化
- 流形学习: MDS、Isomap、LLE、t-SNE 等非线性降维
- 自动推荐: 根据数据类型和规模推荐最适合的方法
🎯 图像分割
- 阈值分割: 固定阈值、直方图双峰法、迭代法、Otsu法、ISODATA
- 自适应分割: 基于局部区域统计的自适应阈值
- 批量处理: 支持多方法多波段的批量分割
- 参数调优: 丰富的参数配置选项
⚡ 边缘检测
- 经典算子: Sobel、Scharr、Laplacian 算子
- 高级方法: Laplacian of Gaussian (LoG)、Canny 算子
- 参数可调: 每个方法都有丰富的参数配置选项
- 预处理: 支持高斯模糊预处理以减少噪声
- 多尺度: 支持不同尺度参数的边缘检测
🎯 GUI就绪架构
- 配置驱动: 集中化参数管理和验证
- 模块化设计: 业务逻辑与参数输入完全解耦
- 错误处理: 全面的验证和用户友好的错误消息
📋 系统要求
系统配置
- Python 3.8 或更高版本
- 4GB+ RAM(推荐大型数据集使用8GB+)
- GPU 支持(可选,用于深度学习模型)
依赖包
核心依赖包(完整列表见 requirements.txt):
numpy>=1.21.0
pandas>=1.3.0
scikit-learn>=1.0.0
matplotlib>=3.5.0
xgboost>=1.5.0
lightgbm>=3.3.0
可选依赖包:
tensorflow或torch用于深度学习模型spectral用于ENVI文件处理opencv-python用于图像滤波
🚀 安装指南
1. 克隆仓库
git clone http://git.iris-rs.cn/zhanghuilai/HSI.git
cd HSI
2. 创建虚拟环境(推荐)
python -m venv hyperspectral_env
source hyperspectral_env/bin/activate # Windows: hyperspectral_env\Scripts\activate
3. 安装依赖包
pip install -r requirements.txt
4. 根据需要安装可选依赖包
# 深度学习支持
pip install tensorflow # 或 torch
# ENVI文件处理
pip install spectral
# 开发环境
pip install pytest jupyter
📖 使用方法
基础用法
# 1. 降维分析
from Dimensionality_Reduction_method.dimensionality_reduction import HyperspectralDimReduction, DimensionalityReductionConfig
config = DimensionalityReductionConfig(
input_path="hyperspectral_data.hdr",
method='pca',
n_components=5,
output_dir='results'
)
reducer = HyperspectralDimReduction(config)
reducer.load_data()
reduced_data, band_names = reducer.apply_dim_reduction()
reducer.save_results(reduced_data, band_names, 'pca_result.dat', 'pca')
# 2. 图像分割
from segment_method.threshold_Segment import ThresholdSegmenter, ThresholdSegmentationConfig
seg_config = ThresholdSegmentationConfig(
input_path="hyperspectral_data.hdr",
band_index=50,
method='otsu',
output_dir='segmentation_results'
)
segmenter = ThresholdSegmenter(seg_config)
segmenter.load_data()
segmented_data, threshold = segmenter.apply_segmentation()
segmenter.save_results(segmented_data, threshold, 'otsu_result.dat', 'otsu')
# 3. 边缘检测
from edge_detect_method.edge_detect import EdgeDetector, EdgeDetectionConfig
edge_config = EdgeDetectionConfig(
input_path="hyperspectral_data.hdr",
band_index=30,
method='canny',
output_dir='edge_results'
)
detector = EdgeDetector(edge_config)
detector.load_data()
edge_data, info = detector.apply_edge_detection()
detector.save_results(edge_data, info, 'canny_result.dat', 'canny')
新功能使用示例
# 降维分析 - 批量处理多种方法
from Dimensionality_Reduction_method.dimensionality_reduction import HyperspectralDimReduction, DimensionalityReductionConfig
config = DimensionalityReductionConfig(
input_path="data.hdr",
output_dir="dim_reduction_results"
)
reducer = HyperspectralDimReduction(config)
reducer.load_data()
# 批量应用多种降维方法
methods = ['pca', 'ica', 'fa', 'lda'] # 如果有标签
components = [5, 5, 5, 3]
results = reducer.batch_process(methods, components, "dim_reduction_results")
# 图像分割 - 参数调优
from segment_method.threshold_Segment import ThresholdSegmenter, ThresholdSegmentationConfig
seg_config = ThresholdSegmentationConfig(
input_path="data.hdr",
band_index=100,
method='otsu',
output_dir="segmentation_results"
)
segmenter = ThresholdSegmenter(seg_config)
segmenter.load_data()
# 批量应用多种分割方法
methods = ['otsu', 'isodata', 'adaptive', 'iterative']
bands = [100, 100, 100, 100]
results = segmenter.batch_process(methods, bands, "segmentation_results")
# 边缘检测 - 高级参数配置
from edge_detect_method.edge_detect import EdgeDetector, EdgeDetectionConfig
edge_config = EdgeDetectionConfig(
input_path="data.hdr",
band_index=50,
method='canny',
canny_min_threshold=50,
canny_max_threshold=150,
use_blur=True,
blur_sigma=1.5,
output_dir="edge_results"
)
detector = EdgeDetector(edge_config)
detector.load_data()
# 批量应用多种边缘检测方法
methods = ['sobel', 'scharr', 'laplacian', 'log', 'canny']
bands = [50, 50, 50, 50, 50]
results = detector.batch_process(methods, bands, "edge_results")
命令行使用
# 光谱指数计算
python spectral_index_method/spectral_index.py input.hdr -i NDVI EVI -o results
# 图像滤波
python fliter_method/Smooth_filter.py input.hdr -f mean -k 3 -b 20 -o filtered_output
# 降维分析(运行内置示例)
python Dimensionality_Reduction_method/dimensionality_reduction.py
# 图像分割(运行内置示例)
python segment_method/threshold_Segment.py
# 边缘检测(运行内置示例)
python edge_detect_method/edge_detect.py
高级配置
# 自定义回归配置
config = RegressionConfig()
config.data.csv_path = "data.csv"
config.data.label_column = "chlorophyll"
config.data.spectrum_columns = "10:200" # 波长范围
config.models.tune_hyperparams = True
config.models.model_names = ['ridge', 'lasso', 'xgboost']
config.output.save_models = True
analyzer = RegressionAnalyzer(config)
results = analyzer.run_analysis_from_config()
快速开始 - 新功能
# 1. 降维分析快速开始
from Dimensionality_Reduction_method.dimensionality_reduction import *
config = DimensionalityReductionConfig(
input_path="your_data.hdr",
method='pca',
n_components=3
)
processor = HyperspectralDimReduction(config)
processor.load_data()
reduced_data, bands = processor.apply_dim_reduction()
# 2. 图像分割快速开始
from segment_method.threshold_Segment import *
config = ThresholdSegmentationConfig(
input_path="your_data.hdr",
band_index=100,
method='otsu'
)
processor = ThresholdSegmenter(config)
processor.load_data()
segmented, threshold = processor.apply_segmentation()
# 3. 边缘检测快速开始
from edge_detect_method.edge_detect import *
config = EdgeDetectionConfig(
input_path="your_data.hdr",
band_index=50,
method='canny'
)
processor = EdgeDetector(config)
processor.load_data()
edges, info = processor.apply_edge_detection()
📁 项目结构
hyperspectral-toolkit/
├── rgression_method/
│ └── regression.py # 回归分析模块
├── classfication_method/
│ └── classfication.py # 分类工具
├── cluster_method/
│ └── cluster.py # 聚类算法
├── Dimensionality_Reduction_method/
│ └── dimensionality_reduction.py # 降维分析
├── segment_method/
│ └── threshold_Segment.py # 阈值分割
├── edge_detect_method/
│ └── edge_detect.py # 边缘检测
├── fliter_method/
│ ├── Smooth_filter.py # 图像滤波模块
│ └── morphological_fliter.py # 形态学滤波
├── spectral_index_method/
│ └── spectral_index.py # 光谱指数计算器
├── preprocessing_method/
│ └── Preprocessing.py # 数据预处理
├── Feature_Selection_method/
│ ├── feture_select.py # 特征选择
│ └── *.py # 各种特征选择算法
├── supervize_cluster_method/
│ └── supervize_cluster.py # 监督聚类
├── requirements.txt # 依赖包列表
├── README.md # 本文件
└── test/ # 测试和示例
🔧 配置系统
该工具包使用为GUI集成设计的分层配置系统:
数据配置
@dataclass
class DataConfig:
csv_path: str = ""
label_column: Union[str, int] = ""
spectrum_columns: Optional[Union[str, List]] = None
test_size: float = 0.2
scale_method: str = 'standard'
模型配置
@dataclass
class ModelConfig:
model_names: Optional[List[str]] = None # None = 所有模型
tune_hyperparams: bool = True
tuning_method: str = 'grid'
cv_folds: int = 5
训练配置
@dataclass
class TrainingConfig:
epochs: int = 100
batch_size: int = 32
learning_rate: float = 0.001
🎨 可用算法
降维方法
- 线性方法: PCA (主成分分析)、ICA (独立成分分析)、FA (因子分析)
- 监督方法: LDA (线性判别分析)
- 非线性方法: MDS (多维尺度分析)、Isomap (等度量映射)、LLE (局部线性嵌入)、t-SNE (t-分布随机邻域嵌入)
- 智能推荐: 基于数据类型和规模的自动方法推荐
分割方法
- 阈值分割: 固定阈值、直方图双峰法、迭代法阈值分割
- 自适应分割: 基于局部统计的自适应阈值
- 自动方法: Otsu (大津法)、ISODATA 阈值分割
- 参数调优: 丰富的参数配置和批量处理支持
边缘检测方法
- 一阶导数: Sobel 算子、Scharr 算子
- 二阶导数: Laplacian 算子
- 复合方法: Laplacian of Gaussian (LoG)、Canny 算子
- 参数控制: 核大小、阈值、尺度参数等全面可调
回归模型
- 线性模型: 线性回归、岭回归、LASSO、弹性网络、贝叶斯岭回归
- 集成模型: 随机森林、梯度提升、AdaBoost
- 提升模型: XGBoost、LightGBM
- 神经网络: MLP、LSTM、GRU
- 专业模型: SVR、高斯过程、KNN
光谱指数
- 植被指数: NDVI、EVI、ARVI、SAVI 等
- 水体指数: NDWI、MNDWI 等
- 矿物指数: 各种矿物特定指数
- 自定义指数: 用户定义的公式
🚀 新功能特性详情
📊 降维分析系统
- 智能推荐: 根据数据类型(图像/CSV)、样本数量和特征维度自动推荐最适合的降维方法
- 8种降维算法: 从经典的PCA到先进的t-SNE,覆盖线性到非线性方法
- 批量处理: 支持一次运行多种降维方法进行对比分析
- 详细报告: 自动生成包含方法适用性和推荐理由的分析报告
🎯 阈值分割系统
- 6种分割方法: 覆盖从简单固定阈值到高级Otsu和ISODATA方法
- 参数开放性: 每个方法都有丰富的参数配置选项
- 批量对比: 支持多方法多波段的批量分割处理
- 自动阈值: 智能阈值选择和手动调优选项
⚡ 边缘检测系统
- 5种检测算法: 从基础的Sobel算子到先进的Canny算法
- 参数可调: 每个方法都有全面的参数控制选项
- 预处理支持: 可选的高斯模糊预处理以减少噪声影响
- 多尺度分析: 支持不同尺度参数的边缘特征提取
🎨 高级特性
- 配置驱动: 所有模块都使用统一的数据类配置系统
- 批量处理: 支持多参数、多方法的批量对比分析
- 智能验证: 全面的参数校验和错误处理
- ENVI兼容: 完整的ENVI格式输入输出支持
- 文档齐全: 每个方法都有详细的使用说明和参数解释
📊 输出格式
- ENVI格式: 标准高光谱数据格式(.dat + .hdr),包含详细的处理信息和参数
- CSV: 包含统计信息和结果的表格数据
- 图像: PNG格式的可视化结果和图表
- 模型: Pickle格式的sklearn模型用于部署
- 配置: JSON格式的参数配置保存和恢复
Description
Languages
Python
100%