Repository navigation
Corrected energy calculation in chan vese - #6902
Conversation
The previous implementation used an integral over curvature instead of an integral over length. The present change intends to remedy this. While integrating over absolute curvature would also give a useful indication, the current implementation fits more closely to the minimized value.
|
Thank you so much for investigating this issue @GGoussar. Would you mind adding a comment to the code that indicates which equation from the paper is implemented, and perhaps give some of the mathematical context, as in the description of this PR? Subtle details like this can be hard to uncover in the future when reading the code. |
Would replacing the docstring of EDIT: Should I also maybe add similar comment to def _cv_energy(image, phi, mu, lambda1, lambda2):
"""Returns the total 'energy' of the current level set function.
This corresponds to equation (7) of the paper by Pascal Getreuer,
which is the weighted sum of the following:
(A) the length of the contour produced by the intersection of the
zero values of the level set,
(B) the area of the "foreground" (area of the image where the
level set is positive)
(C) the variance of the image inside the foreground
(D) the variance of the image outside of the foreground
Each value is computed for each pixel, and then summed. The weight
of (B) is set to 0 in this implementation.
"""
H = _cv_heavyside(phi)
avgenergy = _cv_difference_from_average_term(image, H, lambda1, lambda2)
lenenergy = _cv_edge_length_term(phi, mu)
return np.sum(avgenergy) + np.sum(lenenergy) |
|
Perfect on both counts, thanks! |
The functions `_cv_calculate_variation` and `_cv_energy` now contain a more in-depth explanation that enables the reader to undertand where they can find the orginal equations that these functions implement.
|
@lagru Mind taking a look? I think this is good to go. |
lagru
left a comment
There was a problem hiding this comment.
As far as I can follow this looks good. Thank you for the documentation effort. :)
|
Thanks very much @GGoussar! |
# Description This MR ports several recent changes implemented upstream in scikit-image 0.21rc0. Some are just minor refactoring or documentation fixes, but I have commented on the more significant changes below so we can reuse that for the release note. If preferred, I can split the items below into separate small PRs. ## API Changes / Deprecations - The `random_state` argument of `medial_axis` and `unsupervised_wiener` is now deprecated and will be removed in the future. The new argument name, `seed`, should be used instead. - The formerly private function `_invariant_denoise` has been renamed `denoise_invariant` and is now part of the public `cucim.skimage.restoration` API. - The existing function `cucim.skimage.color.get_xyz_coords` has been renamed `cucim.skimage.color.xyz_tristimulus_values`. The former function name is deprecated and will be removed in the future. ## Enhancements - A new `return_mapping` option was added to `join_segmentations`. This provides an additional output with a mapping between the labels in the joined segmentation and the original ones. - Added support for y-axis shear to the [2D AffineTransform](scikit-image/scikit-image#6752) ## Backwards Incompatible Changes - A bug fix to the energy calculation in `chan_vese` may result in different output from previous versions. ## Bug Fixes - Fixed [bug in energy calculation in Chan-Vese](scikit-image/scikit-image#6902) - Fixed a [bug in 2D shear calculations for `AffineTransform`](scikit-image/scikit-image#6717) Authors: - Gregory Lee (https://github.com/grlee77) - https://github.com/jakirkham Approvers: - Gigon Bae (https://github.com/gigony) URL: #573
Description
Closes #6889
The previous implementation used an integral over curvature instead of an integral over length. The present change intends to remedy this. While integrating over absolute curvature would also give a useful indication, the current implementation fits more closely to the function that needs to be minimized.
The new length-term energy is now computed as μ·δ(Φ)·|∇Φ| instead of μ·κ(Φ). Only the reported "energy" is impacted by this change, as the level set calculation appears to have been implemented by closely following the code in the paper by P. Getreuer. As such the behavior of the algorithm should not be severely affected.
Checklist
Docstrings for all functionsGallery example in./doc/examples(new features only)Benchmark in./benchmarks, if your changes aren't covered by an existing benchmarkUnit testsFor reviewers
later.
__init__.py.doc/release/release_dev.rst.example, to backport to v0.19.x after merging, add the following in a PR
comment:
@meeseeksdev backport to v0.19.xrun-benchmarklabel. To rerun, the labelcan be removed and then added again. The benchmark output can be checked in
the "Actions" tab.