-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Simplify resize implementation using new SciPy 1.6 zoom option #5173
Conversation
- Round trips start with stains, such that the roundtrip does not require negative values. - Using a blue+red+orange stain combination, the test previously used a 2-stain combination that made it impossible to do a correct roundtrip.
use grid-constant and grid-wrap for SciPy >= 1.6.0 closes scikit-imagegh-5064
Hello @grlee77! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2021-01-22 02:51:54 UTC |
|
Maybe an item should be added in the TODO so that we don't forget to remove the other code when the scipy dep is bumped to 1.6 (this will probably take some time... so a reminder might be good). |
Improvement to the IHC example. Co-authored-by: Riadh Fezzani <rfezzani@gmail.com>
I was relying on SciPy to raise on unrecognized modes, but SciPy raises a |
* When ``scipy`` is set to >= 1.16, remove legacy (i.e. non-zoom) code paths in | ||
``skimage.transform.resize``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to NEP-29, we can now do date-based reminders (🎉!): this will be done on Jan 1 2022. Should we add a separate time-based section to the todos?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea, yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops — that should be 2023. Time flies when you're having fun! =P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See how this latest commit reorganizing the "Other" section looks.
We can actually do many of the 2021 items now (we already require NumPy 1.16 and we SciPy 1.1 was released in May 2018).
Love it! I think the few specific cases where performance is worse, the tradeoff is worth it for code simplicity. |
Stain unmixing fix
…cikit-image#5175) This should avoid stochastic test failures that have been occuring on GitHub Actions
* Add normalized mutual information metric * Add tests for NMI * Add NMI to metrics init * Fix error message for incorrect target shape * Add 3D NMI test * properly add nmi to metrics init * _true, _test -> 0, 1 * ravel -> reshape(-1) * Apply suggestions from @mkcor's code review Co-authored-by: Marianne Corvellec <marianne.corvellec@ens-lyon.org> * Fix warning and exception messages Co-authored-by: Marianne Corvellec <marianne.corvellec@ens-lyon.org>
based on NEP-29 24 month window for dropping upstream package version
mode 'nearest' is a scipy.ndimage mode, but warp only accepts the numpy.pad equivalent of 'edge'
Right now the data is not sampled every half degree. Also, -pi/2 to pi/2.
…5182) * Correction to linspace call in hough_line default `theta = np.pi / 2 - np.arange(180) / 180.0 * np.pi` done correctly below. * BUG: Fixup to image orientation in example * DOC: Tiny typo * Changed range to conform to documentation The original was [pi/2, -pi/2), not [-pi/2, pi/2). Updated wording in docs. * Fixed x-bounds of hough image in example * Fixed long line * Fixes to tests Number of lines in checkerboard, longer line in peak ordering assertion, updated angle * Accidentally modified the wrong value. * Updated example to include three lines As requested in review
* Replace correlate_sparse Cython version with a simple slicing-based variant in _mean_std This slicing variant has two benefits: 1.) profiled 30-40% faster on 2d and 3d cases I tested with 2.) can immediately be used by other array backends such as CuPy * remove intermediate padded_sq variable to reduce memory footprint * Update skimage/filters/_sparse.py remove duplicate declarations Co-authored-by: Riadh Fezzani <rfezzani@gmail.com> * move _to_np_mode and _to_ndimage_mode to _shared.utils.py * add comment about corner_index needing to be present * raise RuntimeError on missing corner index * update code style based on reviewer comments Co-authored-by: Riadh Fezzani <rfezzani@gmail.com>
…ikit-image#5187) Co-authored-by: Juan Nunez-Iglesias <juan.nunez-iglesias@monash.edu>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @grlee77, I added some suggestions/remarks, but the PR is good as is 😉
@@ -76,7 +76,7 @@ def _tvl1(reference_image, moving_image, flow0, attachment, tightness, | |||
[1] + reference_image.ndim * [3]) | |||
|
|||
image1_warp = warp(moving_image, get_warp_points(grid, flow_current), | |||
mode='nearest') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀 Was this a bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was an unintentional use of the scipy.ndimage name rather than letting the function convert from the numpy.pad equivalent name ('edge'). The docstring to warp
conforms to numpy.pad
style names (i.e. 'edge' rather than its scipy.ndimage
equivalent: 'nearest'). It just so happened that warp didn't raise an error on unrecognized modes and just passed them along unmodified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be something to investigate 😕...
@@ -6,15 +6,6 @@ | |||
from .._shared.utils import get_bound_method_class, safe_as_int | |||
|
|||
|
|||
def _to_ndimage_mode(mode): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see in master branch that _to_ndimage_mode
is not used in this file but we are reimporting it from skimage._shared.utils
😖
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this just a comment or are you recommending something here? (I didn't quite follow where we are "reimporting it from")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was just a comment 🙂
* Change dtype of CircleModel and EllipseModel to float, to avoid integer overflows * remove failing test and add code review notes * Apply suggestions from code review Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com> * Remove unused pytest import Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com> Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com> Co-authored-by: Juan Nunez-Iglesias <juan.nunez-iglesias@monash.edu>
@grlee77, it looks like a rebase is necessary :) |
…mage#5191) Co-authored-by: Marianne Corvellec <marianne.corvellec@ens-lyon.org> Co-authored-by: Riadh <r.fezzani@vitadx.com>
use grid-constant and grid-wrap for SciPy >= 1.6.0 closes scikit-imagegh-5064
based on NEP-29 24 month window for dropping upstream package version
mode 'nearest' is a scipy.ndimage mode, but warp only accepts the numpy.pad equivalent of 'edge'
Co-authored-by: Riadh Fezzani <rfezzani@gmail.com>
reuse implementation from scikit-imagegh-5173
Description
This PR greatly simplifies the implementation of skimage.transform.resize, by using SciPy 1.6.0's new
grid_mode=True
option toscipy.ndimage.zoom
. This allows us to avoid manually generating coordinates and callingmap_coordinates
.numpy.pad -> scipy.ndimage
mode
conversion was also updated for SciPy 1.6.closes gh-5064
Currently this new code path replaces both the
scipy.ndimage.map_coordinates
code path as well as the one relying on scikit-image's own Cython-based interpolation code. We could also potentially leave the existing Cython code path in place (it was ~10-20% faster thanndimage.zoom
in 2D with orders 0 or 1). Let me know which is preferred.It can be seen in the benchmarks below that
map_coordinates
is occasionally faster than zoom (see e.g. the 3D case for order=5), but this comes at cost of substantially higher memory use needed to store the full set of output coordinates.ASV benchmarks for
resize
andrescale
(which just calls resize internally) were added. The following table summarizes some results for this PR vs. v0.18.1 in both run time and memory usage. This PR is sometimes substantially faster (3D for order 0, 1) and occasionally a bit slower.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
.