Skip to content

Commit 0c4e64d

Browse files
committed
WIP
1 parent 83728db commit 0c4e64d

File tree

10 files changed

+64
-106
lines changed

10 files changed

+64
-106
lines changed

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
\#*
22
.#*
33
_requirements.installed
4-
build
54
*.DS_Store
65
*.html
76
*.ipynb_checkpoints
87
*.pyc
98
*~
10-
*pano-advanced-output.png
11-
book/lessons
129

13-
# ignoring website local builds
10+
# Ignore built website
1411
site/_build
12+
13+
# Ignore auto-generated content
14+
site/lectures
15+

Makefile

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,13 @@
1-
.PHONY: html
1+
.PHONY: clean html
22

3-
OBSHELL=/bin/bash
4-
5-
.DEFAULT_GOAL = html
6-
7-
LESSONS_DIR = lessons
8-
GENERATED_LESSONS_DIR = site/lessons
3+
.DEFAULT_GOAL = book
94

105
_requirements.installed:
116
pip install -q -r requirements.txt
127
touch _requirements.installed
138

14-
MARKDOWNS = $(wildcard $(LESSONS_DIR)/*.md)
15-
MD_OUTPUTS = $(patsubst $(LESSONS_DIR)/%.md, $(GENERATED_LESSONS_DIR)/%.md, $(MARKDOWNS))
16-
NOTEBOOKS = $(patsubst %.md, %.ipynb, $(MD_OUTPUTS))
17-
18-
.SECONDARY: $(MD_OUTPUTS) $(NOTEBOOKS)
19-
20-
$(GENERATED_LESSONS_DIR)/%.ipynb:$(LESSONS_DIR)/%.md site/lessons site/lessons/images
21-
# This does not work, due to bug in notedown; see https://github.com/aaren/notedown/issues/53
22-
#notedown --match=python --precode='%matplotlib inline' $< > $@
23-
notedown --match=python $< > $@
24-
jupyter nbconvert --execute --inplace $@ --ExecutePreprocessor.timeout=-1
25-
26-
%.md:%.ipynb
27-
jupyter nbconvert --to=mdoutput --output="$(notdir $@)" --output-dir=$(GENERATED_LESSONS_DIR) $<
28-
# $(eval NBSTRING := [📂 Download lesson notebook](.\/$(basename $(notdir $@)).ipynb)\n\n)
29-
# sed -i'.bak' '1s/^/$(NBSTRING)/' $@
30-
31-
site/lessons:
32-
mkdir -p book/lessons
33-
34-
site/lessons/images:
35-
ln -s ${PWD}/lessons/images ${PWD}/site/lessons/images
36-
37-
html: site/lessons _requirements.installed $(NOTEBOOKS) $(MD_OUTPUTS)
38-
@export SPHINXOPTS=-W; make -C site html
39-
cp $(GENERATED_LESSONS_DIR)/*.ipynb book/build/html/lessons/
9+
book: _requirements.installed
10+
@export SPHINXOPTS=-W; make -C book html
4011

4112
clean:
42-
rm -rf $(GENERATED_LESSONS_DIR)/*
13+
rm -rf book/_build

_config.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

content/00_images_are_arrays.md

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ jupytext:
44
extension: .md
55
format_name: myst
66
format_version: 0.13
7-
jupytext_version: 1.10.3
7+
jupytext_version: 1.11.2
88
kernelspec:
99
display_name: Python 3
1010
language: python
1111
name: python3
1212
---
1313

14-
```{code-cell} python
15-
:tags: [remove-input, remove-output]
14+
```{code-cell}
15+
---
16+
tags: [remove-input, remove-output]
17+
---
1618
1719
%matplotlib inline
1820
%config InlineBackend.figure_format = 'retina'
@@ -26,7 +28,7 @@ Images are represented in ``scikit-image`` using standard ``numpy`` arrays. Thi
2628

2729
Let's see how to build a grayscale image as a 2D array:
2830

29-
```{code-cell} python
31+
```{code-cell}
3032
import numpy as np
3133
from matplotlib import pyplot as plt
3234
@@ -38,7 +40,7 @@ plt.colorbar();
3840

3941
The same holds for "real-world" images:
4042

41-
```{code-cell} python
43+
```{code-cell}
4244
from skimage import data
4345
4446
coins = data.coins()
@@ -52,7 +54,7 @@ plt.imshow(coins, cmap='gray');
5254

5355
A color image is a 3D array, where the last dimension has size 3 and represents the red, green, and blue channels:
5456

55-
```{code-cell} python
57+
```{code-cell}
5658
cat = data.chelsea()
5759
print("Shape:", cat.shape)
5860
print("Values min/max:", cat.min(), cat.max())
@@ -62,7 +64,7 @@ plt.imshow(cat);
6264

6365
These are *just NumPy arrays*. E.g., we can make a red square by using standard array slicing and manipulation:
6466

65-
```{code-cell} python
67+
```{code-cell}
6668
cat[10:110, 10:110, :] = [255, 0, 0] # [red, green, blue]
6769
plt.imshow(cat);
6870
```
@@ -84,14 +86,14 @@ Images can also include transparent regions by adding a 4th dimension, called an
8486

8587
## Displaying images using matplotlib
8688

87-
```{code-cell} python
89+
```{code-cell}
8890
from skimage import data
8991
9092
img0 = data.chelsea()
9193
img1 = data.rocket()
9294
```
9395

94-
```{code-cell} python
96+
```{code-cell}
9597
import matplotlib.pyplot as plt
9698
9799
f, (ax0, ax1) = plt.subplots(1, 2, figsize=(20, 10))
@@ -128,7 +130,7 @@ data-type of the array.
128130

129131
E.g., here, I generate two valid images:
130132

131-
```{code-cell} python
133+
```{code-cell}
132134
linear0 = np.linspace(0, 1, 2500).reshape((50, 50))
133135
linear1 = np.linspace(0, 255, 2500).reshape((50, 50)).astype(np.uint8)
134136
@@ -148,7 +150,7 @@ as long as the range is correct (0-1 for floating point images, 0-255 for unsign
148150

149151
You can convert images between different representations by using ``img_as_float``, ``img_as_ubyte``, etc.:
150152

151-
```{code-cell} python
153+
```{code-cell}
152154
from skimage import img_as_float, img_as_ubyte
153155
154156
image = data.chelsea()
@@ -164,7 +166,7 @@ print("231/255 =", 231/255.)
164166

165167
Your code would then typically look like this:
166168

167-
```python
169+
```{code-cell}
168170
def my_function(any_image):
169171
float_image = img_as_float(any_image)
170172
# Proceed, knowing image is in [0, 1]
@@ -181,7 +183,7 @@ Mostly, we won't be using input images from the scikit-image example data sets.
181183

182184
scikit-image conveniently wraps many of these in the `io` submodule, and will use whichever of the libraries mentioned above are installed:
183185

184-
```{code-cell} python
186+
```{code-cell}
185187
from skimage import io
186188
187189
image = io.imread('../images/balloon.jpg')
@@ -196,15 +198,15 @@ plt.imshow(image);
196198

197199
We also have the ability to load multiple images, or multi-layer TIFF images:
198200

199-
```{code-cell} python
201+
```{code-cell}
200202
ic = io.ImageCollection('../images/*.png:../images/*.jpg')
201203
202204
print('Type:', type(ic))
203205
204206
ic.files
205207
```
206208

207-
```{code-cell} python
209+
```{code-cell}
208210
import os
209211
210212
f, axes = plt.subplots(nrows=3, ncols=len(ic) // 3 + 1, figsize=(20, 5))
@@ -227,11 +229,11 @@ plt.tight_layout()
227229

228230
`enumerate` gives us each element in a container, along with its position.
229231

230-
```{code-cell} python
232+
```{code-cell}
231233
animals = ['cat', 'dog', 'leopard']
232234
```
233235

234-
```{code-cell} python
236+
```{code-cell}
235237
for i, animal in enumerate(animals):
236238
print('The animal in position {} is {}'.format(i, animal))
237239
```
@@ -244,8 +246,10 @@ The arms and strut of the H should have a width of 3 pixels, and the H itself sh
244246

245247
Start with the following template:
246248

247-
```{code-cell} python
248-
:tags: [hide-output]
249+
```{code-cell}
250+
---
251+
tags: [hide-output]
252+
---
249253
250254
def draw_H(image, coords, color=(0, 255, 0)):
251255
out = image.copy()
@@ -257,8 +261,10 @@ def draw_H(image, coords, color=(0, 255, 0)):
257261

258262
Test your function like so:
259263

260-
```{code-cell} python
261-
:tags: [remove-output]
264+
```{code-cell}
265+
---
266+
tags: [remove-output]
267+
---
262268
263269
cat = data.chelsea()
264270
cat_H = draw_H(cat, (50, -50))
@@ -269,8 +275,10 @@ plt.imshow(cat_H);
269275

270276
Display the different color channels of the image along (each as a gray-scale image). Start with the following template:
271277

272-
```{code-cell} python
273-
:tags: [raises-exception, remove-output]
278+
```{code-cell}
279+
---
280+
tags: [raises-exception, remove-output]
281+
---
274282
275283
# --- read in the image ---
276284
@@ -308,20 +316,20 @@ ax_color.set_title('all channels');
308316

309317
Now, take a look at the following R, G, and B channels. How would their combination look? (Write some code to confirm your intuition.)
310318

311-
```{code-cell} python
319+
```{code-cell}
312320
from skimage import draw
313321
314322
red = np.zeros((300, 300))
315323
green = np.zeros((300, 300))
316324
blue = np.zeros((300, 300))
317325
318-
r, c = draw.circle(100, 100, 100)
326+
r, c = draw.circle_perimeter(100, 100, 100, shape=red.shape)
319327
red[r, c] = 1
320328
321-
r, c = draw.circle(100, 200, 100)
329+
r, c = draw.circle_perimeter(100, 200, 100, shape=green.shape)
322330
green[r, c] = 1
323331
324-
r, c = draw.circle(200, 150, 100)
332+
r, c = draw.circle_perimeter(200, 150, 100, shape=blue.shape)
325333
blue[r, c] = 1
326334
327335
f, axes = plt.subplots(1, 3)
@@ -344,8 +352,10 @@ Compare your results to that obtained with `skimage.color.rgb2gray`.
344352

345353
Change the coefficients to 1/3 (i.e., take the mean of the red, green, and blue channels, to see how that approach compares with `rgb2gray`).
346354

347-
```{code-cell} python
348-
:tags: [raises-exception, remove-output]
355+
```{code-cell}
356+
---
357+
tags: [raises-exception, remove-output]
358+
---
349359
350360
from skimage import color, img_as_float
351361

requirements.txt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
scikit-image[data] >= 0.18
2-
numpy >= 1.12
3-
scipy >= 1.0
4-
matplotlib >= 2.1
2+
numpy >= 1.20
3+
scipy >= 1.7
4+
matplotlib >= 3.0
55
notebook >= 4.0
66
scikit-learn >= 0.18
7-
jupyter-book >= 0.10.2
87
napari[all]
98
jupytext >=1.10.3
10-
sphinx_autodoc_typehints>=1.11.0
11-
ghp-import
12-
pytest
13-
pytest-qt
14-
pooch
15-
furo
9+
furo
10+
myst-nb
11+
sphinx-copybutton

site/Makefile

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# Minimal makefile for Sphinx documentation
2-
#
1+
.PHONY: help Makefile clean
32

43
# You can set these variables from the command line, and also
54
# from the environment for the first two.
@@ -12,18 +11,10 @@ BUILDDIR = _build
1211
help:
1312
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
1413

15-
notebooks:
16-
mkdir -p notebooks
17-
jupytext -k python3 ../content/*.md --from myst --to notebook
18-
mv ../content/*.ipynb notebooks
19-
2014
clean:
2115
rm -rf _build
22-
rm -rf notebooks
23-
24-
.PHONY: help Makefile notebooks clean
2516

2617
# Catch-all target: route all unknown targets to Sphinx using the new
2718
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
2819
%: Makefile
29-
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

site/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
'myst_nb',
3232
'sphinx_copybutton',
3333
]
34+
jupyter_execute_notebooks = "off"
3435

3536
# Add any paths that contain templates here, relative to this directory.
3637
templates_path = ['_templates']
@@ -67,4 +68,4 @@
6768
# Add any paths that contain custom static files (such as style sheets) here,
6869
# relative to this directory. They are copied after the builtin static files,
6970
# so a file named "default.css" will overwrite the builtin "default.css".
70-
html_static_path = ['_static']
71+
html_static_path = ['_static']

site/content

Lines changed: 0 additions & 1 deletion
This file was deleted.

site/index.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[launch_binder]: http://mybinder.org/v2/gh/scikit-image/skimage-tutorials/main?urlpath=lab/tree/content
66

7-
## Content
7+
## Content
88

99
```{toctree}
1010
---
@@ -14,9 +14,8 @@ introduction
1414
applications
1515
```
1616

17-
1817
## Indices and tables
1918

2019
* {ref}`genindex`
2120
* {ref}`modindex`
22-
* {ref}`search`
21+
* {ref}`search`

site/introduction.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ Basic tutorials to prepare you for your journey on scikit-image.
66
---
77
maxdepth: 1
88
---
9-
content/tour_of_skimage.md
10-
content/00_images_are_arrays.md
11-
```
9+
content/tour_of_skimage
10+
content/00_images_are_arrays
11+
```

0 commit comments

Comments
 (0)