Add example code for generating structuring elements.#4528
Add example code for generating structuring elements.#4528jni merged 8 commits intoscikit-image:masterfrom
Conversation
sciunto
left a comment
There was a problem hiding this comment.
Great PR, I love the numbers superimposed on top of the color plot!
I'm wondering if two separate figures would be better, t get ride of the idx and also for the thumbnail. Others can provide their opinion.
| ============================= | ||
|
|
||
| This example shows how to use functions in :py:module:`skimage.morphology` | ||
| to generate structuring elements. |
There was a problem hiding this comment.
I think this paragraph could be improved by explaining what is a structuring element and providing few examples of functions using them (like erosion, dilation, functions in rank filters)...
There was a problem hiding this comment.
Hello sciunto. Thank you for pointing it out : )
I felt a bit hard to explain what structuring element is (my English is bad..).
I made this as an example, which modified from the current example of dilation function:
>>> import numpy as np
>>> from skimage.morphology import dilation, square, disk
>>> bright_pixel = np.array([[0, 0, 0, 0, 0],
... [0, 0, 0, 0, 0],
... [0, 0, 1, 0, 0],
... [0, 0, 0, 0, 0],
... [0, 0, 0, 0, 0]], dtype=np.uint8)
>>> dilation(bright_pixel, square(3))
array([[0, 0, 0, 0, 0],
[0, 1, 1, 1, 0],
[0, 1, 1, 1, 0],
[0, 1, 1, 1, 0],
[0, 0, 0, 0, 0]], dtype=uint8)
>>> dilation(bright_pixel, disk(2))
array([[0, 0, 1, 0, 0],
[0, 1, 1, 1, 0],
[1, 1, 1, 1, 1],
[0, 1, 1, 1, 0],
[0, 0, 1, 0, 0]], dtype=uint8)Not sure if it should be put into the code.
| ax = fig.add_subplot(3, 3, idx) | ||
| ax.imshow(struc, cmap="Paired", vmin=0, vmax=12) | ||
| for i in range(struc.shape[0]): | ||
| for j in range(struc.shape[1]): |
There was a problem hiding this comment.
Here we could use itertools.product to avoid nested loops, but it's optional.
|
Thanks for the PR! This looks great! I think for 2D we should try keeping the same absolute scale of the pixels across the plots. For 3D, one of these visualization methods may suit better - https://matplotlib.org/3.2.0/gallery/mplot3d/voxels.html, https://matplotlib.org/3.2.0/gallery/mplot3d/3d_bars.html . |
|
Thanks for the comments. I will improve these in my free time. |
Co-Authored-By: Riadh Fezzani <rfezzani@gmail.com>
Co-Authored-By: Riadh Fezzani <rfezzani@gmail.com>
Co-Authored-By: Riadh Fezzani <rfezzani@gmail.com>
Co-Authored-By: rfezzani <rfezzani@gmail.com>
Hello @soupault , thanks for your advice! |
Co-Authored-By: Riadh Fezzani <rfezzani@gmail.com>
|
@b-z I love your latest plots! Could you push the code for those to your branch? It is still showing the dots and the different element sizes. I also like @rfezzani's suggestions for iterating over the values. However, since you are not going to access the dictionary, it might be better to revert back to a list of tuples! Sorry about the back and forth there...! Anyway, all that is optional, but the shaded voxels look super nice and we should get that code in since you worked it out! |
I did not get the point. Sorry @jni, can you elaborate more on this? 🙂 |
|
Me too. @rfezzani suggestion looks appropriate to me. |
|
Currently we are doing: structs2d = {'square(5)': square(5), ...}
...
for title, struc in structs2d.items():
...I suggest: structs2d = [('square(5)', square(5)), ...]
...
for title, struc in structs2d:
... |
|
I understood that @jni, I just still don't get your objection:
If it is simply a matter of code style, no problem... Everybody has its own preferences ;-) |
Modify visulization parameters; change 3D plot method; apply @rfezzani 's suggestions. Co-Authored-By: rfezzani <rfezzani@gmail.com>
…/b-z/scikit-image into add_example_structuring_elements
The newest code is using the style rfezzani suggested. |
|
@rfezzani what I meant is that we are not using the mapping feature of the dictionary. We stuff things into a dictionary then immediately unpack it into tuples. So we might as well just use the tuples. @b-z Don’t worry, this is indeed just a suggestion. It’s common for maintainers to have disagreements, and it’s something you get used to over time — you eventually develop a sense for what are requirements and what are minor suggestions. Either way is minor with this dict/tuple question. Thank you so much for your work! |
|
@b-z thanks a lot for the updates! This looks amazing - #4528 (comment)! So happy to have this work merged! |

Description
Closes #4431 .
The example shows how to use functions in
skimage.morphologyto generate structuring elements.The title of each plot indicates the call of the function.
Checklist
Docstrings for all functionsGallery example in./doc/examples(new features only)Benchmark in./benchmarks, if your changes aren't covered by anexisting benchmark
Unit testsFor reviewers
later.
__init__.py.doc/release/release_dev.rst.@meeseeksdev backport to v0.14.x