Skip to content

Commit 42b9f1c

Browse files
author
Jordan DeKraker
committed
Merge branch 'templateseg2' of https://github.com/khanlab/hippunfold into templateseg2
2 parents f2039f4 + 29836ad commit 42b9f1c

22 files changed

+79
-13
lines changed

.github/workflows/python-testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555

5656
- name: Setup env for hippunfold
5757
run: |
58-
echo "HIPPUNFOLD_CACHE_DIR=`pwd`/test_data/fake_models" >> $GITHUB_ENV
58+
echo "HIPPUNFOLD_CACHE_DIR=`pwd`/test_data/hippunfold_cache_dir" >> $GITHUB_ENV
5959
6060
- name: Test single T2w bids
6161
run: |

.readthedocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ version: 2
88
build:
99
os: "ubuntu-22.04"
1010
tools:
11-
python: "3.7"
11+
python: "3.8"
1212

1313
# Build documentation in the docs/ directory with Sphinx
1414
sphinx:
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.8502973449669877

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pipeline/algorithms
5151
5252
outputs/output_files
5353
outputs/visualization
54+
outputs/QC
5455
```
5556

5657

docs/outputs/QC.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Quality Control
2+
3+
A complex pipeline can have multiple points of failure, so its imprtant to check the QC folder to ensure results make sense. This will contain (for example) the following files:
4+
5+
hippunfold/
6+
└── sub-001
7+
└── qc
8+
├── sub-001_from-T1w_to-CITI168_regqc.png
9+
├── sub-001_hemi-L_desc-unetf3d_dice.tsv
10+
├── sub-001_hemi-L_space-cropT1w_desc-subfields_atlas-histologyReference2023_dseg.png
11+
├── sub-001_hemi-L_space-T1w_den-0p5mm_label-dentate_desc-subfields_midthickness.surf.png
12+
└── sub-001_hemi-L_space-T1w_den-0p5mm_label-hipp_desc-subfields_midthickness.surf.png
13+
14+
These files will be mirrored in the right (`hemi-R`) hemisphere, but we will skip that here for brevity.
15+
16+
## Automated checks
17+
18+
A very fast quality check is to simply look at `sub-001_hemi-L_desc-unetf3d_dice.tsv` and ensure that this number is greater than `0.7`. Typically this criterion can be applied to all subjects, and subjects `<0.7` can simply be automatically discarded. A more in-depth explanation for this is provided at the bottom of this page.
19+
20+
To better understand some common points of failure, let's walk through the other files contained here:
21+
22+
## Catch-all failures
23+
24+
A good way to be sure that nothing has failed is also to look at the final results, as in the following snapshot images.
25+
26+
`sub-001_hemi-L_space-cropT1w_desc-subfields_atlas-histologyReference2023_dseg.png`:
27+
28+
![image](../images/QC/sub-001_hemi-L_space-cropT1w_desc-subfields_atlas-histologyReference2023_dseg.png)
29+
30+
Here we see a volumetric output of subfield parcellations. If you have some hippocampal expertise then you may be able to see right away whether the results make sense. Some common errors include missed parts of the hippocampus and, sometimes, parts of collateral sulcus are included as part of the hippocapus. This is because of gross or "catastrophic" failures in the UNet tissue classification, which should be caught be the above automated check. Still, this collage of sample slices should give a good sense for whether/how the segmentation has failed.
31+
32+
`sub-001_hemi-L_space-T1w_den-0p5mm_label-hipp_desc-subfields_midthickness.surf.png`:
33+
34+
![image](../images/QC/sub-001_hemi-L_space-T1w_den-0p5mm_label-hipp_desc-subfields_midthickness.surf.png)
35+
36+
`sub-001_hemi-L_space-T1w_den-0p5mm_label-dentate_desc-subfields_midthickness.surf.png`:
37+
38+
![image](../images/QC/sub-001_hemi-L_space-T1w_den-0p5mm_label-dentate_desc-subfields_midthickness.surf.png)
39+
40+
In these two images we see the output hippocampal and dentate gyrus surfaces, which should roughly resemble those shown in the HippUnfold manuscript (though they may have some differences in shape and/or sulcal/gyral patterning due to inter-individual variance!).
41+
42+
Sometimes the dentate gyrus surface may show a few large triangles that obscure the rest of the surface, as in the example here. This typically arises when just a few vertices are badly misplaced, and so typically this doesn't have much impact on quantitative results but it can look quite ugly in a figure. This can arise because the structure is small and contains few voxels, none of which have a laplace field close to a given value and so the xyz coordinate of a given laplace value is extrapolated badly. We will try to fix this issue in future releases.
43+
44+
## Registration/cropping failures
45+
46+
Though it seems simple, just getting the image roughly aligned to a template so we can then crop around the left and right hippocampi for subsequent processing (in `space-corobl`) can sometimes fail. We can examine this in the file `sub-001_from-T1w_to-CITI168_regqc.png`:
47+
48+
![image](../images/QC/sub-001_from-T1w_to-CITI168_regqc.png)
49+
50+
In this image, the subject tissue boundaries (e.g. grey matter, white matter, CSF, skull) are overlaid on a standard template. This is a linear alignment, so while gyri/sulci may not be well aligned, we should still see fairly good overlap that is sufficient to derive the position of the hippocampus in the image. This most often fails if the input images are in an unexpected orientation (e.g. this sometimes arises in ex-vivo scanning), and can sometimes be imporved by first running FSL's [reorient2std](https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/Fslutils).
51+
52+
## Checking the automated check
53+
54+
The `Dice > 0.7` rule is a good automatic check because HippUnfold typically shows high sensitivity to details in hippocampal structure, but when it fails it often does so catastrophically. These failures are very obvious, and can often be shown by this simple Dice score that compares a whole mask of the hippocampus to a whole mask of a hippocampus generated by a more conventional but less precise measure: diffeomorphic registration to a standard template. The Dice score should be good between the two methods, but will never be close to perfect (`>0.9`) since the HippUnfold method will differ as its more precise.
55+
56+
This issue typically only occurs in ~1% of cases.

docs/requirements.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
docutils==0.17
2-
sphinx-argparse
2+
sphinx-argparse==0.4.0
33
sphinx_rtd_theme>=1.0.0
44
snakebids>=0.4.0
5-
myst-parser
6-
sphinxcontrib.asciinema
5+
myst-parser==1.0.0
6+
sphinxcontrib.asciinema==0.3.7
77
pulp<2.8.0
8+

hippunfold/config/snakebids.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ parse_args:
128128
--version:
129129
help: 'Print the version of HippUnfold'
130130
action: version
131-
version: "1.4.2-pre.35"
131+
version: "1.4.2-pre.37"
132132

133133
--modality:
134134
help: 'Type of image to run hippunfold on. Modality prefixed with seg will import an existing (manual) hippocampal tissue segmentation from that space, instead of running neural network (default: %(default)s)'
@@ -355,6 +355,7 @@ singularity:
355355
autotop: 'docker://khanlab/hippunfold_deps:v0.5.0'
356356

357357
xfm_identity: resources/etc/identity_xfm.txt
358+
xfm_identity_itk: resources/etc/identity_xfm_itk.txt
358359

359360
#templates enabled for template-based segmentation are here
360361
# TODO: should also perhaps include modalities avaialble, and any custom crop_native_res settings

hippunfold/pipeline_description.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"GeneratedBy": [
66
{
77
"Name": "hippunfold",
8-
"Version": "1.4.2-pre.35",
8+
"Version": "1.4.2-pre.37",
99
"CodeURL": "https://github.com/khanlab/hippunfold",
1010
"Author": "Jordan DeKraker & Ali Khan",
1111
"AuthorEmail": "ali.khan@uwo.ca"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#Insight Transform File V1.0
2+
#Transform 0
3+
Transform: MatrixOffsetTransformBase_double_3_3
4+
Parameters: 1 0 0 0 1 0 0 0 1 0 0 0
5+
FixedParameters: 0 0 0

hippunfold/workflow/Snakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ wildcard_constraints:
103103
density="[a-zA-Z0-9]+",
104104
atlas="[a-zA-Z0-9]+",
105105
autotop="[a-zA-Z0-9]+",
106+
template="[a-zA-Z0-9]+",
106107

107108

108109
root = os.path.join(config["root"], "hippunfold")

hippunfold/workflow/rules/preproc_t2.smk

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def get_inputs_compose_t2_xfm_corobl(wildcards):
259259
from_="T2w",
260260
to="T1w",
261261
desc="rigid",
262-
type_="itk"
262+
type_="itk",
263263
),
264264
)
265265
t1_to_cor = (
@@ -271,7 +271,7 @@ def get_inputs_compose_t2_xfm_corobl(wildcards):
271271
from_="T1w",
272272
to="corobl",
273273
desc="affine",
274-
type_="itk"
274+
type_="itk",
275275
),
276276
)
277277
return {"t2_to_t1": t2_to_t1, "t1_to_cor": t1_to_cor}
@@ -287,7 +287,7 @@ def get_inputs_compose_t2_xfm_corobl(wildcards):
287287
from_="T2w",
288288
to=config["template"],
289289
desc="affine",
290-
type_="itk"
290+
type_="itk",
291291
),
292292
)
293293

@@ -296,7 +296,7 @@ def get_inputs_compose_t2_xfm_corobl(wildcards):
296296
return {"t2_to_std": t2_to_std, "template_dir": template_dir}
297297

298298

299-
def get_cmd_compose_t2_xfm_corobl(wildcards, input):
299+
def get_cmd_compose_t2_xfm_corobl(wildcards, input, output):
300300
if config["t1_reg_template"]:
301301
# xfm0: t2 to t1
302302
xfm0 = input.t2_to_t1
@@ -310,7 +310,7 @@ def get_cmd_compose_t2_xfm_corobl(wildcards, input):
310310
"xfm_corobl"
311311
].format(**wildcards)
312312

313-
return "c3d_affine_tool -itk {xfm0} -itk {xfm1} -mult -oitk {output}"
313+
return f"c3d_affine_tool -itk {xfm0} -itk {xfm1} -mult -oitk {output}"
314314

315315

316316
# now have t2 to t1 xfm, compose this with t1 to corobl xfm

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "hippunfold"
3-
version = "1.4.2-pre.35"
3+
version = "1.4.2-pre.37"
44
description = "BIDS App for Hippocampal AutoTop (automated hippocampal unfolding and subfield segmentation)"
55
authors = ["Jordan DeKraker & Ali Khan <alik@robarts.ca>"]
66

test_data/fake_models/trained_model.3d_fullres.Task101_hcp1200_T1w.nnUNetTrainerV2.model_best.tar

Whitespace-only changes.

test_data/fake_models/trained_model.3d_fullres.Task102_hcp1200_T2w.nnUNetTrainerV2.model_best.tar

Whitespace-only changes.

test_data/fake_models/trained_model.3d_fullres.Task103_hcp1200_T1T2w.nnUNetTrainerV2.model_best.tar

Whitespace-only changes.

test_data/fake_models/trained_model.3d_fullres.Task104_hcp1200_b1000.nnUNetTrainerV2.model_best.tar

Whitespace-only changes.

test_data/fake_models/trained_model.3d_fullres.Task105_hcp1200_trimodal.nnUNetTrainerV2.model_best.tar

Whitespace-only changes.

test_data/fake_models/trained_model.3d_fullres.Task110_hcp1200_b1000crop.nnUNetTrainerV2.model_best.tar

Whitespace-only changes.

0 commit comments

Comments
 (0)