-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex1_main.py
77 lines (57 loc) · 1.62 KB
/
ex1_main.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
from ex1_utils import *
from gamma import gammaDisplay
import numpy as np
import matplotlib.pyplot as plt
import time
def histEqDemo(img_path: str, rep: int):
img = imReadAndConvert(img_path, rep)
imgeq, histOrg, histEq = hsitogramEqualize(img)
# Display cumsum
cumsum = np.cumsum(histOrg)
cumsumEq = np.cumsum(histEq)
plt.gray()
plt.plot(range(256), cumsum, 'r')
plt.plot(range(256), cumsumEq, 'g')
# Display the images
plt.figure()
plt.imshow(img)
plt.figure()
plt.imshow(imgeq)
plt.show()
def quantDemo(img_path: str, rep: int):
img = imReadAndConvert(img_path, rep)
st = time.time()
img_lst, err_lst = quantizeImage(img, 3, 20)
print("Time:%.2f" % (time.time() - st))
print("Error 0:\t %f" % err_lst[0])
print("Error last:\t %f" % err_lst[-1])
plt.gray()
plt.imshow(img_lst[0])
plt.figure()
plt.imshow(img_lst[-1])
plt.figure()
plt.plot(err_lst, 'r')
plt.show()
def main():
print("ID:", myID())
img_path = 'sample_image.jpg'
# Basic read and display
imDisplay(img_path, LOAD_GRAY_SCALE)
imDisplay(img_path, LOAD_RGB)
# Convert Color spaces
img = imReadAndConvert(img_path, LOAD_RGB)
yiq_img = transformRGB2YIQ(img)
f, ax = plt.subplots(1, 2)
ax[0].imshow(img)
ax[1].imshow(yiq_img)
plt.show()
# Image histEq
histEqDemo(img_path, LOAD_GRAY_SCALE)
histEqDemo(img_path, LOAD_RGB)
# Image Quantization
quantDemo(img_path, LOAD_GRAY_SCALE)
quantDemo(img_path, LOAD_RGB)
# Gamma
gammaDisplay(img_path, LOAD_GRAY_SCALE)
if __name__ == '__main__':
main()