@@ -143,8 +143,11 @@ to create a mask. Here, we want to turn "on" all pixels which have
143
143
values smaller than the threshold, so we use the less operator ` < ` to
144
144
compare the ` blurred_image ` to the threshold ` t ` . The operator returns
145
145
a mask, that we capture in the variable ` binary_mask ` . It has only one
146
- channel, and each of its values is either 0 or 1. The binary mask
147
- created by the thresholding operation can be shown with ` plt.imshow ` .
146
+ channel, and each of its values is either ` False ` or ` True ` . The
147
+ binary mask created by the thresholding operation can be shown with
148
+ ` plt.imshow ` , where the ` False ` entries are shown as black pixels
149
+ (0-valued) and the ` True ` entries are shown as white pixels
150
+ (1-valued).
148
151
149
152
~~~
150
153
# create a mask based on the threshold
@@ -193,8 +196,8 @@ colored shapes from the original.
193
196
194
197
~~~
195
198
# use the binary_mask to select the "interesting" part of the image
196
- selection = np.zeros_like(image )
197
- selection[binary_mask] = image[binary_mask]
199
+ selection = image.copy( )
200
+ selection[~ binary_mask] = 0
198
201
199
202
fig, ax = plt.subplots()
200
203
plt.imshow(selection)
@@ -268,8 +271,8 @@ plt.show()
268
271
> > And here are the commands to apply the mask and view the thresholded image
269
272
> > ~~~
270
273
> > image = skimage.io.imread("data/shapes-02.jpg")
271
- > > selection = np.zeros_like(image )
272
- > > selection[binary_mask] = image[binary_mask]
274
+ > > selection = image.copy( )
275
+ > > selection[~ binary_mask] = 0
273
276
> >
274
277
> > fig, ax = plt.subplots()
275
278
> > plt.imshow(selection)
@@ -384,8 +387,8 @@ Finally, we use the mask to select the foreground:
384
387
385
388
~~~
386
389
# apply the binary mask to select the foreground
387
- selection = np.zeros_like(image )
388
- selection[ binary_mask] = image [ binary_mask ]
390
+ selection = image.copy( )
391
+ selection[ ~ binary_mask] = 0
389
392
390
393
fig, ax = plt.subplots()
391
394
plt.imshow(selection)
@@ -605,10 +608,10 @@ data/trial-293.jpg,0.13607895611702128
605
608
> > # blur before thresholding
606
609
> > blurred_image = skimage.filters.gaussian(image, sigma=sigma)
607
610
> >
608
- > > # perform inverse binary thresholding to mask the white label and circle
609
- > > binary_mask = blurred_image > 0.95
611
+ > > # perform binary thresholding to mask the white label and circle
612
+ > > binary_mask = blurred_image < 0.95
610
613
> > # use the mask to remove the circle and label from the blurred image
611
- > > blurred_image[binary_mask] = 0
614
+ > > blurred_image[~ binary_mask] = 0
612
615
> >
613
616
> > # perform automatic thresholding to produce a binary image
614
617
> > t = skimage.filters.threshold_otsu(blurred_image)
0 commit comments