Skip to content

Commit 4559ad7

Browse files
committed
DOC Better documentation
1 parent d8eb307 commit 4559ad7

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

ch10/README.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
==========
2+
Chapter 10
3+
==========
4+
5+
Support code for *Chapter 10: Pattern Recognition & Computer Vision*
6+
7+
Data
8+
----
9+
10+
This chapter relies on a publicly available dataset (which can be downloaded
11+
using the ``download.sh`` script inside the ``data/`` directory) as well the
12+
dataset that is packaged with the repository at ``../SimpleImageDataset/``.
13+
14+
Running ``download.sh`` will retrieve the other dataset into a directory
15+
``AnimTransDistr/``.
16+
17+
Scripts
18+
-------
19+
20+
threshold.py
21+
Threshold building image with both Otsu and Ridley-Calvard threshold
22+
lena-ring.py
23+
Show Lena in a sharp ring around a soft focus image
24+
figure5_6.py
25+
Computes figures 5 and 6 in the book
26+
figure9.py
27+
Compute Sobel images
28+
figure10.py
29+
Just paste two images next to each others
30+
figure13.py
31+
Demonstrate salt&pepper effect
32+
edginess.py
33+
Contains the ``edginess_sobel`` function from the book
34+
simple_classification.py
35+
Classify SimpleImageDataset with texture features + sobel feature
36+
figure18.py
37+
Classify ``AnimTransDistr`` with both texture and SURF features.
38+

ch10/figure5_6.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,16 @@
99
import mahotas as mh
1010
image = mh.imread('../SimpleImageDataset/building05.jpg')
1111
image = mh.colors.rgb2gray(image)
12-
im8 = mh.gaussian_filter(image, 8)
12+
13+
# Compute Gaussian filtered versions with increasing kernel widths
14+
im8 = mh.gaussian_filter(image, 8)
1315
im16 = mh.gaussian_filter(image, 16)
1416
im32 = mh.gaussian_filter(image, 32)
17+
18+
# We now build a composite image with three panels:
19+
#
20+
# [ IM8 | | IM16 | | IM32 ]
21+
1522
h, w = im8.shape
1623
canvas = np.ones((h, 3 * w + 256), np.uint8)
1724
canvas *= 255
@@ -20,6 +27,11 @@
2027
canvas[:, -w:] = im32
2128
mh.imsave('../1400OS_10_05+.jpg', canvas[:, ::2])
2229

30+
# Threshold the image
31+
# We need to first stretch it to convert to an integer image
2332
im32 = mh.stretch(im32)
2433
ot32 = mh.otsu(im32)
25-
mh.imsave('../1400OS_10_06+.jpg', (im32 > ot32).astype(np.uint8) * 255)
34+
35+
# Convert to 255 np.uint8 to match the other images
36+
im255 = 255 * (im32 > ot32).astype(np.uint8)
37+
mh.imsave('../1400OS_10_06+.jpg', im255)

ch10/figure9.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
import mahotas as mh
1010
image = mh.imread('../SimpleImageDataset/building05.jpg')
1111
image = mh.colors.rgb2gray(image, dtype=np.uint8)
12+
13+
# We need to downsample ``image`` so that the details are visibly pixelated.
14+
# This exaggerates the effect so that the result is clear
1215
image = image[::4, ::4]
1316
thresh = mh.sobel(image)
1417
filtered = mh.sobel(image, just_filter=True)
1518

1619
thresh = mh.dilate(thresh, np.ones((7, 7)))
1720
filtered = mh.dilate(mh.stretch(filtered), np.ones((7, 7)))
1821

19-
22+
# Paste the thresholded and non-thresholded versions of the image side-by-side
2023
h, w = thresh.shape
2124
canvas = 255 * np.ones((h, w * 2 + 64), np.uint8)
2225
canvas[:, :w] = thresh * 255

0 commit comments

Comments
 (0)