Example #1
0
def load_masker(path, **kwargs):
    params = read_yaml(path + '.yml')
    mask_img = nib.load(path + '.nii.gz')
    masker = NiftiMasker(mask_img)
    masker.set_params(**params)
    if kwargs:
        masker.set_params(**kwargs)
    masker.fit()
    return masker
Example #2
0
def get_roi_mask(
    atlas_maps,
    index_mask,
    labels,
    path=None,
    global_mask=None,
    resample_to_img_=None,
    intersect_with_img=False,
    PROJECT_PATH="/neurospin/unicog/protocols/IRMf/LePetitPrince_Pallier_2018/LePetitPrince/"
):
    """Return the Niftimasker object for a given ROI based on an atlas.
    Optionally resampled based on a resample_to_img_ image and another masker (global masker) parameters.  
    """
    if path is None:
        check_folder(os.path.join(PROJECT_PATH, 'derivatives/fMRI/ROI_masks'))
        path = os.path.join(
            PROJECT_PATH, 'derivatives/fMRI/ROI_masks',
            labels[index_mask])  #be careful to remove ‘background‘ from labels
    if os.path.exists(path + '.nii.gz') and os.path.exists(path + '.yml'):
        masker = load_masker(path,
                             resample_to_img_=resample_to_img_,
                             intersect_with_img=intersect_with_img)
    else:
        mask = math_img('img=={}'.format(index_mask + 1), img=atlas_maps)
        if resample_to_img_ is not None:
            mask = resample_to_img(mask,
                                   resample_to_img_,
                                   interpolation='nearest')
            if intersect_with_img:
                mask_img = math_img('img==2',
                                    img=math_img('img1+img2',
                                                 img1=mask_img,
                                                 img2=resample_to_img_))
        masker = NiftiMasker(mask)
        if global_mask:
            params = read_yaml(global_mask + '.yml')
            params['detrend'] = False
            params['standardize'] = False
            masker.set_params(**params)
        masker.fit()
        save_masker(masker, path)
    return masker
Example #3
0
def load_masker(path,
                resample_to_img_=None,
                intersect_with_img=False,
                **kwargs):
    params = read_yaml(path + '.yml')
    mask_img = nib.load(path + '.nii.gz')
    if resample_to_img_ is not None:
        mask_img = resample_to_img(mask_img,
                                   resample_to_img_,
                                   interpolation='nearest')
        if intersect_with_img:
            mask_img = math_img('img==2',
                                img=math_img('img1+img2',
                                             img1=mask_img,
                                             img2=resample_to_img_))
    masker = NiftiMasker(mask_img)
    masker.set_params(**params)
    if kwargs:
        masker.set_params(**kwargs)
    masker.fit()
    return masker
Example #4
0
def get_roi_mask(atlas_maps, index_mask, labels, path=None, global_mask=None):
    """Return the Niftimasker object for a given ROI based on an atlas.
    Optionally resampled based on a global masker.  
    """
    if path is None:
        path = os.path.join(PROJECT_PATH, 'derivatives/fMRI/ROI_masks', labels[index_mask+1])
        check_folder(path)
    if os.path.exists(path + '.nii.gz') and os.path.exists(path + '.yml'):
        masker = load_masker(path)
    else:
        mask = math_img('img > 50', img=index_img(atlas_maps, index_mask))
        if global_mask:
            global_masker = nib.load(global_mask + '.nii.gz')
            mask = resample_to_img(mask, global_masker, interpolation='nearest')
            params = read_yaml(global_mask + '.yml')
            params['detrend'] = False
            params['standardize'] = False
        masker = NiftiMasker(mask)
        if global_mask:
            masker.set_params(**params)
        masker.fit()
        save_masker(masker, path)
    return masker
Example #5
0
    FMRIDATA_PATH,
    INPUT_PATH,
    smoothing_fwhm=None,
    logger=logger)

original_masker = global_masker_50
new_masker = global_masker_95
original_masker.set_params(detrend=False, standardize=False)
new_masker.set_params(detrend=False, standardize=False)

params = global_masker_95.get_params()
new_img = new_img_like(
    global_masker_95.mask_img,
    scipy.ndimage.binary_dilation(global_masker_95.mask_img.get_data()))
dilated_global_masker_95 = NiftiMasker()
dilated_global_masker_95.set_params(**params)
dilated_global_masker_95.mask_img = new_img
dilated_global_masker_95.fit()

atlas_maps, labels = reporting.load_atlas()
subject_names_list = [
    utils.get_subject_name(sub_id)
    for sub_id in utils.possible_subjects_id(language)
]
subject_ids_list = utils.possible_subjects_id(language)


def dilate_img(img):
    if type(img) == str:
        img = nib.load(img)
    data = img.get_data()