Skip to content

Commit dd9cf28

Browse files
committed
markdown source builds
Auto-generated via {sandpaper} Source : 0852382 Branch : main Author : Jacob Deppen <deppen.8@gmail.com> Time : 2023-08-16 02:52:31 +0000 Message : Merge pull request #293 from deppen8/291-snippet-docstring-formatting Simplify one-line docstrings for snippets
1 parent 494d405 commit dd9cf28

File tree

4 files changed

+24
-74
lines changed

4 files changed

+24
-74
lines changed

02-image-basics.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,13 @@ the distinction between matrices and arrays is not important, we don't really ca
7777
in its memory. The important thing is that the computer stores values describing the pixels in images, as arrays. And
7878
the terms matrix and array can be used interchangeably.
7979

80-
8180
::::::::::::::::::::::::::::::::::::::::::::::::::
8281

8382
First, the necessary imports:
8483

8584
```python
86-
"""
87-
* Python libraries for learning and performing image processing.
88-
*
89-
"""
85+
"""Python libraries for learning and performing image processing."""
86+
9087
import numpy as np
9188
import matplotlib.pyplot as plt
9289
import ipympl
@@ -254,9 +251,9 @@ Using array slicing, we can then address and assign a new value to that position
254251
```python
255252
zero = iio.imread(uri="data/eight.tif")
256253
zero[2,1]= 1.0
257-
"""
258-
The follwing line of code creates a new figure for imshow to use in displaying our output. Without it, plt.imshow() would overwrite our previous image in the cell above
259-
"""
254+
255+
# The following line of code creates a new figure for imshow to use in displaying our output.
256+
# Without it, plt.imshow() would overwrite our previous image in the cell above
260257
fig, ax = plt.subplots()
261258
plt.imshow(zero)
262259
print(zero)
@@ -311,7 +308,6 @@ can be especially helpful in cases where you need to transpose image viewer data
311308
provided in *x,y* format to *y,x* format. Thus, we will use *cx* and *ry* where appropriate
312309
to help bridge these two approaches.
313310

314-
315311
::::::::::::::::::::::::::::::::::::::::::::::::::
316312

317313
::::::::::::::::::::::::::::::::::::::: challenge
@@ -347,8 +343,6 @@ print(five)
347343

348344
![](fig/five.png){alt='Image of 5'}
349345

350-
351-
352346
:::::::::::::::::::::::::
353347

354348
::::::::::::::::::::::::::::::::::::::::::::::::::

03-skimage-images.md

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ and save an image to a different format.
5050
Here are the first few lines:
5151

5252
```python
53-
"""
54-
* Python program to open, display, and save an image.
55-
*
56-
"""
53+
"""Python program to open, display, and save an image."""
5754
# read image
5855
chair = iio.imread(uri="data/chair.jpg")
5956
```
@@ -97,7 +94,6 @@ that was loaded into Python!*
9794
If the image metadata is important to you, be sure to **always keep an unchanged
9895
copy of the original image!**
9996

100-
10197
::::::::::::::::::::::::::::::::::::::::::::::::::
10298

10399
::::::::::::::::::::::::::::::::::::::::: callout
@@ -111,7 +107,6 @@ For example, if we are editing a document in Microsoft Word,
111107
and we save the document as `paper.pdf` instead of `paper.docx`,
112108
the file *is not* saved as a PDF document.
113109

114-
115110
::::::::::::::::::::::::::::::::::::::::::::::::::
116111

117112
::::::::::::::::::::::::::::::::::::::::: callout
@@ -145,7 +140,6 @@ The style we will use in this workshop is to name each argument, like this:
145140
This style will make it easier for you to learn how to use the variety of
146141
functions we will cover in this workshop.
147142

148-
149143
::::::::::::::::::::::::::::::::::::::::::::::::::
150144

