Skip to content

Commit

Permalink
markdown source builds
Browse files Browse the repository at this point in the history
Auto-generated via {sandpaper}
Source  : 5224322
Branch  : main
Author  : Toby Hodges <[email protected]>
Time    : 2023-12-19 13:25:09 +0000
Message : Merge pull request #318 from bear-rsg/connected-components-changes

Review changes
  • Loading branch information
actions-user committed Dec 19, 2023
1 parent 23ef1d9 commit aad9cee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions 08-connected-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@ labeled_image, count = connected_components(filename="data/shapes-01.jpg", sigma

fig, ax = plt.subplots()
plt.imshow(labeled_image)
plt.axis("off")
plt.axis("off");
```

:::::::::::::::: spoiler

## Do you see an empty image?

If you are using an old version of Matplotlib you might get a warning
If you are using an older version of Matplotlib you might get a warning
`UserWarning: Low image data range; displaying image with stretched contrast.`
or just see a visually empty image.

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

:::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::: callout

## Suppressing outputs in Jupyter Notebooks

We just used `plt.axis("off");` to hide the axis from the image for a visually cleaner figure. The
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)
the axis limits. This is specific to Jupyter Notebooks.

::::::::::::::::::::::::::::::::::::::::::::::::::

We can use the function `ski.color.label2rgb()`
to convert the 32-bit grayscale labeled image to standard RGB colour
(recall that we already used the `ski.color.rgb2gray()` function
Expand All @@ -385,7 +395,7 @@ colored_label_image = ski.color.label2rgb(labeled_image, bg_label=0)

fig, ax = plt.subplots()
plt.imshow(colored_label_image)
plt.axis("off")
plt.axis("off");
```

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

As you might have guessed, the return value `count` already
contains the number of found objects in the image. So it can simply be printed
contains the number of objects found in the image. So it can simply be printed
with

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

fig, ax = plt.subplots()
plt.imshow(colored_label_image)
plt.axis("off")
plt.axis("off");

print("Found", count, "objects in the image.")
```
Expand Down Expand Up @@ -786,7 +796,7 @@ fig, ax = plt.subplots()
im = plt.imshow(colored_area_image)
cbar = fig.colorbar(im, ax=ax, shrink=0.85)
cbar.ax.set_title("Area")
plt.axis("off")
plt.axis("off");
```

![](fig/shapes-01-objects-coloured-by-area.png){alt='Objects colored by area'}
Expand Down
2 changes: 1 addition & 1 deletion md5sum.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"episodes/05-creating-histograms.md" "59c07192c0a6217e8a42d3e7365025f9" "site/built/05-creating-histograms.md" "2023-12-08"
"episodes/06-blurring.md" "8d109bb4c49f27f54857f6d35b4c6b9a" "site/built/06-blurring.md" "2023-12-08"
"episodes/07-thresholding.md" "bc0b3a64255ef9dd359d4cf3188aba83" "site/built/07-thresholding.md" "2023-12-15"
"episodes/08-connected-components.md" "ffea5032d5ede5aa12673c83f9c62e97" "site/built/08-connected-components.md" "2023-12-15"
"episodes/08-connected-components.md" "c4b727de6f6f5ea4f8ef5467759c85bd" "site/built/08-connected-components.md" "2023-12-19"
"episodes/09-challenges.md" "655bdca8cab5d28dc6b2c2e9275aaecc" "site/built/09-challenges.md" "2023-12-15"
"instructors/instructor-notes.md" "b1c166a544eb4b9b91f3ac8f2dafd549" "site/built/instructor-notes.md" "2023-05-12"
"learners/discuss.md" "ad762c335f99400dc2cd1a8aad36bdbd" "site/built/discuss.md" "2023-07-26"
Expand Down

0 comments on commit aad9cee

Please sign in to comment.