-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab1.py
More file actions
68 lines (51 loc) · 1.46 KB
/
Lab1.py
File metadata and controls
68 lines (51 loc) · 1.46 KB
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
# Plot histograms for parts of two images- unnoisy and noisy
import matplotlib.pyplot as plt
import cv2
ny=4
nx=4
img = cv2.imread('./images/unnoisy-image.jpg',0)
h = int(img.shape[0]/ny)
w = int(img.shape[1]/nx)
plot_no=1
for i in range(ny):
for j in range(nx):
part = img[i*h:(i+1)*h,j*w:(j+1)*w]
plt.subplot(ny,nx,plot_no)
plt.imshow(part, cmap='gray')
plot_no+=1
plt.suptitle('Unnoisy image')
plt.show()
plot_no=1
for i in range(ny):
for j in range(nx):
part = img[i*h:(i+1)*h,j*w:(j+1)*w]
part = part.flatten()
plt.subplot(ny,nx,plot_no)
hist = cv2.calcHist([part],[0], None, [256], [0,256])
plt.plot(hist)
plot_no+=1
plt.suptitle('Histograms for Unnoisy image')
plt.show()
img = cv2.imread('./images/noisy-image.png',0)
h = int(img.shape[0]/ny)
w = int(img.shape[1]/nx)
plot_no=1
for i in range(ny):
for j in range(nx):
part = img[i*h:(i+1)*h,j*w:(j+1)*w]
plt.subplot(ny,nx,plot_no)
plt.imshow(part, cmap='gray')
plot_no+=1
plt.suptitle('Noisy image')
plt.show()
plot_no=1
for i in range(ny):
for j in range(nx):
part = img[i*h:(i+1)*h,j*w:(j+1)*w]
part = part.flatten()
plt.subplot(ny,nx,plot_no)
hist = cv2.calcHist([part],[0], None, [256], [0,256])
plt.plot(hist)
plot_no+=1
plt.suptitle('Histograms for noisy image')
plt.show()