-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests_ch06.py
122 lines (103 loc) · 3.4 KB
/
tests_ch06.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import math
from matplotlib import pyplot as plt
from skimage import io
from skimage.color import hsv2rgb
from skimage.color import rgb2hsv
from skimage.util import img_as_float
from skimage import exposure
from tempfile import TemporaryFile
import color_filters as cf
import color_models as cm
import wavelets_transforms as wt
import numpy as np
def test_color_models(image):
fig = plt.figure("Color Model")
ax = fig.add_subplot(1, 2, 1)
ax.set_title("Original Image")
plt.imshow(image)
ax = fig.add_subplot(1, 2, 2)
ax.set_title("Modified Image")
hsi_image = cm.rgb_to_hsi(image)
rgb_image = cm.hsi_to_rgb(hsi_image)
plt.imshow(rgb_image, cmap='gray')
plt.show()
def test_brightness(image):
fig = plt.figure("Color Model")
ax = fig.add_subplot(1, 2, 1)
ax.set_title("Original Image")
plt.imshow(image)
ax = fig.add_subplot(1, 2, 2)
ax.set_title("Modified Image")
hsi_image = cf.brightness_filter(image, 0.3)
plt.imshow(hsi_image, cmap='hsv')
plt.show()
def test_average_filter(image):
fig = plt.figure("Color Model")
ax = fig.add_subplot(2, 2, 1)
ax.set_title("Original Image")
plt.imshow(image)
ax = fig.add_subplot(2, 2, 2)
ax.set_title("RGB Image")
avg_image = cf.average_filter_rgb(image)
plt.imshow(avg_image, cmap='gray')
ax = fig.add_subplot(2, 2, 3)
ax.set_title("HSI Image")
hsi_image = rgb2hsv(image)
hsi_image = cf.average_filter_hsi(hsi_image)
hsi_image = hsv2rgb(hsi_image)
plt.imshow(hsi_image, cmap='gray')
plt.show()
def test_tone_filter_rgb(image):
fig = plt.figure("Color Model")
ax = fig.add_subplot(1, 2, 1)
ax.set_title("Original Image")
plt.imshow(image)
ax = fig.add_subplot(1, 2, 2)
ax.set_title("Modified Image")
hsi_image = cf.tone_filter_rgb(img_as_float(image), lambda x: math.pow(x, 1.25))
plt.imshow(hsi_image, cmap='hsv')
plt.show()
def test_sepia(image):
fig = plt.figure("Color Model")
ax = fig.add_subplot(1, 2, 1)
ax.set_title("Original Image")
plt.imshow(image)
ax = fig.add_subplot(1, 2, 2)
ax.set_title("Modified Image")
hsi_image = cf.sepia_filter(img_as_float(image))
plt.imshow(hsi_image, cmap='gray')
plt.show()
def test_histogram(image):
fig = plt.figure("Color Model")
ax = fig.add_subplot(1, 2, 1)
ax.set_title("Original Image")
plt.imshow(image)
ax = fig.add_subplot(1, 2, 2)
ax.set_title("Modified Image")
hsi_image = cf.image_equalization(image)
plt.imshow(hsi_image, cmap='gray')
plt.show()
def test_chroma_key(image1, image2):
chroma = cf.chroma_key(img_as_float(image1), img_as_float(image2))
plt.imshow(chroma, cmap="gray")
plt.show()
def test_batch_CH06():
image = io.imread("dog.jpg")
# test_color_models(image)
# test_brightness(image)
# test_average_filter(image)
# test_tone_filter_rgb(image)
# test_sepia(image)
# test_histogram(image)
# donald = io.imread("donald.jpg")
# back = io.imread("back.jpg")
# test_chroma_key(donald, back)
lena = io.imread("lena.bmp")
t_lena = wt.haar_image(img_as_float(lena), level=5)
t_lena_n = exposure.rescale_intensity(t_lena, in_range=(0, 1))
plt.imshow(t_lena_n, cmap="gray")
plt.show()
t_lena = wt.haar_inverse_image(t_lena, level=5)
t_lena = exposure.rescale_intensity(t_lena, in_range=(0, 1))
plt.imshow(t_lena, cmap="gray")
plt.show()