@@ -52,11 +52,11 @@ Image filtering
52
52
>>> lena = misc.lena()
53
53
>>> import numpy as np
54
54
>>> noisy_lena = np.copy(lena).astype(np.float)
55
- >>> noisy_lena += lena.std()* 0.5* np.random.standard_normal(lena.shape)
55
+ >>> noisy_lena += lena.std() * 0.5 * np.random.standard_normal(lena.shape)
56
56
>>> blurred_lena = ndimage.gaussian_filter(noisy_lena, sigma=3)
57
57
>>> median_lena = ndimage.median_filter(blurred_lena, size=5)
58
58
>>> from scipy import signal
59
- >>> wiener_lena = signal.wiener(blurred_lena, (5,5))
59
+ >>> wiener_lena = signal.wiener(blurred_lena, (5, 5))
60
60
61
61
.. figure :: image_processing/filtered_lena.png
62
62
:align: center
@@ -89,7 +89,7 @@ in order to modify other geometrical structures.
89
89
Let us first generate a structuring element ::
90
90
91
91
>>> el = ndimage.generate_binary_structure(2, 1)
92
- >>> el# doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
92
+ >>> el # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
93
93
array([[False, True, False],
94
94
[...True, True, True],
95
95
[False, True, False]], dtype=bool)
@@ -100,7 +100,7 @@ Let us first generate a structuring element ::
100
100
101
101
* **Erosion ** ::
102
102
103
- >>> a = np.zeros((7,7), dtype=np.int)
103
+ >>> a = np.zeros((7, 7), dtype=np.int)
104
104
>>> a[1:6, 2:5] = 1
105
105
>>> a
106
106
array([[0, 0, 0, 0, 0, 0, 0],
@@ -147,16 +147,17 @@ Let us first generate a structuring element ::
147
147
148
148
* **Opening ** ::
149
149
150
- >>> a = np.zeros((5,5), dtype=np.int)
151
- >>> a[1:4, 1:4] = 1; a[4, 4] = 1
150
+ >>> a = np.zeros((5, 5), dtype=np.int)
151
+ >>> a[1:4, 1:4] = 1
152
+ >>> a[4, 4] = 1
152
153
>>> a
153
154
array([[0, 0, 0, 0, 0],
154
155
[0, 1, 1, 1, 0],
155
156
[0, 1, 1, 1, 0],
156
157
[0, 1, 1, 1, 0],
157
158
[0, 0, 0, 0, 1]])
158
159
>>> # Opening removes small objects
159
- >>> ndimage.binary_opening(a, structure=np.ones((3,3))).astype(np.int)
160
+ >>> ndimage.binary_opening(a, structure=np.ones((3, 3))).astype(np.int)
160
161
array([[0, 0, 0, 0, 0],
161
162
[0, 1, 1, 1, 0],
162
163
[0, 1, 1, 1, 0],
@@ -183,7 +184,7 @@ image. ::
183
184
184
185
>>> a = np.zeros((50, 50))
185
186
>>> a[10:-10, 10:-10] = 1
186
- >>> a += 0.25* np.random.standard_normal(a.shape)
187
+ >>> a += 0.25 * np.random.standard_normal(a.shape)
187
188
>>> mask = a>=0.5
188
189
>>> opened_mask = ndimage.binary_opening(mask)
189
190
>>> closed_mask = ndimage.binary_closing(opened_mask)
@@ -203,9 +204,9 @@ For *gray-valued* images, eroding (resp. dilating) amounts to replacing
203
204
a pixel by the minimal (resp. maximal) value among pixels covered by the
204
205
structuring element centered on the pixel of interest. ::
205
206
206
- >>> a = np.zeros((7,7), dtype=np.int)
207
+ >>> a = np.zeros((7, 7), dtype=np.int)
207
208
>>> a[1:6, 1:6] = 3
208
- >>> a[4,4] = 2; a[2,3] = 1
209
+ >>> a[4, 4] = 2; a[2, 3] = 1
209
210
>>> a
210
211
array([[0, 0, 0, 0, 0, 0, 0],
211
212
[0, 3, 3, 3, 3, 3, 0],
@@ -214,7 +215,7 @@ structuring element centered on the pixel of interest. ::
214
215
[0, 3, 3, 3, 2, 3, 0],
215
216
[0, 3, 3, 3, 3, 3, 0],
216
217
[0, 0, 0, 0, 0, 0, 0]])
217
- >>> ndimage.grey_erosion(a, size=(3,3))
218
+ >>> ndimage.grey_erosion(a, size=(3, 3))
218
219
array([[0, 0, 0, 0, 0, 0, 0],
219
220
[0, 0, 0, 0, 0, 0, 0],
220
221
[0, 0, 1, 1, 1, 0, 0],
@@ -230,7 +231,7 @@ Measurements on images
230
231
Let us first generate a nice synthetic binary image. ::
231
232
232
233
>>> x, y = np.indices((100, 100))
233
- >>> sig = np.sin(2*np.pi*x/50.)* np.sin(2*np.pi*y/50.)* (1+x*y/50.**2)**2
234
+ >>> sig = np.sin(2*np.pi*x/50.) * np.sin(2*np.pi*y/50.) * (1+x*y/50.**2)**2
234
235
>>> mask = sig > 1
235
236
236
237
Now we look for various information about the objects in the image::
0 commit comments