NiftiMasker error - 'labels_img and imgs affines must be identical'

when I ran masker label , after maskerLabels.fit_transform(current)

I get the error :
“labels_img and imgs affines must be identical” although the affines seems identical.
the func image was preprocessed in fsl feat.
I’m adding the FSL headers.
what might be the problem and solution?
Thanks in advance,
Keren

func hd:
sizeof_hdr 348
data_type FLOAT32
dim0 4
dim1 96
dim2 96
dim3 35
dim4 292
dim5 1
dim6 1
dim7 1
vox_units mm
time_units s
datatype 16
nbyper 4
bitpix 32
pixdim0 0.000000
pixdim1 2.613636
pixdim2 2.613636
pixdim3 3.000000
pixdim4 2.000000
pixdim5 0.000000
pixdim6 0.000000
pixdim7 0.000000
vox_offset 352
cal_max 0.0000
cal_min 0.0000
scl_slope 1.000000
scl_inter 0.000000
phase_dim 0
freq_dim 0
slice_dim 0
slice_name Unknown
slice_code 0
slice_start 0
slice_end 0
slice_duration 0.000000
time_offset 0.000000
intent Unknown
intent_code 0
intent_name
intent_p1 0.000000
intent_p2 0.000000
intent_p3 0.000000
qform_name Scanner Anat
qform_code 1
qto_xyz:1 -2.593575 -0.265615 0.211372 116.595695
qto_xyz:2 -0.195844 2.476147 0.933511 -136.118576
qto_xyz:3 0.257114 -0.793245 2.843216 -49.637619
qto_xyz:4 0.000000 0.000000 0.000000 1.000000
qform_xorient Right-to-Left
qform_yorient Posterior-to-Anterior
qform_zorient Inferior-to-Superior
sform_name Scanner Anat
sform_code 1
sto_xyz:1 -2.593575 -0.265615 0.211372 116.595695
sto_xyz:2 -0.195844 2.476147 0.933511 -136.118576
sto_xyz:3 0.257114 -0.793245 2.843216 -49.637619
sto_xyz:4 0.000000 0.000000 0.000000 1.000000
sform_xorient Right-to-Left
sform_yorient Posterior-to-Anterior
sform_zorient Inferior-to-Superior
file_type NIFTI-1+
file_code 1
descrip FSL5.0
aux_file

label hd :slight_smile:
sizeof_hdr 348
data_type FLOAT64
dim0 3
dim1 96
dim2 96
dim3 35
dim4 1
dim5 1
dim6 1
dim7 1
vox_units mm
time_units Unknown
datatype 64
nbyper 8
bitpix 64
pixdim0 0.000000
pixdim1 2.613636
pixdim2 2.613636
pixdim3 3.000000
pixdim4 0.000000
pixdim5 0.000000
pixdim6 0.000000
pixdim7 0.000000
vox_offset 352
cal_max 0.0000
cal_min 0.0000
scl_slope 1.000000
scl_inter 0.000000
phase_dim 0
freq_dim 0
slice_dim 0
slice_name Unknown
slice_code 0
slice_start 0
slice_end 0
slice_duration 0.000000
time_offset 0.000000
intent Unknown
intent_code 0
intent_name
intent_p1 0.000000
intent_p2 0.000000
intent_p3 0.000000
qform_name Scanner Anat
qform_code 1
qto_xyz:1 -2.593575 -0.265615 0.211372 116.595695
qto_xyz:2 -0.195844 2.476147 0.933511 -136.118576
qto_xyz:3 0.257114 -0.793245 2.843216 -49.637619
qto_xyz:4 0.000000 0.000000 0.000000 1.000000
qform_xorient Right-to-Left
qform_yorient Posterior-to-Anterior
qform_zorient Inferior-to-Superior
sform_name Unknown
sform_code 0
sto_xyz:1 0.000000 0.000000 0.000000 0.000000
sto_xyz:2 0.000000 0.000000 0.000000 0.000000
sto_xyz:3 0.000000 0.000000 0.000000 0.000000
sto_xyz:4 0.000000 0.000000 0.000000 0.000000
sform_xorient Unknown
sform_yorient Unknown
sform_zorient Unknown
file_type NIFTI-1+
file_code 1
descrip
aux_file

Oh God, these headers…
Please simply do

import nibabel as nib
# assuming that your images are called 'img1' and 'img2'
print(nib.load(img1).affine)
print(nib.load(img2).affine)

If they differ you might simply want to resample one of the images onto the other. you can use nilearn.image.resample_img for that.

HTH

@bthirion in my case the headers are identical when I load the images in fsleyes and look at the SForm/QForm matrices.
If I load the images in nibabel and do img1.affine and img2.affine it seems that img1.affine has one less decimal digit in one of the cells than img2 and this is enough for nilearn to believe they have different affines.

OK.
Does resampling the labels_img to imgs (resample_to_img) solve the problem ?
Best,
Bertrand