Skip to content

Commit 80aceef

Browse files
committed
DOC More comments & explanatory output
1 parent 6b27812 commit 80aceef

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

ch10/threshold.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,28 @@
77

88
import numpy as np
99
import mahotas as mh
10+
11+
# Load our example image:
1012
image = mh.imread('../SimpleImageDataset/building05.jpg')
13+
14+
# Convert to greyscale
1115
image = mh.colors.rgb2gray(image, dtype=np.uint8)
16+
17+
# Compute a threshold value:
1218
thresh = mh.thresholding.otsu(image)
13-
print(thresh)
19+
print('Otsu threshold is {0}'.format(thresh))
20+
21+
# Compute the thresholded image
1422
otsubin = (image > thresh)
23+
print('Saving thresholded image (with Otsu threshold) to otsu-threshold.jpeg')
1524
mh.imsave('otsu-threshold.jpeg', otsubin.astype(np.uint8) * 255)
16-
otsubin = ~ mh.close(~otsubin, np.ones((15, 15)))
25+
26+
# Execute morphological opening to smooth out the edges
27+
otsubin = mh.open(otsubin, np.ones((15, 15)))
1728
mh.imsave('otsu-closed.jpeg', otsubin.astype(np.uint8) * 255)
1829

30+
# An alternative thresholding method:
1931
thresh = mh.thresholding.rc(image)
20-
print(thresh)
32+
print('Ridley-Calvard threshold is {0}'.format(thresh))
33+
print('Saving thresholded image (with Ridley-Calvard threshold) to rc-threshold.jpeg')
2134
mh.imsave('rc-threshold.jpeg', (image > thresh).astype(np.uint8) * 255)

0 commit comments

Comments
 (0)