applying an AffineMap resampling with " interpolation = 'nearest' " returns error " TypeError: No matching signature found "

Hi - I'm running a script that registers MR images to MNI space, producing an AffineMap object 'final' for each registration ('final' is the result of iterative registrations with increasing degrees of freedom). For resampling the transformed scan I use: resampled = final.transform ( grey ); without any problem, using trilinear interpolation. I also have an atlas with discrete atlas labels -that should not be interpolated- so the line I am using for that is: resampled = final.transform ( atl, interpolation='nearest' ); but that results in the error message "TypeError: No matching signature found" According to the documentation though, that should be the syntax [ https://dipy.org/documentation/1.4.0./reference/dipy.align/#dipy.align._publ... ]. The value 'linear' gives no error: resampled = final.transform ( atl, interpolation='nearest' ); produces the same result as not using the interpolation parameter. Does anyone know why " interpolation = 'nearest' " does not work? Should I have specified this already during the registration process? I'm not sure what the error message means because the strings 'linear' and 'nearest' are of the same type! Many thanks, Alle Meije

Hi Alle I confirm that is strange. Can you create an issue on DIPY Github and provide the full error and a sample of your code. Also, I recommend you check your atlas space. Otherwise, you need to define image_grid2world, sampling_grid_shape, sampling_grid2world arguments variables. Thank you for your feedback! Serge K ------------------------------ Simple is better than complex | http://pythonastuces.com On Thu, Jun 24, 2021 at 4:01 PM Alle Meije Wink <a.m.wink@gmail.com> wrote:

Hi Jongsung, thanks! It's what I could find too. That's where the final comment came from: the exact same command with " interpolation = 'linear' " does work, but replacing only 'linear' by 'nearest' makes it stop. I just cannot see the difference between the two in type?! bw Alle Meije On Thu, 2021-06-24 at 14:19 -0400, jongsung park wrote:

Can you try changing the dtype of your image to np.float64( i.e image = image.astype(np.float64) ) before you run transform? I'm not sure but this might solve the issue. P.S I hit reply instead of reply all by mistake, so you might be getting the same message twice. Sincerely, Jong Sung Park On Fri, Jun 25, 2021 at 7:56 AM Alle Meije Wink <a.m.wink@gmail.com> wrote:

Thanks, will do! Will also check the atlas space, but: how would that make the same command work with " interpolation = 'linear' " and not with 'nearest' (or without the interpolation option)? I would guess the two options don't use the coordinates differently? bw All eMeije On Thu, 2021-06-24 at 16:21 +0200, Serge K. wrote:

I'm not sure about the reasons behind it yet, but 'linear' has a step of changing your image data to a np.float64 data type before transform, while 'nearest' does not. I think it's because 'nearest' just looks for the closest coordinate while 'linear' uses distance weights among all the neighbors(thus it has to be a float data type). But my guess was that there might be a function or code that requires the image to be a float type somewhere in the 'nearest' option. Sincerely, Jong Sung Park On Fri, Jun 25, 2021 at 11:43 AM Alle Meije Wink <a.m.wink@gmail.com> wrote:

Hi Alle I confirm that is strange. Can you create an issue on DIPY Github and provide the full error and a sample of your code. Also, I recommend you check your atlas space. Otherwise, you need to define image_grid2world, sampling_grid_shape, sampling_grid2world arguments variables. Thank you for your feedback! Serge K ------------------------------ Simple is better than complex | http://pythonastuces.com On Thu, Jun 24, 2021 at 4:01 PM Alle Meije Wink <a.m.wink@gmail.com> wrote:

Hi Jongsung, thanks! It's what I could find too. That's where the final comment came from: the exact same command with " interpolation = 'linear' " does work, but replacing only 'linear' by 'nearest' makes it stop. I just cannot see the difference between the two in type?! bw Alle Meije On Thu, 2021-06-24 at 14:19 -0400, jongsung park wrote:

Can you try changing the dtype of your image to np.float64( i.e image = image.astype(np.float64) ) before you run transform? I'm not sure but this might solve the issue. P.S I hit reply instead of reply all by mistake, so you might be getting the same message twice. Sincerely, Jong Sung Park On Fri, Jun 25, 2021 at 7:56 AM Alle Meije Wink <a.m.wink@gmail.com> wrote:

Thanks, will do! Will also check the atlas space, but: how would that make the same command work with " interpolation = 'linear' " and not with 'nearest' (or without the interpolation option)? I would guess the two options don't use the coordinates differently? bw All eMeije On Thu, 2021-06-24 at 16:21 +0200, Serge K. wrote:

I'm not sure about the reasons behind it yet, but 'linear' has a step of changing your image data to a np.float64 data type before transform, while 'nearest' does not. I think it's because 'nearest' just looks for the closest coordinate while 'linear' uses distance weights among all the neighbors(thus it has to be a float data type). But my guess was that there might be a function or code that requires the image to be a float type somewhere in the 'nearest' option. Sincerely, Jong Sung Park On Fri, Jun 25, 2021 at 11:43 AM Alle Meije Wink <a.m.wink@gmail.com> wrote:
participants (3)
-
Alle Meije Wink
-
jongsung park
-
Serge K.