-
Notifications
You must be signed in to change notification settings - Fork 11
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
Comparison with Scikit-image Radon #1
Comments
hi! check out the development branch. i just updated the constants to use |
Thanks a lot for your commit! It works very well for forward and back projection! BTW, I compared pytorch_radon dev branch and scikit's radon's hann filtered backprojection. I'm using torch.double and the mean absolute difference between them is still around 1e-6. I checked through the codes and I'm not sure if this is still a precision loss any more. Did you implement the hann back projection in a different way from scikit? P.S. That's not a big difference, but I'm just very curious why that happened, because everything seems to be using torch.double now. |
Hm, might be related to |
ok, it is only partly related to
i can't explain this behavior but i will use the combination of rfft/ifft and commit it shortly |
I see! Thanks for locating this ifft problem, it totally slipped my mind... Maybe that's due to the the problem described here.pytorch/pytorch#19111, but I'm not exactly sure. I guess we don't need to worry about that. |
I notice another strange thing. Right now, in the test_radon.py, the phantom is first filled with zeros, and then the values of its center part are changed to 0.5. And it worked very well. However, instead of first filling it with zeros, if I first filled it with ones, or any values other than zero, and then changed the center part to 0.5, then the back projection's pixel at [0,0] alone differs a lot from the back projection from scikit (around 1e-3). The rest of the pixels differ very little from scikit (about 1e-14). I'm a beginner on the radon transform and don't quite understand the reason behind this. Do you know what's happening here? Many thanks! Actually, when I replace the testing phantom with any other real CT images, I can observe the same phenomena: the single pixel at [0,0] has a large difference from scikit, the rest pixels are the same. I've tested more phantoms on this problem: It seems that if I set the first two rows or the first two columns to zeros, then no matter how I changed the rest of the pixels of the phantom, the resulting back projections will be the same as scikit (difference within 1e-14). But I still don't figure out why is that... |
I also thought so first, but the problem there was that he used |
Can you show me your code? |
Here's my code. Basically all I did is changing the background of the phantom from zero to a non-zero number. _________________________________________________________________________________________________________________________________ from pytorch_radon import Radon, IRadon import torch import skimage.transform import numpy as np import sysset cuda device and display limitnp.set_printoptions(threshold=sys.maxsize, precision=20) create phantomFor the following line, I changed the torch.zeros to torch.ones.img = torch.ones(1, 1, 256, 256, dtype=torch.double) * 1 set thetatheta = torch.arange(180, dtype=torch.double).to(device).requires_grad_(True) forward project (torch and scikit)r = Radon(img.shape[2], theta, False, dtype=torch.double, device=device).to(device) backward project (torch and scikit)ir = IRadon(img.shape[2], theta, False, dtype=torch.double, use_filter=None, device=device).to(device) print the difference between the sinogramprint('comparing sinogram') print the difference between the reconstructionprint('comparing reconstruction') |
I think I found out where the errors come from. The problem is related to the grids that are created and used for the interpolation (both |
|
I see! Thanks a lot! Could you please push the changes to the repo? |
All the changes are now in the master branch :) |
I'm actually a bit confused here. Because Pytorch_radon has been using align_corners=True since the beginning, right? So basically that the difference at pixel [0, 0] between torch and scikit is due to the different implementation of the center of rotation, and the scikit is inaccurate because it uses |
I think so, yes. I just noticed something else. In your code above, try to change |
Hi! Many thanks for this repo! It is very helpful! I'm wondering if there is any difference with scikit-image's radon? For instance, if I run the following code, I would get a small difference between pytorch_radon and scikit-image's radon (around 1e-6 ~ 1e-8) . Is this because these two radon functions are implemented in different ways? Or is this because there's precision loss in torch? If this difference is due to precision loss, do you know of any ways to fix that? Thank you!
Follow up: I just fixed this precision issue, just need to change two lines of the utils.py like this.
The text was updated successfully, but these errors were encountered: