@@ -316,14 +316,14 @@ labeled_image, count = connected_components(filename="data/shapes-01.jpg", sigma
316
316
317
317
fig, ax = plt.subplots()
318
318
plt.imshow(labeled_image)
319
- plt.axis(" off" )
319
+ plt.axis(" off" );
320
320
```
321
321
322
322
:::::::::::::::: spoiler
323
323
324
324
## Do you see an empty image?
325
325
326
- If you are using an old version of Matplotlib you might get a warning
326
+ If you are using an older version of Matplotlib you might get a warning
327
327
` UserWarning: Low image data range; displaying image with stretched contrast. `
328
328
or just see a visually empty image.
329
329
@@ -371,6 +371,16 @@ Alternatively we could convert the image to RGB and then display it.
371
371
372
372
:::::::::::::::::::::::::
373
373
374
+ ::::::::::::::::::::::::::::::::::::::::: callout
375
+
376
+ ## Suppressing outputs in Jupyter Notebooks
377
+
378
+ We just used ` plt.axis("off"); ` to hide the axis from the image for a visually cleaner figure. The
379
+ semicolon is added to supress the output(s) of the statement, in this [ case] ( https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.axis.html )
380
+ the axis limits. This is specific to Jupyter Notebooks.
381
+
382
+ ::::::::::::::::::::::::::::::::::::::::::::::::::
383
+
374
384
We can use the function ` ski.color.label2rgb() `
375
385
to convert the 32-bit grayscale labeled image to standard RGB colour
376
386
(recall that we already used the ` ski.color.rgb2gray() ` function
@@ -385,7 +395,7 @@ colored_label_image = ski.color.label2rgb(labeled_image, bg_label=0)
385
395
386
396
fig, ax = plt.subplots()
387
397
plt.imshow(colored_label_image)
388
- plt.axis(" off" )
398
+ plt.axis(" off" );
389
399
```
390
400
391
401
![ ] ( fig/shapes-01-labeled.png ) {alt='Labeled objects'}
@@ -407,7 +417,7 @@ How does changing the `sigma` and `threshold` values influence the result?
407
417
## Solution
408
418
409
419
As you might have guessed, the return value ` count ` already
410
- contains the number of found objects in the image. So it can simply be printed
420
+ contains the number of objects found in the image. So it can simply be printed
411
421
with
412
422
413
423
``` python
@@ -733,7 +743,7 @@ colored_label_image = ski.color.label2rgb(labeled_image, bg_label=0)
733
743
734
744
fig, ax = plt.subplots()
735
745
plt.imshow(colored_label_image)
736
- plt.axis(" off" )
746
+ plt.axis(" off" );
737
747
738
748
print (" Found" , count, " objects in the image." )
739
749
```
@@ -786,7 +796,7 @@ fig, ax = plt.subplots()
786
796
im = plt.imshow(colored_area_image)
787
797
cbar = fig.colorbar(im, ax = ax, shrink = 0.85 )
788
798
cbar.ax.set_title(" Area" )
789
- plt.axis(" off" )
799
+ plt.axis(" off" );
790
800
```
791
801
792
802
![ ] ( fig/shapes-01-objects-coloured-by-area.png ) {alt='Objects colored by area'}
0 commit comments