def get_protocol(self): super(BatchFitProtocolLoader, self).get_protocol() if self._protocol_fname and os.path.isfile(self._protocol_fname): return load_protocol(self._protocol_fname) return auto_load_protocol(self._base_dir, protocol_columns=self._protocol_columns, bvec_fname=self._bvec_fname, bval_fname=self._bval_fname)
def get_protocol(self): if self._protocol_fname and os.path.isfile(self._protocol_fname): return load_protocol(self._protocol_fname) return auto_load_protocol(self._base_dir, protocol_columns=self._protocol_columns, bvec_fname=self._bvec_fname, bval_fname=self._bval_fname)
def create_median_otsu_brain_mask(dwi_info, protocol, mask_threshold=0, fill_holes=True, **kwargs): """Create a brain mask using the given volume. Args: dwi_info (string or tuple or image): The information about the volume, either: - the filename of the input file - or a tuple with as first index a ndarray with the DWI and as second index the header - or only the image as an ndarray protocol (string or :class:`~mdt.protocols.Protocol`): The filename of the protocol file or a Protocol object mask_threshold (float): everything below this b-value threshold is masked away (value in s/m^2) fill_holes (boolean): if we will fill holes after the median otsu algorithm and before the thresholding **kwargs: the additional arguments for median_otsu. Returns: ndarray: The created brain mask """ logger = logging.getLogger(__name__) logger.info('Starting calculating a brain mask') if isinstance(dwi_info, str): signal_img = load_nifti(dwi_info) dwi = signal_img.get_data() elif isinstance(dwi_info, (tuple, list)): dwi = dwi_info[0] else: dwi = dwi_info if isinstance(protocol, str): protocol = load_protocol(protocol) if len(dwi.shape) == 4: unweighted_ind = protocol.get_unweighted_indices() if len(unweighted_ind): unweighted = np.mean(dwi[..., unweighted_ind], axis=3) else: unweighted = np.mean(dwi, axis=3) else: unweighted = dwi.copy() brain_mask = median_otsu(unweighted, **kwargs) brain_mask = brain_mask > 0 if fill_holes: brain_mask = binary_fill_holes(brain_mask) if mask_threshold: brain_mask = np.mean(dwi[..., protocol.get_weighted_indices()], axis=3) * brain_mask > mask_threshold logger.info('Finished calculating a brain mask') return brain_mask
def get_protocol(self): if self._protocol is None: self._protocol = load_protocol(self._filename) return self._protocol