-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
iradon doesn't quantitatively agree with MATLAB #3742
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
Comments
Hey. Thanks for the detailed report. I’m trying to get one of the remaining PRs through that you listed with regards to iradon. If you can answer that last question I had in the review that would help it move forward. It seems that it still wouldn’t resolve the issues you are pointing out. to ensure the issue is resolved to your satisfaction, we will need some kind of test. It doesn’t have to be with real data. Feel free to create a phantom datasets or use numpy random functionality with a predetermined seed. If checking against the full matlab array is too complicated, maybe check against a few pixels? |
Hi @hmaarrfk, thanks for getting back to me. Before I create a test, it might be worth getting some feedback from people on whether the aim of skimage is to replicate the behaviour of MATLAB or not. I spoke to someone at my University yesterday who said that it's possible the off-by-one errors are not actually bugs, just a change in convention (although he wasn't certain without looking into it more). If the consensus is that it should agree with MATLAB I'm happy to make the changes and create a test, but I'd like clarification on that before I put in the work :) There is also the possibility that if this is a convention change and not a bug, that it will mess-up a lot of peoples code (although given the filters are also currently wrong, maybe that doesn't matter so much?) and that the forward radon transform might also need updating. Not being an expert in radon transforms though I can't be certain. |
The aim is to behave correctly, regardless of what MATLAB does! So, we have to figure out what desired behavior is outside of any software system, and then ensure we implement that. This module definitely needs more review, so your help is greatly valued. |
Right, my goal is to get the mathematics correct. I agree that there are some issues with the module. I would just like to get that PR pushed in since I think it definitely addresses some of the issues. Without a concrete little bit of code (should be about 10 lines long), it is really difficult to tell if anything would continue being wrong once PR #3067 gets merged in. |
@hmaarrfk I've attached some test code to demonstrate the issue. This code:
The changes I made in addition to PR #3067 were:
I think the key here is probably the additional padding (3.). I hadn't done this in my very first tests when reporting this issue, as it didn't seem to be necessary but it turns out it changes the results of the last row and column significantly (which I hadn't been looking at closely). Once the padding is applied, I think that the changes 1. and 4. flow naturally from that. The change in 2. might just be a convention, I'm honestly not sure. Of course none of this is to say that MATLAB is correct. But hopefully this is enough information for you to determine if the mathematics of the skimage radon transform are correct or not. If my proposed changes are just a change of convention in padding and/or determining the center point, then it might be worth exposing this through new keyword arguments so users can choose what to do. For example, it looks like there is possibly an alternative convention where the center is chosen as the boundary between pixels (if I'm reading the code of radontea correctly) |
Matlab creates a matlab engine for python, only to ignore numpy....
crazyness. These potential off by one errors are a little crazy. Ok, I kinda see your point, I would like to better understand if:
I think I need to get that PR through first. It seems like the right thing to do for now, I Just don't understand one line of it. |
Seems like padding is good clue. Might have to do with the diagonal of the image. not too sure. Also, seems like somebody else is looking at these kinds of errors: |
Hi, I also encountered a problem that may be caused by the iradon function. I tried to reconstruct an images in dimension of 512x512 from its radon measure in 50 views, i.e., Note: There are some difference between the Version Information |
Description
I've looked at PR #3067 and PR #3099 (addressing #2853) and PR #683 and while the first two do fix some issues with the
iradon
function and the last improves feature parity between the skimage iradon and the MATLAB iradon, the output between the two (at least for my dataset) does not quantitatively agree.The error appears to be cause by 3 off-by-one errors that I believe probably crept in when the code was originally ported from MATLAB code. I think whoever did this probably missed the fact that the
A:B
style syntax in MATLAB is used both as slicing (in which case you need to reduceA
by 1 in Python to handle the 0 indexing of Python) and for defining a range (in which case you want to incrementB
by 1 in Python to account for the fact that ranges in MATLAB include the last integer whereas in Python they do not).The fix (also requires PR #3067) is to the following two lines:
[X, Y] = np.mgrid[0:output_size, 0:output_size]
and
x = np.arange(radon_filtered.shape[0]) - mid_index
which must become
[X, Y] = np.mgrid[1:output_size+1, 1:output_size+1]
and
x = np.arange(1,radon_filtered.shape[0]+1) - mid_index
This increments the start of the ranges by 1 to undo the incorrect translation (so now the indices would match the original MATLAB code) and then increments the end point of the ranges by 1 to apply the correct translation between MATLAB and Python code. This change (merged with PR #3067) then gives me quantitatively the same output as MATLAB.
Caveat: I can't provide the data I'm working on as it's not data I'm allowed to make public. However I can tell you that
radon_image
is a 26x30 and I'm calling iradon withtheta = np.arange(0,180,6), output_size=20, filter='ramp', interpolation='linear', circle=False
Version information
The text was updated successfully, but these errors were encountered: