Skip to content

Commit 5224322

Browse files
authored
Merge pull request #318 from bear-rsg/connected-components-changes
Review changes
2 parents 0c8bfff + 06ae05d commit 5224322

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

episodes/08-connected-components.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -316,14 +316,14 @@ labeled_image, count = connected_components(filename="data/shapes-01.jpg", sigma
316316

317317
fig, ax = plt.subplots()
318318
plt.imshow(labeled_image)
319-
plt.axis("off")
319+
plt.axis("off");
320320
```
321321

322322
:::::::::::::::: spoiler
323323

324324
## Do you see an empty image?
325325

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
327327
`UserWarning: Low image data range; displaying image with stretched contrast.`
328328
or just see a visually empty image.
329329

@@ -371,6 +371,16 @@ Alternatively we could convert the image to RGB and then display it.
371371

372372
:::::::::::::::::::::::::
373373

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+
374384
We can use the function `ski.color.label2rgb()`
375385
to convert the 32-bit grayscale labeled image to standard RGB colour
376386
(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)
385395

386396
fig, ax = plt.subplots()
387397
plt.imshow(colored_label_image)
388-
plt.axis("off")
398+
plt.axis("off");
389399
```
390400

391401
![](fig/shapes-01-labeled.png){alt='Labeled objects'}
@@ -407,7 +417,7 @@ How does changing the `sigma` and `threshold` values influence the result?
407417
## Solution
408418

409419
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
411421
with
412422

413423
```python
@@ -733,7 +743,7 @@ colored_label_image = ski.color.label2rgb(labeled_image, bg_label=0)
733743

734744
fig, ax = plt.subplots()
735745
plt.imshow(colored_label_image)
736-
plt.axis("off")
746+
plt.axis("off");
737747

738748
print("Found", count, "objects in the image.")
739749
```
@@ -786,7 +796,7 @@ fig, ax = plt.subplots()
786796
im = plt.imshow(colored_area_image)
787797
cbar = fig.colorbar(im, ax=ax, shrink=0.85)
788798
cbar.ax.set_title("Area")
789-
plt.axis("off")
799+
plt.axis("off");
790800
```
791801

792802
![](fig/shapes-01-objects-coloured-by-area.png){alt='Objects colored by area'}

0 commit comments

Comments
 (0)