Repository navigation
Refactor radon transform module - #4136
Conversation
sciunto
left a comment
There was a problem hiding this comment.
Great work! Thanks for this contribution. I made minor comments only, the result is much easier to read 👍
Can you check that this does not introduce any performance regression please? (likely not)
|
Thank you @sciunto for your kind comments and for your review. I already made some tests and I observed no performance drop: SetupIn [1]: from skimage.transform.radon_transform import order_angles_golden_ratio, radon, iradon
In [2]: from skimage.data import shepp_logan_phantom
In [3]: image = shepp_logan_phantom()
In [4]: theta = np.linspace(0., 180., max(image.shape), endpoint=False)
In [5]: sinogram = radon(image, theta=theta, circle=True) Actual versionIn [6]: %timeit -n10 -r10 iradon(sinogram, theta=theta, circle=True)
572 ms ± 9.51 ms per loop (mean ± std. dev. of 10 runs, 10 loops each)
In [7]: %timeit -n10 -r10 radon(image, theta=theta, circle=True)
1.21 s ± 4.71 ms per loop (mean ± std. dev. of 10 runs, 10 loops each)
In [8]: %timeit -n10 -r10 [x for x in order_angles_golden_ratio(theta)]
6.96 ms ± 312 µs per loop (mean ± std. dev. of 10 runs, 10 loops each)Refactored versionIn [6]: %timeit -n10 -r10 iradon(sinogram, theta=theta, circle=True)
572 ms ± 769 µs per loop (mean ± std. dev. of 10 runs, 10 loops each)
In [7]: %timeit -n10 -r10 radon(image, theta=theta, circle=True)
1.2 s ± 3.18 ms per loop (mean ± std. dev. of 10 runs, 10 loops each)
In [8]: %timeit -n10 -r10 [x for x in order_angles_golden_ratio(theta)]
6.66 ms ± 285 µs per loop (mean ± std. dev. of 10 runs, 10 loops each) |
|
Perfect. we just need a second approval by another core dev. |
|
Thank you @sciunto, my last commit is just about replacing |
|
Given the golden ratio γ. It's inverse |
|
is this going to conflict with: #4131 which one do you want us to look at first? |
| else: | ||
| slices.append(slice(None)) | ||
| slices = tuple(slices) | ||
| slices = find_objects((~outside_reconstruction_circle).astype(int))[0] |
There was a problem hiding this comment.
calling find_objects is more elegant, but it takes a few ms for a 2000x2000 image. This is not a big deal since the whole function takes several seconds to complete, but if someday we accelerate massively this function (the loop on angles could easily be parallelized) it could be significant. Even then it would only represent around 10% of the execution time so I'm ok with this change, I just wanted to raise this point in case somebody wants to comment.
There was a problem hiding this comment.
Seems silly to analyze the data instead of the metadata when looking for a slice....
There was a problem hiding this comment.
I agree with you, the use of find_object requires also negating outside_reconstruction_circle and casing it to int, which is a lot of processing to find the desired slice...
My last commit removes the call to find_object.
|
I just left one comment, but it looks good to me so I'll merge tomorrow if there's nothing to add. Note that it would be great to parallelize the loop on angles (if it is the bottleneck which I did not check, but it's likely). |
|
Thank you @emmanuelle for your feedback. I also think that the |
soupault
left a comment
There was a problem hiding this comment.
One minor suggestion, otherwise 👍 . Thanks for the PR, it is a good work!
| if not output_size: | ||
|
|
||
| filter_types = ('ramp', 'shepp-logan', 'cosine', 'hamming', 'hann', None) | ||
| if filter not in filter_types: |
There was a problem hiding this comment.
Oh, wow, this is a terrible name for an argument. I think we should fix this and the similar cases all across the library. In a different PR, of course.
There was a problem hiding this comment.
I fully agree with you, but this is the original argument name!
I also opened an equivalent issue in scipy where input is used as argument name in many functions. This issue was closed and will not be fixed for retro-compatibility reasons :-(
I proposed this gist as a solution for this problem. I don't know if skimage accepts such a solution...
There was a problem hiding this comment.
@rfezzani can't blame Ralf, that is understandable from the core developer perspective 😄. We have had a brief discussion with the similar outcome recently - #2838 (review), but I still believe that we should change that. The proper approach is to deprecate all the occurencies of such cases in the public API (practically, similar to your gist). I have raised a ticket for this - #4152, feel free to jump into the discussion.
There was a problem hiding this comment.
Of course, this is understandable, but a little bit sad 😄 I would be happy to help on this ;-)
| [-np.sin(T), np.cos(T), 0], | ||
| for i, T in enumerate(np.deg2rad(theta)): | ||
| cos_T, sin_T = np.cos(T), np.sin(T) | ||
| R = np.array([[cos_T, sin_T, -center * (cos_T + sin_T - 1)], |
There was a problem hiding this comment.
Please, use lowercase for the variable names.
|
@rfezzani Looking good, thanks for the contribution! |
Description
The major changes introduced by this PR are:
warpinstead of_warp_fastto ease the maintenance when an enhancement/fix is introduced to_warp_cy(_warp_fastis now called only by thewarpfunction),build_rotationinradonandangle_distanceinorder_angles_golden_ratio),_get_fourier_filterfunction to improveiradonreadability,radon,ifstatements,scipy.ndimage.measurements.find_objectsto find reconstruction circle area instead of a hand made loop,functools.partialto makenp.interpcall consistent withscipy.interpolate.interp1dcall iniradonThis results in some lines drop and no API change is introduced.
Checklist
./doc/examples(new features only)./benchmarks, if your changes aren't covered by anexisting benchmark
For reviewers
later.
__init__.py.doc/release/release_dev.rst.@meeseeksdev backport to v0.14.x