Skip to content

Commit

Permalink
ENH: Rename 3-tissue brain extraction network.
Browse files Browse the repository at this point in the history
  • Loading branch information
ntustison committed Nov 20, 2024
1 parent 00b7038 commit 11cae69
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions antspynet/utilities/brain_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def brain_extraction(image,
* "t1nobrainer": T1-weighted MRI---FreeSurfer-trained: h/t Satra Ghosh and Jakub Kaczmarzyk.
* "t1combined": Brian's combination of "t1" and "t1nobrainer". One can also specify
"t1combined[X]" where X is the morphological radius. X = 12 by default.
* "t1threetissue": T1-weighted MRI---originally developed from BrainWeb20 (and later expanded).
Label 1: parenchyma, label 2: meninges/csf, label 3: misc. head.
* "flair": FLAIR MRI. Previous versions are specified as "flair.v0".
* "t2": T2 MRI. Previous versions are specified as "t2.v0".
* "t2star": T2Star MRI.
Expand Down Expand Up @@ -140,7 +142,7 @@ def brain_extraction(image,
weights_file_name_prefix = "brainExtractionInfantT1"
elif modality == "t2infant":
weights_file_name_prefix = "brainExtractionInfantT2"
elif modality == "bw20":
elif modality == "t1threetissue":
weights_file_name_prefix = "brainExtractionBrainWeb20"
is_standard_network = True
else:
Expand All @@ -154,14 +156,13 @@ def brain_extraction(image,
if verbose:
print("Brain extraction: retrieving template.")

if modality == "bw20":
if modality == "t1threetissue":
reorient_template = ants.image_read(get_antsxnet_data("nki"))
resampled_image_size = reorient_template.shape
else:
reorient_template = ants.image_read(get_antsxnet_data("S_template3"))
if is_standard_network and (modality != "t1.v1" and modality != "mra"):
ants.set_spacing(reorient_template, (1.5, 1.5, 1.5))
resampled_image_size = reorient_template.shape
resampled_image_size = reorient_template.shape

number_of_filters = (8, 16, 32, 64)
mode = "classification"
Expand All @@ -171,9 +172,9 @@ def brain_extraction(image,
mode = "sigmoid"

unet_model = None
if modality == "bw20":
if modality == "t1threetissue":
mode = "classification"
number_of_classification_labels = 4 # background, brain, skull, skin/misc.
number_of_classification_labels = 4 # background, brain, meninges/csf, misc. head
unet_model = create_unet_model_3d((*resampled_image_size, channel_size),
number_of_outputs=number_of_classification_labels, mode=mode,
number_of_filters=number_of_filters, dropout_rate=0.0,
Expand Down Expand Up @@ -218,7 +219,7 @@ def brain_extraction(image,

xfrm_inv = xfrm.invert()

if modality == "bw20":
if modality == "t1threetissue":
probability_images_warped = list()
for i in range(number_of_classification_labels):
probability_images_warped.append(xfrm_inv.apply_to_image(
Expand Down
4 changes: 2 additions & 2 deletions antspynet/utilities/deep_atropos.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ def deep_atropos(t1,
rescale_intensities=True,
verbose=verbose)
if i == 0:
t1_bw20 = brain_extraction(input_images[0], modality="bw20", verbose=verbose)
t1_mask = t1_bw20['probability_images'][1]
t1_bext = brain_extraction(input_images[0], modality="t1threetissue", verbose=verbose)
t1_mask = t1_bext['probability_images'][1]
n4 = n4 * t1_mask
reg = ants.registration(hcp_t1_template, n4,
type_of_transform="antsRegistrationSyNQuick[a]",
Expand Down
2 changes: 1 addition & 1 deletion antspynet/utilities/preprocess_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def preprocess_brain_image(image,
print("Preprocessing: brain extraction.")

bext = brain_extraction(preprocessed_image, modality=brain_extraction_modality, verbose=verbose)
if brain_extraction_modality == "bw20":
if brain_extraction_modality == "t1threetissue":
mask = ants.threshold_image(bext['segmentation_image'], 1, 1, 1, 0)
else:
mask = ants.threshold_image(bext, 0.5, 1, 1, 0)
Expand Down

0 comments on commit 11cae69

Please sign in to comment.