-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path3A.py
68 lines (51 loc) · 1.79 KB
/
3A.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
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from freq_filters import filter_image_freq
from scaling_functions import im2double, im2uint8
# Global max and min intensity values for plotting
max_r = np.iinfo(np.uint8).max
min_r = np.iinfo(np.uint8).min
if __name__ == "__main__":
# Load images to numpy arrays
img1 = mpimg.imread('data/P3_fig1.png')
img2 = mpimg.imread('data/P3_fig2.png')
img3 = mpimg.imread('data/P3_fig3.png')
# Get power spectrum of image 3
_, _, P3 = filter_image_freq(img3)
# Scale to uint8 before displaying
img1 = im2uint8(img1)
img2 = im2uint8(img2)
img3 = im2uint8(img3)
# Extract a subimage from image 1 with reasonably constant background intensity
subimage1 = img1[240:290, 100:200]
# Extract a subimage from image 2 with reasonably constant background intensity
subimage2 = img2[240:290, 100:200]
# Plot results
fig = plt.figure()
fig.suptitle('3A: Denoising', fontsize=20)
ax = plt.subplot(2,3,1)
ax.set_title("Image 1")
plt.imshow(img1, cmap=plt.cm.gray, vmin=min_r, vmax=max_r)
plt.axis('off')
ax = plt.subplot(2,3,2)
ax.set_title("Image 2")
plt.imshow(img2, cmap=plt.cm.gray, vmin=min_r, vmax=max_r)
plt.axis('off')
ax = plt.subplot(2,3,3)
ax.set_title("Image 3")
plt.imshow(img3, cmap=plt.cm.gray, vmin=min_r, vmax=max_r)
plt.axis('off')
ax = plt.subplot(2,3,4)
ax.set_title("Subimage 1 Histogram")
plt.hist(subimage1.ravel(), bins=max_r, range=(min_r, max_r), normed=True, color='k')
plt.xlim((min_r,max_r))
ax = plt.subplot(2,3,5)
ax.set_title("Subimage 2 Histogram")
plt.hist(subimage2.ravel(), bins=max_r, range=(min_r, max_r), normed=True, color='k')
plt.xlim((min_r,max_r))
ax = plt.subplot(2,3,6)
ax.set_title("Image 3 Power Spectrum")
plt.imshow(P3, cmap=plt.cm.gray)
plt.axis('off')
plt.show()