Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesh spm #233

Merged
merged 5 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_on_prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:

strategy:
matrix:
soft: [ANTS, ANTS_T1]
soft: [ANTS, ANTS_T1, SPM_native]
steps:
- name: Pull latest docker image
run:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_on_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:

strategy:
matrix:
soft: [ANTS, ANTS_T1]
soft: [ANTS, ANTS_T1, SPM_native]
steps:
- name: Pull latest docker image
run:
Expand Down
3 changes: 3 additions & 0 deletions macapype/pipelines/full_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def create_full_spm_subpipes(
outputnode = pe.Node(
niu.IdentityInterface(fields=['brain_mask', 'segmented_brain_mask',
'debiased_T1', 'debiased_brain',
"wmgm_stl",
'prob_wm', 'prob_gm', 'prob_csf']),
name='outputnode')
# preprocessing
Expand Down Expand Up @@ -673,6 +674,8 @@ def create_full_spm_subpipes(
seg_pipe.connect(inputnode, 'indiv_params',
mask_from_seg_pipe, 'inputnode.indiv_params')

seg_pipe.connect(mask_from_seg_pipe, "wmgm2mesh.stl_file",
outputnode, 'wmgm_stl')
# seg_mask
if pad and space == "native":
if "short_preparation_pipe" in params.keys():
Expand Down
17 changes: 17 additions & 0 deletions macapype/pipelines/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,20 @@ def rename_all_derivatives(params, main_workflow, segment_pnh_pipe,
main_workflow.connect(
rename_segmented_brain_mask, 'out_file',
datasink, '@segmented_brain_mask')

print("Renaming wmgm_stl file")

rename_wmgm_stl = pe.Node(niu.Rename(),
name="rename_wmgm_stl")
rename_wmgm_stl.inputs.format_string = \
pref_deriv + "_space-{}_desc-wmgm_mask".format(space)
rename_wmgm_stl.inputs.parse_string = parse_str
rename_wmgm_stl.inputs.keep_ext = True

main_workflow.connect(
segment_pnh_pipe, 'outputnode.wmgm_stl',
rename_wmgm_stl, 'in_file')

main_workflow.connect(
rename_wmgm_stl, 'out_file',
datasink, '@wmgm_stl')
57 changes: 55 additions & 2 deletions macapype/pipelines/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@

import nipype.interfaces.spm as spm

from ..nodes.segment import (AtroposN4, merge_masks,
from ..nodes.segment import (AtroposN4, merge_masks, BinaryFillHoles,
merge_imgs, split_indexed_mask, copy_header,
compute_5tt, fill_list_vol)


from macapype.nodes.surface import wrap_afni_IsoSurface

from ..utils.misc import (gunzip, merge_3_elem_to_list,
get_pattern, get_list_length, get_index)

Expand Down Expand Up @@ -845,7 +848,6 @@ def create_native_old_segment_pipe(params_template, params={},
###############################################################################
# create mask from segment
def create_mask_from_seg_pipe(params={}, name="mask_from_seg_pipe"):

"""
Description: mask from segmentation tissues

Expand Down Expand Up @@ -916,4 +918,55 @@ def create_mask_from_seg_pipe(params={}, name="mask_from_seg_pipe"):
seg_pipe.connect(bin_csf, 'out_file',
merge_indexed_mask, "mask_csf_file")

# Compute union of the 3 tissues
# Done with 2 fslmaths as it seems to hard to do it
wmgm_union = pe.Node(fsl.BinaryMaths(), name="wmgm_union")
wmgm_union.inputs.operation = "add"
seg_pipe.connect(bin_gm, 'out_file', wmgm_union, 'in_file')
seg_pipe.connect(bin_wm, 'out_file', wmgm_union, 'operand_file')

tissues_union = pe.Node(fsl.BinaryMaths(), name="tissues_union")
tissues_union.inputs.operation = "add"
seg_pipe.connect(wmgm_union, 'out_file', tissues_union, 'in_file')
seg_pipe.connect(bin_csf, 'out_file',
tissues_union, 'operand_file')

# Opening (dilating) mask
dilate_mask = NodeParams(fsl.DilateImage(),
params=parse_key(params, "dilate_mask"),
name="dilate_mask")

dilate_mask.inputs.operation = "mean" # Arbitrary operation
seg_pipe.connect(tissues_union, 'out_file', dilate_mask, 'in_file')

# fill holes of dilate_mask
fill_holes_dil = pe.Node(BinaryFillHoles(), name="fill_holes_dil")
seg_pipe.connect(dilate_mask, 'out_file', fill_holes_dil, 'in_file')

# Eroding mask
erode_mask = NodeParams(fsl.ErodeImage(),
params=parse_key(params, "erode_mask"),
name="erode_mask")

seg_pipe.connect(tissues_union, 'out_file', erode_mask, 'in_file')

# fill holes of erode_mask
fill_holes = pe.Node(BinaryFillHoles(), name="fill_holes")
seg_pipe.connect(erode_mask, 'out_file', fill_holes, 'in_file')

# bin mask
bin_mask = pe.Node(interface=fsl.UnaryMaths(), name="bin_mask")
bin_mask.inputs.operation = "bin"

seg_pipe.connect(fill_holes, 'out_file', bin_mask, 'in_file')

# wmgm2mesh
wmgm2mesh = pe.Node(
interface=niu.Function(input_names=["nii_file"],
output_names=["stl_file"],
function=wrap_afni_IsoSurface),
name="wmgm2mesh")

seg_pipe.connect(bin_mask, 'out_file', wmgm2mesh, "nii_file")

return seg_pipe