Skip to content

Commit f79aa12

Browse files
JeremyPikeuschilletobyhodges
authored
Apply suggestions from code review
Suggestions from review Co-authored-by: Ulf Schiller <uschille@users.noreply.github.com> Co-authored-by: Toby Hodges <tbyhdgs@gmail.com>
1 parent 1717003 commit f79aa12

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

episodes/07-thresholding.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,18 +347,16 @@ plt.xlim(0, 1.0)
347347

348348
![](fig/maize-root-cluster-histogram.png){alt='Grayscale histogram of the maize root image'}
349349

350-
The histogram has a significant peak around 0.2, and a second,
351-
shallower peak near 0.6.
350+
The histogram has a significant peak around 0.2 and then a broader "hill" around 0.6 followed by a smaller peak near 1.0. Looking at the grayscale image, we can identify the lower peak at 0.2 as the background and the larger pixel values as the foreground, but it is not so obvious what the threshold should be.
352351
Thus, this image is a good candidate for thresholding with Otsu's method.
353352
The mathematical details of how this works are complicated (see
354353
[the scikit-image documentation](https://scikit-image.org/docs/dev/api/skimage.filters.html#threshold-otsu)
355354
if you are interested),
356355
but the outcome is that Otsu's method finds a threshold value between
357356
the two peaks of a grayscale histogram.
358-
Note there is a third peak very close to 1.0 which corresponds to the white label and disk on the
359-
left hand side of the image. It would be a good idea to remove these white pixels
360-
before calculating the Otsu threshold. We will discuss how to do this later in the episode but for
361-
now we will continue without removing them.
357+
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: instructor
358+
The histogram of the maize root image may prompt questions from learners about the interpretation of the peaks and the broader region around 0.6. The focus here is on the separation of background and foreground pixel values. We note that Otsu's method does not work well for the image with the shapes used earlier in this episode, as the foreground pixel values are more distributed. These examples could be augmented by a discussion of unimodal, bimodal, and multimodal histograms. While these points can lead to fruitful discussions, the text in this episode attempts to reduce cognitive load and deliberately simplifies the discussion.
359+
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
362360

363361
The `ski.filters.threshold_otsu()` function can be used to determine
364362
the threshold automatically via Otsu's method.
@@ -662,7 +660,21 @@ data/trial-020.jpg,0.05886968085106383
662660
data/trial-216.jpg,0.13712117686170214
663661
data/trial-293.jpg,0.13190342420212767
664662
```
663+
:::::::::::::::::::::::::::::::::::::::::: spoiler
665664

665+
### What is `&` doing in the example above?
666+
667+
The `&` operator above means that we have defined a logical AND statement. This combines the two tests of pixel intensities in the blurred image such that both must be true for a pixel's position to be set to `True` in the resulting mask.
668+
669+
| Result of `t < blurred_image` | Result of `blurred_image < 0.95 | Resulting value in `binary_mask` |
670+
|----------|---------|---------|
671+
| False | True | False |
672+
| True | False | False |
673+
| True | True | True |
674+
675+
Knowing how to construct this kind of logical operation can be very helpful in image processing. The University of Minnesota Library's [guide to Boolean operators](https://libguides.umn.edu/BooleanOperators) is a good place to start if you want to learn more.
676+
677+
::::::::::::::::::::::::::::::::::::::::::::::::::
666678
Here are the binary images produced by the additional thresholding.
667679
Note that we have not completely removed the offending white pixels.
668680
Outlines still remain.

0 commit comments

Comments
 (0)