Commit 22d041f9 authored by Michiel Cottaar's avatar Michiel Cottaar
Browse files

ENH: don't allow deep white matter to be filled by binary_fill_holes

parent 5602eb29
Pipeline #5297 failed with stage
in 54 minutes and 48 seconds
......@@ -59,6 +59,18 @@ gyral_wm_mask = (dist_mask | thickness_mask) & (white_dist < 0)
final_mask = (gyral_wm_mask | intersect_mask) & close_to_white_mask
idx_deepest = np.unravel_index(dist_mask.argmin(), shape=dist_mask.shape)
if final_mask[idx_deepest]:
raise ValueError("Even the deepest white matter point was included in the gyral mask.")
# Fill any holes left in the gyral white matter
filled = ndimage.binary_fill_holes(final_mask)
if filled[idx_deepest]:
# Filling holes in the gyral white matter also filled the deep white matter
# Let's fix that
new_filled = filled - final_mask
labels, _ = ndimage.label(new_filled)
filled[labels[idx_deepest] == labels] = False
nib.Nifti1Image(filled, affine=None, header=img.header).to_filename(args.out)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment