Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shiftnd crashes (also in example notebook) #55

Closed
ItayKishon-Q opened this issue Mar 17, 2024 · 2 comments · Fixed by #57
Closed

shiftnd crashes (also in example notebook) #55

ItayKishon-Q opened this issue Mar 17, 2024 · 2 comments · Fixed by #57

Comments

@ItayKishon-Q
Copy link
Contributor

Hi,
It seems that shift.shiftnd crashes, with the following error:

Cell In[4], line 4
      2 im1 = image_registration.tests.make_extended(100)
      3 # create an offset version corrupted by noise
----> 4 im2 = image_registration.tests.make_offset_extended(im1, 4.76666, -12.33333333333333333333333, noise=0.1)
      5 pl.subplot(121); img1=pl.imshow(im1, cmap='viridis', interpolation='nearest')
      6 pl.subplot(122); img2=pl.imshow(im2, cmap='viridis', interpolation='nearest')

File <myenv>/lib/python3.10/site-packages/image_registration/tests/registration_testing.py:124, in make_offset_extended(img, xsh, ysh, noise, mode, noise_taper)
    122     noise /= edge_weight(img.shape[0])
    123 #newimage = scipy.ndimage.map_coordinates(img+noise, [yy,xx], mode=mode)
--> 124 newimage = np.real(shift.shiftnd(img, (ysh, xsh))+noise)
    126 return newimage

File <myenv>/lib/python3.10/site-packages/image_registration/fft_tools/shift.py:100, in shiftnd(data, offset, phase, nthreads, use_numpy_fft, return_abs, return_real)
     97 if np.any(np.isnan(data)):
     98     data = np.nan_to_num(data)
--> 100 freq_grid = np.sum(
    101     [off*np.fft.fftfreq(nx)[
    102         tuple(
    103             [np.newaxis]*dim + [slice(None)] + [np.newaxis]*(data.ndim-dim-1)
    104             )
    105         ]
    106         for dim,(off,nx) in enumerate(zip(offset,data.shape))],
    107     axis=0)
    109 kernel = np.exp(-1j*2*np.pi*freq_grid-1j*phase)
    111 result = ifftn( fftn(data) * kernel )

File <myenv>/envs/itay_v1/lib/python3.10/site-packages/numpy/core/fromnumeric.py:2313, in sum(a, axis, dtype, out, keepdims, initial, where)
   2310         return out
   2311     return res
-> 2313 return _wrapreduction(a, np.add, 'sum', axis, dtype, out, keepdims=keepdims,
   2314                       initial=initial, where=where)

File <myenv>/lib/python3.10/site-packages/numpy/core/fromnumeric.py:88, in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
     85         else:
     86             return reduction(axis=axis, out=out, **passkwargs)
---> 88 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

Note that the above is from the package's official demo:
https://github.com/keflavich/image_registration/blob/master/examples/Cross%20Correlation.ipynb

BTW: the above notebook is missing import numpy as np

I have a wild guess that this has something to do with Numpy version, and that something has changed (perhaps in fft.fftfreq?).
I'm using Numpy v1.26.2

Thanks.

@keflavich
Copy link
Owner

Thanks, I can reproduce this with the minimal example in the readme. It may well be a numpy version issue.

@mikebrv-q
Copy link
Contributor

Thank you for updating. we would be happy if you could release a new version with this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants