# 02_threshold_segmentation **Repository Path**: xiao_pacai/02_threshold_segmentation ## Basic Information - **Project Name**: 02_threshold_segmentation - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-29 - **Last Updated**: 2026-06-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 阈值分割教学软件 这是一个使用 Python Tkinter 编写的数字图像处理课程设计项目,主题为“阈值分割”。软件包含图像显示区、代码区和操作区,可用于演示阈值分割的完整处理流程。 ## 功能概览 - 本地图像加载与当前结果保存。 - 原始图像和当前处理步骤结果实时显示。 - “上一步 / 下一步”教学导航,首步自动禁用“上一步”,末步自动禁用“下一步”。 - 操作区支持手动阈值、滤波半径、形态学核大小和后处理来源选择。 - 参数修改后自动动态预览。 - 代码区同步显示当前步骤对应的 Python 算法代码和关键指标。 ## 教学流程 软件共包含 8 个展示步骤,其中至少 5 个属于独立图像处理操作: 1. 原始图像显示。 2. 灰度化。 3. 高斯滤波去噪。 4. 灰度直方图分析。 5. 手动阈值分割。 6. Otsu 自动阈值分割。 7. 形态学开运算后处理。 8. 分割结果叠加显示。 ## 项目结构 ```text . ├── main.py ├── requirements.txt ├── README.md ├── assets/ │ └── samples/ ├── scripts/ │ └── generate_samples.py ├── src/ │ └── threshold_teaching/ │ ├── __init__.py │ ├── app.py │ └── processing.py └── tests/ └── test_processing.py ``` ## 环境安装 建议使用虚拟环境: ```powershell python -m venv .venv .\.venv\Scripts\activate pip install -r requirements.txt ``` Tkinter 通常随 Windows 版 Python 自带,无需单独安装。 ## 运行软件 ```powershell python main.py ``` 首次运行会优先加载 `assets/samples/threshold_demo.png`。如果该文件不存在,程序会自动生成内置示例图用于展示。 ## 生成测试素材 ```powershell python scripts/generate_samples.py ``` 生成文件: - `assets/samples/threshold_demo.png` - `assets/samples/threshold_demo_gray.png` - `assets/samples/threshold_demo_binary_t140.png` ## 运行测试 ```powershell python -m unittest discover -s tests ``` 测试覆盖内容包括手动阈值、Otsu 阈值、形态学开运算、前景比例计算和完整处理流程步骤数量。 ## 课程设计提交建议 提交时建议包含: - 完整源码:`main.py`、`src/`。 - 依赖声明:`requirements.txt`。 - 测试用例:`tests/`。 - 图像素材:`assets/samples/`。 - 说明文档:`README.md`。