151145
::::::::::::::::::::::::::::::::::::::: challenge
@@ -179,7 +173,6 @@ parameters that allow the user to control this interpolation. You
179173
can find more details in the [scikit-image
180174
documentation](https://scikit-image.org/docs/stable/api/skimage.transform.html#skimage.transform.resize).
181175

182-
183176
::::::::::::::::::::::::::::::::::::::::::::::::::
184177

185178
Image files on disk are normally stored as whole numbers for space efficiency,
@@ -210,10 +203,7 @@ or the OS file browser if it is configured to show file sizes.
210203
Here is what your Python script might look like.
211204

212205
```python
213-
"""
214-
* Python script to read an image, resize it, and save it
215-
* under a different name.
216-
"""
206+
"""Python script to read an image, resize it, and save it under a different name."""
217207

218208
# read in image
219209
chair = iio.imread(uri="data/chair.jpg")
@@ -237,8 +227,6 @@ The script resizes the `data/chair.jpg` image by a factor of 10 in both dimensio
237227
saves the result to the `data/resized_chair.jpg` file,
238228
and displays original and resized for comparision.
239229

240-
241-
242230
:::::::::::::::::::::::::
243231

244232
::::::::::::::::::::::::::::::::::::::::::::::::::
@@ -276,14 +264,10 @@ We will start by reading the image and displaying it.
276264

277265
When loading an image with `imageio`, in certain situations the image is stored in a read-only array. If you attempt to manipulate the pixels in a read-only array, you will receive an error message `ValueError: assignment destination is read-only`. In order to make the image array writeable, we can create a copy with `image = np.array(image)` before manipulating the pixel values.
278266

279-
280267
::::::::::::::::::::::::::::::::::::::::::::::::::
281268

282269
```python
283-
"""
284-
* Python script to ignore low intensity pixels in an image.
285-
*
286-
"""
270+
"""Python script to ignore low intensity pixels in an image."""
287271

288272
# read input image
289273
maize_roots = iio.imread(uri="data/maize-root-cluster.jpg")
@@ -341,14 +325,10 @@ To account for this, we will use the US English spelling, `color`,
341325
in example Python code throughout the lesson.
342326
You will encounter a similar approach with "centre" and `center`.
343327

344-
345328
::::::::::::::::::::::::::::::::::::::::::::::::::
346329

347330
```python
348-
"""
349-
* Python script to load a color image as grayscale.
350-
*
351-
"""
331+
"""Python script to load a color image as grayscale."""
352332

353333
# read input image
354334
chair = iio.imread(uri="data/chair.jpg")
@@ -367,10 +347,7 @@ We can also load colour images as grayscale directly by
367347
passing the argument `mode="L"` to `iio.imread()`.
368348

369349
```python
370-
"""
371-
* Python script to load a color image as grayscale.
372-
*
373-
"""
350+
"""Python script to load a color image as grayscale."""
374351

375352
# read input image, based on filename parameter
376353
gray_chair = iio.imread(uri="data/chair.jpg", mode="L")
@@ -390,7 +367,6 @@ pass `plugin="pillow"`. If the backend is not specified explicitly, `iio.imread(
390367

391368
When loading an image with `mode="L"`, the pixel values are stored as 8-bit integer numbers that can take values in the range 0-255. However, pixel values may also be stored with other types and ranges. For example, some scikit-image functions return the pixel values as floating point numbers in the range 0-1. The type and range of the pixel values are important for the colorscale when plotting, and for masking and thresholding images as we will see later in the lesson. If you are unsure about the type of the pixel values, you can inspect it with `print(image.dtype)`. For the example above, you should find that it is `dtype('uint8')` indicating 8-bit integer numbers.
392369

393-
394370
::::::::::::::::::::::::::::::::::::::::::::::::::
395371

396372
::::::::::::::::::::::::::::::::::::::: challenge
@@ -469,7 +445,6 @@ you can specify them via `vmin` and `vmax` to get the desired output.
469445
If you forget about this, it can lead to unexpected results. Try removing
470446
the `vmax` parameter from the sudoku challenge solution and see what happens.
471447

472-
473448
::::::::::::::::::::::::::::::::::::::::::::::::::
474449

475450
## Access via slicing
@@ -514,10 +489,7 @@ indicates that we want all three colour channels in our new image.
514489
A script to create the subimage would start by loading the image:
515490

516491
```python
517-
"""
518-
* Python script demonstrating image modification and creation via
519-
* NumPy array slicing.
520-
"""
492+
"""Python script demonstrating image modification and creation via NumPy array slicing."""
521493

522494
# load and display original image
523495
board = iio.imread(uri="data/board.jpg")
@@ -578,10 +550,7 @@ Here is the completed Python program to select only the plant and roots
578550
in the image.
579551

580552
```python
581-
"""
582-
* Python script to extract a sub-image containing only the plant and
583-
* roots in an existing image.
584-
"""
553+
"""Python script to extract a sub-image containing only the plant and roots in an existing image."""
585554

586555
# load and display original image
587556
maize_roots = iio.imread(uri="data/maize-root-cluster.jpg")

edge-detection.md

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ exercises: 0
1919

2020
:::::::::::::::::::::::::::::::::::::::::
2121

22-
2322
In this episode, we will learn how to use scikit-image functions to apply *edge
2423
detection* to an image.
2524
In edge detection, we find the boundaries or edges of objects in an image,
@@ -148,10 +147,9 @@ the program reads the command-line arguments and
148147
saves them in their respective variables.
149148

150149
```python
151-
"""
152-
* Python script to demonstrate Canny edge detection.
153-
*
154-
* usage: python CannyEdge.py <filename> <sigma> <low_threshold> <high_threshold>
150+
"""Python script to demonstrate Canny edge detection.
151+
152+
usage: python CannyEdge.py <filename> <sigma> <low_threshold> <high_threshold>
155153
"""
156154
import imageio.v3 as iio
157155
import matplotlib.pyplot as plt
@@ -271,11 +269,9 @@ reading the image in grayscale,
271269
and creating a window.
272270

273271
```python
274-
"""
275-
* Python script to demonstrate Canny edge detection
276-
* with sliders to adjust the thresholds.
277-
*
278-
* usage: python CannyTrack.py <filename>
272+
"""Python script to demonstrate Canny edge detection with sliders to adjust the thresholds.
273+
274+
usage: python CannyTrack.py <filename>
279275
"""
280276
import imageio.v3 as iio
281277
import matplotlib.pyplot as plt
@@ -345,7 +341,6 @@ The filter function will be called with the slider parameters
345341
according to their *names* as *keyword* arguments.
346342
So it is very important to name the sliders appropriately.
347343

348-
349344
::::::::::::::::::::::::::::::::::::::::::::::::::
350345

351346
Finally, we add the plugin the viewer and display the resulting user interface:
@@ -385,8 +380,6 @@ The coloured shape edge image above was produced with a low threshold
385380
value of 0.05 and a high threshold value of 0.07.
386381
You may be able to achieve similar results with other threshold values.
387382

388-
389-
390383
:::::::::::::::::::::::::
391384

392385
::::::::::::::::::::::::::::::::::::::::::::::::::
@@ -419,11 +412,9 @@ Here is a program that uses a slider to vary the threshold value used in
419412
a simple, fixed-level thresholding process.
420413

421414
```python
422-
"""
423-
* Python program to use a slider to control fixed-level
424-
* thresholding value.
425-
*
426-
* usage: python interactive_thresholding.py <filename>
415+
"""Python program to use a slider to control fixed-level thresholding value.
416+
417+
usage: python interactive_thresholding.py <filename>
427418
"""
428419

429420
import imageio.v3 as iio
@@ -465,8 +456,6 @@ blurring with a sigma of 1.5 and a threshold value of 0.45:
465456

466457
![](fig/maize-roots-threshold.png){alt='Thresholded maize roots'}
467458

468-
469-
470459
:::::::::::::::::::::::::
471460

472461
::::::::::::::::::::::::::::::::::::::::::::::::::
@@ -489,7 +478,6 @@ These include `skimage.filters.sobel()`,
489478
which you will recognise as part of the Canny method.
490479
Another choice is `skimage.filters.laplace()`.
491480

492-
493481
:::::::::::::::::::::::::::::: keypoints
494482

495483
- The `skimage.viewer.ImageViewer` is extended using a `skimage.viewer.plugins.Plugin`.
@@ -498,4 +486,3 @@ Another choice is `skimage.filters.laplace()`.
498486
with the `skimage.viewer.widgets.slider()` function and adding them to the plugin.
499487

500488
::::::::::::::::::::::::::::::::::::::::
501-

md5sum.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"config.yaml" "101b3ac4b679126bb1f437306eb1b836" "site/built/config.yaml" "2023-04-25"
55
"index.md" "6e80c662708984307918adfad711e15f" "site/built/index.md" "2023-07-26"
66
"episodes/01-introduction.md" "9755639c515fdbf752422e2e59128f63" "site/built/01-introduction.md" "2023-07-26"
7-
"episodes/02-image-basics.md" "e529d3d8138af0fd01cad6bc6c64a6c9" "site/built/02-image-basics.md" "2023-07-26"
8-
"episodes/03-skimage-images.md" "ece756d6c4506d1c0f5204c4f617fdfb" "site/built/03-skimage-images.md" "2023-07-26"
7+
"episodes/02-image-basics.md" "939be71c509752fc9b02a07874ba65c0" "site/built/02-image-basics.md" "2023-08-16"
8+
"episodes/03-skimage-images.md" "2ed4f295d98a05ab0c98550b1dd210f3" "site/built/03-skimage-images.md" "2023-08-16"
99
"episodes/04-drawing.md" "f1c7af067155a6b9c82a932d4cfe65d3" "site/built/04-drawing.md" "2023-07-26"
1010
"episodes/05-creating-histograms.md" "3bf31d32ff27f76d149c26d7c7ab4662" "site/built/05-creating-histograms.md" "2023-07-26"
1111
"episodes/06-blurring.md" "f8389e7a45f224c63d68a219b0c08a09" "site/built/06-blurring.md" "2023-07-26"
@@ -14,7 +14,7 @@
1414
"episodes/09-challenges.md" "e3342f430b45f5480d797b6d54b79bce" "site/built/09-challenges.md" "2023-07-26"
1515
"instructors/instructor-notes.md" "b1c166a544eb4b9b91f3ac8f2dafd549" "site/built/instructor-notes.md" "2023-05-12"
1616
"learners/discuss.md" "ad762c335f99400dc2cd1a8aad36bdbd" "site/built/discuss.md" "2023-07-26"
17-
"learners/edge-detection.md" "eda7d28c42c2ce8817a2c6e8a78b4ca9" "site/built/edge-detection.md" "2023-07-26"
17+
"learners/edge-detection.md" "fdbcee7436e104e6587e1cb40cd37d18" "site/built/edge-detection.md" "2023-08-16"
1818
"learners/prereqs.md" "7ca883d3d01d18c98ce7524ed297e56c" "site/built/prereqs.md" "2023-07-26"
1919
"learners/reference.md" "7ae9deea84007c6ed1339955ac23f4b7" "site/built/reference.md" "2023-04-26"
2020
"learners/setup.md" "fa9395f2f212644764bb0e5b4ebd984b" "site/built/setup.md" "2023-07-26"

0 commit comments

Comments
 (0)