code: def test_nifti_labels_masker_with_mask():
      """Test NiftiLabelsMasker with a separate mask_img parameter."""
      shape = (13, 11, 12, 3)
      affine = np.eye(4)
      fmri_img, mask_img = data_gen.generate_random_img(
          shape, affine=affine
      )
      labels_img = data_gen.generate_labeled_regions(
          shape[:3],
          affine=affine,
          n_regions=7,
      )
      masker = NiftiLabelsMasker(
          labels_img, resampling_target=None, mask_img=mask_img
      )
      signals = masker.fit().transform(fmri_img)
      bg_masker = NiftiMasker(mask_img).fit()
      masked_labels = bg_masker.inverse_transform(
          bg_masker.transform(labels_img),
      )
      masked_masker = NiftiLabelsMasker(
          masked_labels, resampling_target=None, mask_img=mask_img
      )
      masked_signals = masked_masker.fit().transform(fmri_img)
      assert np.allclose(signals, masked_signals)
  
      #  masker.region_atlas_ should be the same as the masked_labels
      # masked_labels is a 4D image with shape (13,11,12,1)
      masked_labels_data = get_data(masked_labels)[:, :, :, 0]
      assert np.allclose(
          get_data(masker.region_atlas_), masked_labels_data
      )
  
imports: import warnings
  import nibabel
  import numpy
  import pytest
  from nilearn._utils import data_gen, testing
  from nilearn._utils.exceptions import DimensionError
  from nilearn.image import get_data
  from nilearn.maskers import NiftiLabelsMasker, NiftiMasker
label_desc: Use image node_id 9 for calling a global function with example usage: test_nifti_labels_masker_with_mask() without return types