-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMedical-Image-Processing__Morphology-DenoisingMethods-NLM-TotalVariation_Theorem.py
94 lines (83 loc) · 2.06 KB
/
Medical-Image-Processing__Morphology-DenoisingMethods-NLM-TotalVariation_Theorem.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
"""
Medical-Image-Processing__Morphology-DenoisingMethods-NLM-TotalVariation
Arya Koureshi(aryakoureshi.github.io)
arya.koureshi@gmail.com
"""
# %%
import cv2
import matplotlib.pyplot as plt
# %% part a
A = cv2.imread('C:/Users/aryak/OneDrive/Desktop/MAM/HW02_MIAP_Corrected/HW02_MIAP_Corrected/Theorem/image.png', cv2.IMREAD_GRAYSCALE)
_, A = cv2.threshold(A, 120, 1, cv2.THRESH_BINARY)
B = A[656: 691, 651:685]
C = cv2.erode(A, B, iterations=1)
plt.figure()
plt.suptitle('Erosion')
plt.subplot(1, 3, 1)
plt.imshow(A, cmap='gray', vmin=0, vmax=1)
plt.axis('off')
plt.title('A')
plt.subplot(1, 13, 7)
plt.imshow(B, cmap='gray', vmin=0, vmax=1)
plt.axis('off')
plt.title('B')
plt.subplot(1, 3, 3)
plt.imshow(C, cmap='gray', vmin=0, vmax=1)
plt.axis('off')
plt.title('C')
plt.tight_layout()
plt.show()
# %% part b
D = cv2.dilate(C, B, iterations=1)
plt.figure()
plt.suptitle('Dilation')
plt.subplot(1, 3, 1)
plt.imshow(C, cmap='gray', vmin=0, vmax=1)
plt.axis('off')
plt.title('C')
plt.subplot(1, 13, 7)
plt.imshow(B, cmap='gray', vmin=0, vmax=1)
plt.axis('off')
plt.title('B')
plt.subplot(1, 3, 3)
plt.imshow(D, cmap='gray', vmin=0, vmax=1)
plt.axis('off')
plt.title('D')
plt.tight_layout()
plt.show()
# %% part c
E = cv2.dilate(D, B, iterations=1)
plt.figure()
plt.suptitle('Dilation')
plt.subplot(1, 3, 1)
plt.imshow(D, cmap='gray', vmin=0, vmax=1)
plt.axis('off')
plt.title('D')
plt.subplot(1, 13, 7)
plt.imshow(B, cmap='gray', vmin=0, vmax=1)
plt.axis('off')
plt.title('B')
plt.subplot(1, 3, 3)
plt.imshow(E, cmap='gray', vmin=0, vmax=1)
plt.axis('off')
plt.title('E')
plt.tight_layout()
plt.show()
# %% part d
F = cv2.erode(E, B, iterations=1)
plt.figure()
plt.suptitle('Erosion')
plt.subplot(1, 3, 1)
plt.imshow(E, cmap='gray', vmin=0, vmax=1)
plt.axis('off')
plt.title('E')
plt.subplot(1, 13, 7)
plt.imshow(B, cmap='gray', vmin=0, vmax=1)
plt.axis('off')
plt.title('B')
plt.subplot(1, 3, 3)
plt.imshow(F, cmap='gray', vmin=0, vmax=1)
plt.axis('off')
plt.title('F')
plt.tight_layout()
plt.show()