Skip to content

Commit 5776eb2

Browse files
committed
Add basic docstring examples to isotropic morphology funcs
Inspired by the examples of the gray morphology functions. (cherry picked from commit 3b2b1a5)
1 parent 4fe2c3f commit 5776eb2

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

skimage/morphology/isotropic.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ def isotropic_erosion(image, radius, out=None, spacing=None):
4848
and thresholding of distance maps, Pattern Recognition Letters,
4949
Volume 13, Issue 3, 1992, Pages 161-166.
5050
:DOI:`10.1016/0167-8655(92)90055-5`
51+
52+
Examples
53+
--------
54+
Erosion shrinks bright regions
55+
56+
>>> import numpy as np
57+
>>> import skimage as ski
58+
>>> image = np.array([[0, 0, 1, 0, 0],
59+
... [0, 1, 1, 1, 0],
60+
... [0, 1, 1, 1, 0],
61+
... [0, 1, 1, 1, 0],
62+
... [0, 0, 0, 0, 0]], dtype=bool)
63+
>>> result = ski.morphology.isotropic_erosion(image, radius=1)
64+
>>> result.view(np.uint8)
65+
array([[0, 0, 0, 0, 0],
66+
[0, 0, 1, 0, 0],
67+
[0, 0, 1, 0, 0],
68+
[0, 0, 0, 0, 0],
69+
[0, 0, 0, 0, 0]], dtype=uint8)
5170
"""
5271

5372
dist = ndi.distance_transform_edt(image, sampling=spacing)
@@ -96,6 +115,25 @@ def isotropic_dilation(image, radius, out=None, spacing=None):
96115
and thresholding of distance maps, Pattern Recognition Letters,
97116
Volume 13, Issue 3, 1992, Pages 161-166.
98117
:DOI:`10.1016/0167-8655(92)90055-5`
118+
119+
Examples
120+
--------
121+
Dilation enlarges bright regions
122+
123+
>>> import numpy as np
124+
>>> import skimage as ski
125+
>>> image = np.array([[0, 0, 0, 0, 0],
126+
... [0, 0, 0, 0, 0],
127+
... [0, 0, 1, 0, 0],
128+
... [0, 0, 1, 1, 0],
129+
... [0, 0, 0, 0, 0]], dtype=bool)
130+
>>> result = ski.morphology.isotropic_dilation(image, radius=1)
131+
>>> result.view(np.uint8)
132+
array([[0, 0, 0, 0, 0],
133+
[0, 0, 1, 0, 0],
134+
[0, 1, 1, 1, 0],
135+
[0, 1, 1, 1, 1],
136+
[0, 0, 1, 1, 0]], dtype=uint8)
99137
"""
100138

101139
dist = ndi.distance_transform_edt(np.logical_not(image), sampling=spacing)
@@ -142,6 +180,25 @@ def isotropic_opening(image, radius, out=None, spacing=None):
142180
and thresholding of distance maps, Pattern Recognition Letters,
143181
Volume 13, Issue 3, 1992, Pages 161-166.
144182
:DOI:`10.1016/0167-8655(92)90055-5`
183+
184+
Examples
185+
--------
186+
Remove undesired connection between two bright regions
187+
188+
>>> import numpy as np
189+
>>> import skimage as ski
190+
>>> image = np.array([[1, 0, 0, 0, 1],
191+
... [1, 1, 0, 1, 1],
192+
... [1, 1, 1, 1, 1],
193+
... [1, 1, 0, 1, 1],
194+
... [1, 0, 0, 0, 1]], dtype=bool)
195+
>>> result = ski.morphology.isotropic_opening(image, radius=1)
196+
>>> result.view(np.uint8)
197+
array([[1, 0, 0, 0, 1],
198+
[1, 1, 0, 1, 1],
199+
[1, 1, 1, 1, 1],
200+
[1, 1, 0, 1, 1],
201+
[1, 0, 0, 0, 1]], dtype=uint8)
145202
"""
146203

147204
eroded = isotropic_erosion(image, radius, out=out, spacing=spacing)
@@ -188,6 +245,25 @@ def isotropic_closing(image, radius, out=None, spacing=None):
188245
and thresholding of distance maps, Pattern Recognition Letters,
189246
Volume 13, Issue 3, 1992, Pages 161-166.
190247
:DOI:`10.1016/0167-8655(92)90055-5`
248+
249+
Examples
250+
--------
251+
Close gap between two bright lines
252+
253+
>>> import numpy as np
254+
>>> import skimage as ski
255+
>>> image = np.array([[0, 0, 0, 0, 0],
256+
... [0, 0, 0, 0, 0],
257+
... [1, 1, 0, 1, 1],
258+
... [0, 0, 0, 0, 0],
259+
... [0, 0, 0, 0, 0]], dtype=bool)
260+
>>> result = ski.morphology.isotropic_closing(image, radius=1)
261+
>>> result.view(np.uint8)
262+
array([[0, 0, 0, 0, 0],
263+
[0, 0, 0, 0, 0],
264+
[1, 1, 0, 1, 1],
265+
[0, 0, 0, 0, 0],
266+
[0, 0, 0, 0, 0]], dtype=uint8)
191267
"""
192268

193269
dilated = isotropic_dilation(image, radius, out=out, spacing=spacing)

0 commit comments

Comments
 (0)