How to denoise fMRIprep data and output the denoised nii file in nilearn

Hi i’m using denoise my fMRIprep data, it seems that masker.fit_transform outputs a timeseries ndarray object. How can i write this ndarray object into a .nii.gz file?

from nilearn.maskers import NiftiMasker
from nilearn.interfaces.fmriprep import load_confounds

masker = NiftiMasker(standardize=True,  low_pass=0.1,  t_r=1.97)
conf, sample_mask= load_confounds("sub-1003_task-rest_space-MNI152NLin6Asym_desc-preproc_bold.nii.gz",strategy=("high_pass", "motion", "wm_csf","global_signal"), motion="full", wm_csf="full",global_signal="full")
time_series = masker.fit_transform("sub-1003_task-rest_space-MNI152NLin6Asym_desc-preproc_bold.nii.gz",confounds=conf)

Hi @gerardyu,

You can use nilearn.image.new_img_like - Nilearn to make a new nifti from that time series.

Best,
Steven

2 Likes