def edge_mask(mask):
""" Find the edges of a mask or masked image
Parameters
----------
mask : 3D array
Binary mask (or masked image) with axis orientation LPS or RPS, and the
non-brain region set to 0
Returns
-------
2D array
Outline of sagittal profile (PS orientation) of mask
"""
# Sagittal profile
brain = mask.any(axis=0)
# Simple edge detection
edgemask = 4 * brain - np.roll(brain, 1, 0) - np.roll(brain, -1, 0) - \
np.roll(brain, 1, 1) - np.roll(brain, -1, 1) != 0
return edgemask.astype('uint8')
评论列表
文章目录