How can I use nilearn.image.clean_img to remove sample_mask?

Summary of what happened:

Dear Sir/Madam
I am a beginner in Python and I am working on constructing functional connectivity from preprocessed fMRI data. Before that, I am trying to apply some denoising steps. First, I used nilearn.interfaces.fmriprep.load_confounds_strategy to extract the confounds I need, then I applied nilearn.image.clean_img for denoising. However, I noticed that while the simple_mask parameter can be passed to nilearn.signal.clean, it cannot be used with nilearn.image.clean_img (which is more convenient for me as it takes images as input). I am wondering if there is a way to resolve this?

Additionally, I would like to use an atlas (not included in nilearn.datasets.fetch) to extract time series signals. How can I import my custom atlas for use in this process?

Command used (and if a helper script was used, a link to the helper script or the command generated):

clean_img = nilearn.image.clean_img(img, runs=None, detrend=True, standardize=True, 
                                    confounds=None, low_pass=None, high_pass=None, 
                                    t_r=None, ensure_finite=False, mask_img=None)
nib.save(clean_img, 'path/to/save/rest_cleaned.nii.gz')

img_files = 'C:/Users/10852/Desktop/HUproject/derivatives/fmriprep/sub-0002/func/sub-0002_task-gstroop_acq-seq_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz'
[confounds, simplemask] = nilearn.interfaces.fmriprep.load_confounds_strategy(img_files, denoise_strategy='simple')

Version:

(nilearn.version)
0.10.3

Environment (Docker, Singularity / Apptainer, custom installation):

Data formatted according to a validatable standard? Please provide the output of the validator:

PASTE VALIDATOR OUTPUT HERE

Relevant log outputs (up to 20 lines):

PASTE LOG OUTPUT HERE

Screenshots / relevant information:

When using fMRIPrep for preprocessing data, what are the recommended post-processing steps before constructing functional connectivity for both resting-state and task-based data?
Thank you very much!


quick question: does this section the “Extracting signals from a brain parcellation” example help you with what you want to do?

You may also want to check the giga connectome bids app that takes an fmriprep dataset as input and should be able to do some of the things you want to do:

an atlas not included in nilearn.datasets.fetch

which one is it?

Thank you for your reply!it has been very helpful. :+1: I want to apply detrending, a band-pass filter, and nuisance regression. It seems that in this example, nuisance regression has already been applied, and load_confounds appears to support filtering. In that case, I think I need to perform detrending before (or after?) processing. I want to use the Brainnetome Atlas (BNA) (Brainnetome Atlas | Atlas) or the volumetric version of the HCP-MMP1.0 parcellation (HCP-MMP1.0 projected on MNI2009a GM (volumetric) in NIfTI format). To summarize, based on the fMRIprep-preprocessed data, I want to apply detrending, nuisance regression, and then extract signal to constrcut connetome based on the BNA (or HCP) atlas.

I am currently a bit confused about the optimal steps. Which functions in nilearn can help me complete this process? I have not used giga_connectome before; it looks good, but I am not sure about the detrending step. Also, I am still unsure how to load the atlas I want.