Switch viewer and training to patient1 fixed flat CT
This commit is contained in:
41
README.md
41
README.md
@@ -1,6 +1,6 @@
|
||||
# VoxelMorph Head CT Deformable Registration
|
||||
|
||||
面向“患者平扫 CT(中立位)到仰头 CT(极度后仰位)”的 3D 形变配准工程。项目包含 DICOM 转 NIfTI、医学图像预处理、官方 VoxelMorph 训练适配器、独立推理,以及 Streamlit 交互式结果查看界面。
|
||||
面向“患者仰头 CT(Moving)到平扫 CT(Fixed)”的 3D 形变配准工程。项目包含 DICOM 转 NIfTI、医学图像预处理、官方 VoxelMorph 训练适配器、独立推理,以及 Streamlit 交互式结果查看界面。
|
||||
|
||||
核心模型使用官方仓库 `voxelmorph/voxelmorph` 的 PyTorch 实现:
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
```text
|
||||
Voxelmorph_Head_CT/
|
||||
├── Data/
|
||||
│ ├── 患者1-平扫CT/ # Moving 原始 DICOM
|
||||
│ ├── 患者1-仰头CT/ # Fixed 原始 DICOM
|
||||
│ ├── 患者1-平扫CT/ # Fixed 原始 DICOM
|
||||
│ ├── 患者1-仰头CT/ # Moving 原始 DICOM
|
||||
│ └── 患者2-平扫CT/
|
||||
├── app.py # Streamlit Web 可视化界面
|
||||
├── config.py # 默认路径与预处理参数
|
||||
@@ -60,11 +60,11 @@ bash scripts/setup_env.sh
|
||||
```bash
|
||||
python data_loader.py \
|
||||
--dicom-dir "Data/患者1-平扫CT" \
|
||||
--output "outputs/nifti/patient1_moving.nii.gz"
|
||||
--output "outputs/nifti/patient1_fixed.nii.gz"
|
||||
|
||||
python data_loader.py \
|
||||
--dicom-dir "Data/患者1-仰头CT" \
|
||||
--output "outputs/nifti/patient1_fixed.nii.gz"
|
||||
--output "outputs/nifti/patient1_moving.nii.gz"
|
||||
```
|
||||
|
||||
`data_loader.py` 会优先按 `InstanceNumber` 排序,其次按 `SliceLocation` 排序,并保存 spacing、层厚、排序依据等元数据 JSON。
|
||||
@@ -72,17 +72,17 @@ python data_loader.py \
|
||||
## 2. 预处理
|
||||
|
||||
```bash
|
||||
python preprocess.py \
|
||||
--input "outputs/nifti/patient1_moving.nii.gz" \
|
||||
--output "outputs/preprocessed/patient1_moving_preprocessed.nii.gz" \
|
||||
--target-spacing 1 1 1 \
|
||||
--target-shape 160 192 224
|
||||
|
||||
python preprocess.py \
|
||||
--input "outputs/nifti/patient1_fixed.nii.gz" \
|
||||
--output "outputs/preprocessed/patient1_fixed_preprocessed.nii.gz" \
|
||||
--target-spacing 1 1 1 \
|
||||
--target-shape 160 192 224
|
||||
--target-shape 256 256 352
|
||||
|
||||
python preprocess.py \
|
||||
--input "outputs/nifti/patient1_moving.nii.gz" \
|
||||
--output "outputs/preprocessed/patient1_moving_preprocessed.nii.gz" \
|
||||
--target-spacing 1 1 1 \
|
||||
--target-shape 256 256 352
|
||||
```
|
||||
|
||||
默认窗口为 `W=400, L=40`,适合观察颈部软组织和气道。
|
||||
@@ -93,10 +93,10 @@ python preprocess.py \
|
||||
python model_and_train.py \
|
||||
--moving "outputs/preprocessed/patient1_moving_preprocessed.nii.gz" \
|
||||
--fixed "outputs/preprocessed/patient1_fixed_preprocessed.nii.gz" \
|
||||
--checkpoint "outputs/checkpoints/vxm_head_ct.pt" \
|
||||
--epochs 200 \
|
||||
--image-loss ncc \
|
||||
--ncc-impl local \
|
||||
--checkpoint "outputs/checkpoints/vxm_head_ct_patient1.pt" \
|
||||
--epochs 80 \
|
||||
--image-loss mse \
|
||||
--nb-features 8 8 8 8 8 \
|
||||
--smooth-weight 0.01
|
||||
```
|
||||
|
||||
@@ -109,7 +109,7 @@ python model_and_train.py \
|
||||
python infer.py \
|
||||
--moving "outputs/preprocessed/patient1_moving_preprocessed.nii.gz" \
|
||||
--fixed "outputs/preprocessed/patient1_fixed_preprocessed.nii.gz" \
|
||||
--checkpoint "outputs/checkpoints/vxm_head_ct.pt" \
|
||||
--checkpoint "outputs/checkpoints/vxm_head_ct_patient1.pt" \
|
||||
--out-dir "outputs/inference"
|
||||
```
|
||||
|
||||
@@ -131,9 +131,8 @@ streamlit run app.py
|
||||
|
||||
网页提供:
|
||||
|
||||
- Moving/Fixed/模型权重/输出目录输入。
|
||||
- 自动发现 `outputs/` 与项目目录下的 NIfTI 和 checkpoint,也支持手动输入路径。
|
||||
- “开始推理”按钮。
|
||||
- 患者1专用固定路径:Fixed 为 `患者1-平扫CT`,Moving 为 `患者1-仰头CT`。
|
||||
- “重新训练模型”和“开始推理”按钮。
|
||||
- Axial、Coronal、Sagittal 正交三视图;每个平面按行同时展示 Fixed、Moving、Warped。
|
||||
- Fixed 与 Warped 的 Alpha 融合或棋盘格对比。
|
||||
- DDF 位移强度热力图。
|
||||
@@ -143,4 +142,4 @@ streamlit run app.py
|
||||
|
||||
- DICOM 转换和重采样都有 `--max-memory-mb` 防护。
|
||||
- Web 界面对超大 NIfTI 会通过 nibabel proxy 按 stride 切片读取并下采样,只影响浏览器展示,不改变磁盘结果;侧栏可调整显示体素上限。
|
||||
- 训练阶段的主要瓶颈是 3D U-Net 显存;`160x192x224` 是较重的 3D 输入,建议优先使用 CUDA GPU。
|
||||
- 训练阶段的主要瓶颈是 3D U-Net 显存;`256x256x352` 是较重的 3D 输入,建议优先使用 CUDA GPU。当前患者1默认使用较轻的 `8 8 8 8 8` 特征配置。
|
||||
|
||||
Reference in New Issue
Block a user