Implementation of medial surface thinning
- Implemented medial surface thinning algorithm
- Implemented medial surface thinning tests in test_medial_surface.py
- Implemented example of medial axis and medial surface thinning in plot_medial_axis_surface.py
Description
Hi all,
here is an implementation of the medial surface thinning method from [1]. The medial axis thinning method from this paper is already implemented in scikit-image, so the medial surface thinning implementation extends the already existing functionality. I have implemented tests and an example for the documentation.
Cheers, Simon
[1] T.-C. Lee, R.L. Kashyap and C.-N. Chu, Building skeleton models via 3-D medial surface/axis thinning algorithms. Computer Vision, Graphics, and Image Processing, 56(6):462-478, 1994.
Checklist
- Docstrings for all functions
- Gallery example in
./doc/examples(new features only) - Benchmark in
./benchmarks, if your changes aren't covered by an existing benchmark - Unit tests
- Clean style in the spirit of PEP8
- Descriptive commit messages (see below)
For reviewers
- Check that the PR title is short, concise, and will make sense 1 year later.
- Check that new functions are imported in corresponding
__init__.py. - Check that new features, API changes, and deprecations are mentioned in
doc/release/release_dev.rst. - There is a bot to help automate backporting a PR to an older branch. For
example, to backport to v0.19.x after merging, add the following in a PR
comment:
@meeseeksdev backport to v0.19.x - To run benchmarks on a PR, add the
run-benchmarklabel. To rerun, the label can be removed and then added again. The benchmark output can be checked in the "Actions" tab.
Hello @SimonPfeifer! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
- In the file
skimage/morphology/__init__.py:
- In the file
skimage/morphology/_skeletonize.py:
Line 680:80: E501 line too long (80 > 79 characters)
Comment last updated at 2022-06-16 14:16:00 UTC
In terms of tests, have you compared on any relatively small real-world example data that the result here matches that for the ImageJ implementation?
I am not very familiar with ImageJ but a I couldn't find a medial surface thinning implementation. Maybe someone more familiar with it could confirm this?
For tests, I have tried to copy the example data in Fig. 12 in the original Lee94 paper (counting the voxels by hand). That's what is shown in plot_medial_axis_surface.py. However, the exact dimensions are difficult to make out as some of the shape is obscured. The method also does not return the exact same result as shown in Lee94 even when the order in which the border points are checked is changed to be consistent with Lee94 (U, B, N, S, W, E) rather than the ImageJ implementation (W, E, S, N, U, B). The medial surfaces are found but face in different directions.
I am not very familiar with ImageJ but a I couldn't find a medial surface thinning implementation. Maybe someone more familiar with it could confirm this?
The Skeletonize3D plugin mentions the same paper, but I'm not sure it has an option to do the medial surface variant (the plugin was based on this ITK module, but that may also only have the medial axis). I also found this SGEXT package, but that one also looks like it is likely only the 3D medial axis as well (and the algorithm is different).
@SimonPfeifer thank you for this! Would you like some help on @grlee77's requests? We could take it from here, also; I could help testing it on ImageJ and confirming the results, if that's the case. Thanks again!
@SimonPfeifer thank you for this! Would you like some help on @grlee77's requests? We could take it from here, also; I could help testing it on ImageJ and confirming the results, if that's the case. Thanks again!
Any help would be appreciated, especially comparing to ImageJ.
Thank you @SimonPfeifer for your contribution!
FWIW, there is a related issue on medial thinning beyond 2D - https://github.com/scikit-image/scikit-image/issues/4105. I would agree with @grlee77 regarding the tests - while synthetic examples are useful for checking some of the corner cases, we should likely aim at testing with a 3D input of irregular thickness - something like this in 3D, perhaps also with discontinuities:

Figures 11 and 21 from the last URL in the issue above provide a nice overview on how skeletons may vary based on the chosen thinning algorithm. Not sure if it reasonable to use any other skeleton testing method except for a direct comparison. For storing, the object image and the reference skeleton(s) could be then compressed with RLE encoding.