From 19410f649b5aad7f3bf9f7c4da8874734b3a149a Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Mon, 11 Dec 2023 11:17:54 +0000 Subject: [PATCH] differences for PR #310 --- 03-skimage-images.md | 25 ++++++++++++++++--------- md5sum.txt | 2 +- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/03-skimage-images.md b/03-skimage-images.md index b9268b50..4d5e7809 100644 --- a/03-skimage-images.md +++ b/03-skimage-images.md @@ -379,7 +379,8 @@ The file `data/sudoku.png` is an RGB image of a sudoku puzzle: ![](data/sudoku.png){alt='Su-Do-Ku puzzle'} -Your task is to turn all of the bright pixels in the image to a +Your task is to load the image in grayscale format and turn all of +the bright pixels in the image to a light gray colour. In other words, mask the bright pixels that have a pixel value greater than, say, 192 and set their value to 192 (the value 192 is chosen here because it corresponds to 75% of the @@ -387,31 +388,37 @@ range 0-255 of an 8-bit pixel). The results should look like this: ![](fig/sudoku-gray.png){alt='Modified Su-Do-Ku puzzle'} -*Hint: this is an instance where it is helpful to load the image in grayscale format.* +*Hint: the `cmap`, `vmin`, and `vmax` parameters of `matplotlib.pyplot.imshow` +will be needed to display the modified image as desired. See the [Matplotlib +documentation](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html) +for more details on `cmap`, `vmin`, and `vmax`.* ::::::::::::::: solution ## Solution -First, load the image file `data/sudoku.png` as a grayscale image. Remember that we use `image = np.array(image)` to create a copy of the image array because `imageio.imread` returns a non-writeable image. +First, load the image file `data/sudoku.png` as a grayscale image. +Note we may want to create a copy of the image array to avoid modifying our original variable and +also because `imageio.v3.imread` sometimes returns a non-writeable image. ```python - -sudoku = iio.imread(uri="data/sudoku.png") +sudoku = iio.imread(uri="data/sudoku.png", mode="L") +sudoku_gray_background = np.array(sudoku) ``` Then change all bright pixel values greater than 192 to 192: ```python -sudoku = sudoku.copy() -sudoku[sudoku > 125] = 125 +sudoku_gray_background[sudoku_gray_background > 192] = 192 ``` -Finally, display the modified image. Note that we have to specify `vmin=0` and `vmax=255` as the range of the colorscale because it would otherwise automatically adjust to the new range 0-192. +Finally, display the original and modified images side by side. Note that we have to specify `vmin=0` and `vmax=255` as the range of the colorscale because it would otherwise automatically adjust to the new range 0-192. ```python fig, ax = plt.subplots() -plt.imshow(sudoku, cmap="gray", vmin=0, vmax=1) +fig, ax = plt.subplots(ncols=2) +ax[0].imshow(sudoku, cmap="gray", vmin=0, vmax=255) +ax[1].imshow(sudoku_gray_background, cmap="gray", vmin=0, vmax=255) ``` ::::::::::::::::::::::::: diff --git a/md5sum.txt b/md5sum.txt index 44a1cd7c..00b93ed0 100644 --- a/md5sum.txt +++ b/md5sum.txt @@ -5,7 +5,7 @@ "index.md" "6e80c662708984307918adfad711e15f" "site/built/index.md" "2023-07-26" "episodes/01-introduction.md" "9755639c515fdbf752422e2e59128f63" "site/built/01-introduction.md" "2023-07-26" "episodes/02-image-basics.md" "b17ae758d5d8a2a81348306a97b37067" "site/built/02-image-basics.md" "2023-12-11" -"episodes/03-skimage-images.md" "063fa4bb5032702c0196b0d953d94474" "site/built/03-skimage-images.md" "2023-12-08" +"episodes/03-skimage-images.md" "e65a5d9bea4f5ee0597ac13cb0be875d" "site/built/03-skimage-images.md" "2023-12-11" "episodes/04-drawing.md" "9d78a765f5e9747ffc2aa43a4a5a414d" "site/built/04-drawing.md" "2023-09-05" "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"