Does NiftiLabelsMasker.fit_transform() only resample images?

I would like to learn how fit_transform register atlas map image with input images.
But I find the registration of image data is not performed?
Nilearn only use affine of input image to let atlas map image aligned with input image in image.resample_img()?
So, atlas map image will align the same with NIFTI images with same affine?

I tried to find what NiftiLabelsMasker.fit_transform() do.

line 531 in nilearn/nilearn/maskers/nifti_labels_masker.py :
return self.fit(imgs).transform(

-> line 268 nilearn/nilearn/maskers/base_masker.py :
return self.transform_single_imgs

-> line 543 nilearn/nilearn/maskers/nifti_labels_masker.py :
def transform_single_imgs(self, imgs, confounds=None, sample_mask=None)

Because line 90 nilearn/nilearn/maskers/nifti_labels_masker.py :

resampling_target : {"data", "labels", None}, default="data"

We goes to line 606-613 nilearn/nilearn/maskers/nifti_labels_masker.py :

self._resampled_labels_img_ = self._cache(
image.resample_img, func_memory_level=2
)(
self.labels_img_,
interpolation="nearest",
target_shape=imgs_.shape[:3],
target_affine=imgs_.affine,
)

“imgs_” is our input images.
“self.labels_img_” is atlas map image.

Here we can see that image.resample_img is the key function of NiftiLabelsMasker.fit_transform().
However, it just uses shape and affine of our input images.
So, atlas map image will align the same with NIFTI images with same affine?
Is that means we should first register our images in MNI space before calling NiftiLabelsMasker.fit_transform()?

Hi @RenchZhao, and welcome to neurostars!

It does not have to be MNI, but the labels image should be in the same space as the image you are applying the labels to.

Best,
Steven

Good day, Steven. Nice to talk with you.

So we should register labels image and the input image first if they are not in the same space?
For example using flirt or fnirt in FSL to register them first?