Different results when using `resample_to_img` function
Hi,
I've been trying to use the resample_to_img function to crop a T1 image based on a template. Both image are previously aligned. Every works fine using nilearn v.0.5.0:
crop_img = resample_to_img(input_img, crop_template)
plot_anat(crop_img)
produces:

but when executing the same code (and the same inputs) with nilearn v0.6.1, the output image is not cropped at the right values:

It seems that there was some refactoring work on the file nilearn/image/resampling.py at the commit ee1f25a908d8357b4fba84dab1d2b7018e9f5e04 . It's maybe related to the changes on the behavior of this function?
Thanks in advance,
Thanks for reporting! I will try to have a look. could you by any chance share the images and a script to reproduce?
Yes, of course. Files can be (temporary) available here. The following snippet will reproduce the code (try it with both versions):
from nilearn.image import resample_img, crop_img, resample_to_img
from nilearn.plotting import plot_anat
input_img = './inputs/input_img.nii.gz'
crop_template = './inputs/ref_cropped_template.nii.gz'
crop_img = resample_to_img(input_img, crop_template)
plot_anat(crop_img)
@jeromedockes : if I can do any thing else, don't hesitate to tell me, but I'm pretty new with nilearn and I don't known exactly where to start debugging this function.
@jeromedockes : if I can do any thing else, don't hesitate to tell me, but I'm pretty new with
nilearnand I don't known exactly where to start debugging this function. Thanks a lot for your help, I will let you know if I have more questions!
I can reproduce the bug, but I don't have the fix yet...
sorry for taking so long to get back to this. the bug was introduced in #2025 . i will try to open a pr today
note that in the meanwhile you can fix your problem by passing force_resample=True to resample_to_img
Has this bug been addressed? I cannot reproduce since the files are not available anymore, but the changes introduced in #2025 are still there AFAICT.
@NicolasGensollen AFAIK it hasn't been addressed
I encountered this bug today. While the bug is being fixed, force_resample=True should be made default for the functions resample_img and resample_to_img. The force_resample=False which is currently default, the code is not implemented correctly and I see lot of #TODO flags in the code for force_resample=False case.
Thx for raising ! I think that you're right. Th only issue is that we need to go through deprecation cycels for all API changes. Do you want to open a PR ?
Created PR. thanks,