-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMix.py
83 lines (66 loc) · 2.44 KB
/
Mix.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
import matplotlib.pyplot as plt
from skimage import io
from skimage import img_as_float
from skimage.metrics import peak_signal_noise_ratio
from skimage.restoration import denoise_bilateral, denoise_tv_chambolle, denoise_wavelet
from skimage.restoration import estimate_sigma
# Read the input image
image_path = "Skeleton.jpg"
noisy_img = img_as_float(io.imread(image_path, as_gray=True))
ref_img = img_as_float(io.imread(image_path, as_gray=True))
# Denoising using bilateral filter
denoise_bilateral_img = denoise_bilateral(noisy_img, sigma_spatial=15)
bilateral_cleaned_psnr = peak_signal_noise_ratio(ref_img, denoise_bilateral_img)
# Denoising using total variation (TV) filter
denoise_tv_img = denoise_tv_chambolle(noisy_img, weight=0.1)
TV_cleaned_psnr = peak_signal_noise_ratio(ref_img, denoise_tv_img)
# Denoising using wavelet filter
denoise_wavelet_img = denoise_wavelet(noisy_img)
Wavelet_cleaned_psnr = peak_signal_noise_ratio(ref_img, denoise_wavelet_img)
# Print PSNR values
print("PSNR of input noisy image = inf")
print("PSNR of bilateral cleaned image = ", bilateral_cleaned_psnr)
print("PSNR of TV cleaned image = ", TV_cleaned_psnr)
print("PSNR of wavelet cleaned image = ", Wavelet_cleaned_psnr)
# Display the original and denoised images side by side
plt.figure(figsize=(10, 6))
# Display the original image
plt.subplot(1, 2, 1)
plt.title('Original Image')
plt.imshow(noisy_img, cmap='gray')
plt.axis('off')
# Display the bilateral cleaned image
plt.subplot(1, 2, 2)
plt.title('Bilateral Cleaned Image')
plt.imshow(denoise_bilateral_img, cmap='gray')
plt.axis('off')
plt.tight_layout()
plt.show()
# Display the original and denoised images side by side
plt.figure(figsize=(10, 6))
# Display the original image
plt.subplot(1, 2, 1)
plt.title('Original Image')
plt.imshow(noisy_img, cmap='gray')
plt.axis('off')
# Display the TV cleaned image
plt.subplot(1, 2, 2)
plt.title('TV Cleaned Image')
plt.imshow(denoise_tv_img, cmap='gray')
plt.axis('off')
plt.tight_layout()
plt.show()
# Display the original and denoised images side by side
plt.figure(figsize=(10, 6))
# Display the original image
plt.subplot(1, 2, 1)
plt.title('Original Image')
plt.imshow(noisy_img, cmap='gray')
plt.axis('off')
# Display the wavelet cleaned image
plt.subplot(1, 2, 2)
plt.title('Wavelet Cleaned Image')
plt.imshow(denoise_wavelet_img, cmap='gray')
plt.axis('off')
plt.tight_layout()
plt.show()