mmuckley / torchkbnufft

A high-level, easy-to-deploy non-uniform Fast Fourier Transform in PyTorch.
https://torchkbnufft.readthedocs.io/
MIT License
201 stars 44 forks source link

KbInterpAdjoint gives mismatch results? #90

Closed razgzy closed 1 year ago

razgzy commented 1 year ago

The omega is given by np.mgrid as on-grid locaiton 2 pi n / N

data = torch.randn(1, 1, 8, 8) + 1j * torch.randn(1, 1, 8, 8)
[x, y] = np.mgrid[-4:4, -4:4].astype(np.float32) * np.pi / 8
omega = torch.stack([torch.tensor(x), torch.tensor(y)], dim=0)
adjkb_ob = tkbn.KbInterpAdjoint(im_size=(8, 8), grid_size=(8, 8))
image = adjkb_ob(data.view(1, 1, -1), omega.view(2, -1))
plt.figure()
plt.imshow(data.squeeze().abs())
plt.figure()
plt.imshow(image.squeeze().abs())
plt.show()

image The left one is the original data and the right is after interpolation. They are quite different ! I wonder whether the on-grid location after interpolation is 2 pi n / N ?

mmuckley commented 1 year ago

Hello @razgzy, we test numerical precision to exactly match the original NUFFT implementation in the Michigan Image Reconstruction Toolbox, so there is almost certainly no issue with the implementation, but rather a misunderstanding of how the NUFFT works.

In this case, I wouldn't expect data to be the same before and after NUFFT. If you're expecting the noise to be even due to the orthogonality of the FFT and the on-grid samples, then the issue might be that the coordinates are slightly off. You'd want to use -4:3.

razgzy commented 1 year ago

Sorry I misunderstood the interpolation. Thanks a lot for your reply.

mmuckley commented 1 year ago

Hello @razgzy no worries at all! If you have further questions feel free to open a Q&A Discussion rather than an Issue - we use these to document bugs and things that aren't working with the package.