2026-03-05 17:12:01 +08:00
2026-03-05 17:12:01 +08:00
2026-03-05 17:12:01 +08:00
2026-02-25 09:42:51 +08:00
2026-03-05 17:12:01 +08:00
2026-02-25 09:42:51 +08:00
2026-02-25 09:42:51 +08:00
2026-02-25 09:42:51 +08:00
2026-03-05 17:12:01 +08:00
2026-03-05 17:12:01 +08:00
2026-02-25 09:42:51 +08:00
2026-03-05 17:12:01 +08:00
2026-03-05 17:12:01 +08:00
2026-02-25 09:42:51 +08:00
2026-02-25 09:42:51 +08:00
2026-02-25 09:42:51 +08:00
2026-02-25 09:39:14 +08:00
2026-02-25 09:42:51 +08:00
2026-02-25 09:42:51 +08:00
2026-03-05 17:12:01 +08:00
2026-02-25 09:42:51 +08:00
2026-02-25 09:42:51 +08:00
2026-02-25 09:42:51 +08:00

高光谱塑料分类工具

CC BY-NC Python Version

基于高光谱成像和深度学习的微塑料材料分类与识别工具

功能特性

  • 支持BIL格式高光谱数据读取和处理
  • 使用UNet模型进行图像分割和掩膜生成
  • 多种塑料材料的分类识别
  • 背景校正和光谱特征提取
  • 输出ENVI标准格式分类结果

安装

前置要求

  • Python 3.12
  • CUDA (可选用于GPU加速)
  • 足够的内存处理高光谱数据
  • 固态硬盘

安装步骤

  1. 克隆仓库:

    git clone 
    cd hyperspec-plastic-classification
    
  2. 安装依赖:

    pip install -r requirements.txt
    

使用方法

基本用法

python main.py --bil_path /path/to/input.bil --output_path /path/to/output --model_path /path/to/model.m

参数说明

参数 必需 默认值 描述
--bil_path 输入BIL文件路径
--output_path 输出目录路径
--model_path 分类模型路径
--unet_path ./unet_pytorch/logs/best_epoch_weights.pth UNet模型权重路径

示例

# 使用默认UNet权重
python main.py --bil_path ./data/input.bil --output_path ./results --model_path ./models/svm.m

# 指定所有参数
python main.py --bil_path ./data/input.bil --output_path ./results --model_path ./models/svm.m --unet_path ./custom_unet_weights.pth

# Windows系统示例
python main.py --bil_path "C:\Users\HyperSpec\test\MPData2.bil" --output_path "C:\Users\HyperSpec\test" --model_path ".\classification_model\modelsave\svm.m" --unet_path ".\unet_pytorch\logs\best_epoch_weights.pth"

项目结构

hyperspec-plastic-classification/
├── main.py                         # 主程序入口
├── bil2rgb.py                      # BIL转RGB模块
├── unet_pytorch/                   # UNet模型相关
│   ├── predict_rgb.py
│   └── logs/
│       └── best_epoch_weights.pth  # 预训练UNet权重
├── classification_model/           # 分类模型
│   └── Parallel/
│       └── predict_plastic.py
├── modelsave/
│           └── svm.m               # 预训练分类模型
├── shape_spectral.py               # 光谱特征提取
├── shape_spectral_background.py    # 背景校正
├── requirements.txt                # 项目依赖
└── README.md                       # 项目说明

img.png

输入输出格式

输入文件格式

  • BIL 格式高光谱数据文件 (.bil)
  • 对应的 HDR 头文件 (.hdr)

输出文件格式

  • ENVI 分类结果文件 (.dat)
  • ENVI 头文件 (.hdr)

处理流程

  1. 读取BIL格式高光谱数据
  2. 转换为RGB图像
  3. 使用UNet模型生成掩膜
  4. 提取光谱特征
  5. 应用背景校正
  6. 数据清理和过滤
  7. 使用分类模型预测材料类型
  8. 保存ENVI格式分类结果

支持的塑料类型

工具支持以下塑料材料的分类:

类别编号 材料名称
1 ABS
2 HDPE
3 LDPE
4 PA6
5 PET
6 PP
7 PS
8 PTFE
9 PVC

依赖库

主要依赖的 Python 库:

  • opencv-python
  • numpy
  • matplotlib
  • pandas
  • pywavelets
  • scikit-learn
  • torch

完整依赖请查看 requirements.txt 文件。

许可证

本项目采用 Creative Commons 非商业许可证。

常见问题

  1. 运行时报错"ModuleNotFoundError"

    确保已安装所有依赖:pip install -r requirements.txt

  2. 处理大型文件时内存不足

    考虑减少处理区域或增加系统内存

  3. 分类结果不准确

    检查输入数据质量,确认模型是否适合当前数据类型

联系方式

作者:[北京依锐思] 邮箱:huilai_zhang@126.com
项目地址:https://github.com/yourusername/hyperspec-plastic-classification

更新日志

  • v1.0.0 (2025-08-26)
    初始版本发布
    • 支持BIL格式高光谱数据处理
    • 集成UNet分割和SVM分类
    • 输出ENVI格式分类结果
Description
显微高光谱微塑料分类
Readme 110 MiB
Languages
Python 100%