def median_otsu(unweighted_volume, median_radius=4, numpass=4, dilate=1):
""" Simple brain extraction tool for dMRI data.
This function is inspired from the ``median_otsu`` function from ``dipy``
and is copied here to remove a dependency.
It uses a median filter smoothing of the ``unweighted_volume``
automatic histogram Otsu thresholding technique, hence the name
*median_otsu*.
This function is inspired from Mrtrix's bet which has default values
``median_radius=3``, ``numpass=2``. However, from tests on multiple 1.5T
and 3T data. From GE, Philips, Siemens, the most robust choice is
``median_radius=4``, ``numpass=4``.
Args:
unweighted_volume (ndarray): ndarray of the unweighted volumes brain volumes
median_radius (int): Radius (in voxels) of the applied median filter (default 4)
numpass (int): Number of pass of the median filter (default 4)
dilate (None or int): optional number of iterations for binary dilation
Returns:
ndarray: a 3D ndarray with the binary brain mask
"""
b0vol = unweighted_volume
logger = logging.getLogger(__name__)
logger.info('We will use a single precision float type for the calculations.'.format())
for env in mot.configuration.get_load_balancer().get_used_cl_environments(mot.configuration.get_cl_environments()):
logger.info('Using device \'{}\'.'.format(str(env)))
m = MedianFilter(median_radius)
b0vol = m.filter(b0vol, nmr_of_times=numpass)
thresh = _otsu(b0vol)
mask = b0vol > thresh
if dilate is not None:
cross = generate_binary_structure(3, 1)
mask = binary_dilation(mask, cross, iterations=dilate)
return mask
评论列表
文章目录