nilearn icon indicating copy to clipboard operation
nilearn copied to clipboard

Different results when using `resample_to_img` function

Open mdiazmel opened this issue 6 years ago • 11 comments

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: np050

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: np061

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,

mdiazmel avatar Feb 07 '20 10:02 mdiazmel

Thanks for reporting! I will try to have a look. could you by any chance share the images and a script to reproduce?

jeromedockes avatar Feb 07 '20 11:02 jeromedockes

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.

mdiazmel avatar Feb 07 '20 13:02 mdiazmel

@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. Thanks a lot for your help, I will let you know if I have more questions!

jeromedockes avatar Feb 07 '20 14:02 jeromedockes

I can reproduce the bug, but I don't have the fix yet...

bthirion avatar Feb 24 '20 22:02 bthirion

sorry for taking so long to get back to this. the bug was introduced in #2025 . i will try to open a pr today

jeromedockes avatar Mar 11 '20 13:03 jeromedockes

note that in the meanwhile you can fix your problem by passing force_resample=True to resample_to_img

jeromedockes avatar Mar 11 '20 18:03 jeromedockes

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 avatar Jan 18 '21 15:01 NicolasGensollen

@NicolasGensollen AFAIK it hasn't been addressed

jeromedockes avatar Aug 17 '21 14:08 jeromedockes

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.

ajoshiusc avatar May 12 '24 18:05 ajoshiusc

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 ?

bthirion avatar May 12 '24 20:05 bthirion

Created PR. thanks,

ajoshiusc avatar May 13 '24 19:05 ajoshiusc