-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests_ch09.py
52 lines (41 loc) · 1.32 KB
/
tests_ch09.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from skimage import io
import morphological_operators as mo
import matplotlib.pyplot as plt
import color_models
import numpy as np
def test_erosion(filename):
image = io.imread(filename)
image = color_models.rgb_to_grayscale(image.astype(np.float))
fig = plt.figure("Original vs Erosion")
fig.add_subplot(121)
plt.imshow(image, cmap="gray")
mo.erosion(image)
fig.add_subplot(122)
plt.imshow(image, cmap="gray")
plt.show()
def test_dilation(filename):
image = io.imread(filename)
image = color_models.rgb_to_grayscale(image.astype(np.float))
fig = plt.figure("Original vs Dilation")
fig.add_subplot(121)
plt.imshow(image, cmap="gray")
mo.dilation(image)
fig.add_subplot(122)
plt.imshow(image, cmap="gray")
plt.show()
def test_morphological_gradient(filename):
image = io.imread(filename)
image = color_models.rgb_to_grayscale(image.astype(np.float))
fig = plt.figure("Original vs Gradient")
fig.add_subplot(121)
plt.imshow(image, cmap="gray")
img_grad = mo.morphological_gradient(image)
# img_grad = mo.dilation(img_grad)
fig.add_subplot(122)
plt.imshow(img_grad, cmap="gray")
plt.show()
def test_batch_CH09():
filename = "lena.bmp"
test_erosion(filename)
test_dilation(filename)
test_morphological_gradient(filename)