-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathquickshear.py
More file actions
76 lines (63 loc) · 2.81 KB
/
quickshear.py
File metadata and controls
76 lines (63 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from pathlib import Path
from typing import Union
import nibabel as nib
from auxiliary.io import read_image, write_image
from brainles_preprocessing.defacing.defacer import Defacer
from brainles_preprocessing.defacing.quickshear.nipy_quickshear import run_quickshear
from brainles_preprocessing.constants import Atlas
class QuickshearDefacer(Defacer):
"""
Defacer using Quickshear algorithm.
Quickshear uses a skull stripped version of an anatomical images as a reference to deface the unaltered anatomical image.
Base publication:
- PDF: https://www.researchgate.net/profile/J-Hale/publication/262319696_Quickshear_defacing_for_neuroimages/links/570b97ee08aed09e917516b1/Quickshear-defacing-for-neuroimages.pdf
- Bibtex:
```
@article{schimke2011quickshear,
title={Quickshear Defacing for Neuroimages.},
author={Schimke, Nakeisha and Hale, John},
journal={HealthSec},
volume={11},
pages={11},
year={2011}
}
```
"""
def __init__(
self,
buffer: float = 10.0,
force_atlas_registration: bool = True,
atlas_image_path: Union[str, Path, Atlas] = Atlas.SRI24,
):
"""Initialize Quickshear defacer
Args:
buffer (float, optional): buffer parameter from quickshear algorithm. Defaults to 10.0.
force_atlas_registration (bool, optional): If True, forces atlas registration of the BET mask before defacing to potentially boost quickshear performance. Defaults to True.
atlas_image_path (Union[str, Path, Atlas], optional): Path to the atlas image or an Atlas enum value that will be used for the optional atlas registrations. Defaults to Atlas.SRI24.
"""
super().__init__()
self.buffer = buffer
self.force_atlas_registration = force_atlas_registration
self.atlas_image_path = atlas_image_path
def deface(
self,
input_image_path: Union[str, Path],
mask_image_path: Union[str, Path],
) -> None:
"""
Generate a defacing mask using Quickshear algorithm.
Note:
The input image must be a brain-extracted (skull-stripped) image.
Args:
input_image_path (str or Path): Path to the brain-extracted input image.
mask_image_path (str or Path): Path to save the generated mask image.
"""
bet_img = nib.load(str(input_image_path))
mask = run_quickshear(bet_img=bet_img, buffer=self.buffer)
# transpose to match simpletik order
mask = mask.transpose(2, 1, 0)
write_image(
input_array=mask,
output_path=str(mask_image_path),
reference_path=str(input_image_path),
)