-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_denoising.m
77 lines (65 loc) · 1.7 KB
/
main_denoising.m
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
clc; clear; close all;
addpath("figure\");
addpath("function\");
file = 'lenna.jpg';
% parameter
grayscale = true;
resize = true;
sigma = 5e-3; % gaussian noise
lambda = 10;
gamma = 5;
tol = 1e-6;
maxIter = 100;
if grayscale
image = rgb2gray(imread(file));
else
image = imread(file);
end
if resize
image = imresize(image, [512 512]);
end
u_exact = double(image) / 255;
f = imnoise(u_exact, 'gaussian', 0, sigma); % generate noise
%% Denosing
tic;
u_sol = ROFDenoising(f, lambda, gamma, tol, maxIter);
psnr = ComputePSNR(u_sol, u_exact);
time = toc;
%% Plot figure
figure;
subplot(2, 2, 1);
imshow(u_exact);
title("Original Image");
subplot(2, 2, 2);
imshow(f);
title("Noisy Image");
subplot(2, 2, 3);
imshow(u_sol);
title("ROF Denoising");
subplot(2, 2, 4);
imshow((u_sol-u_exact)*10);
title("Differece between origin and denoising");
fprintf("The PSNR of denosing image is %.4d\n", psnr);
fprintf("The time spending of ROF denosing is %.4d sec\n", time);
%% Compare with difference lambda
clc; figure;
ts = TightSubplot(2, 3, [0.05 0.01], [0.03 0.05], [0.06 0.06]);
Lambda = [5, 10, 15, 20];
axes(ts(1));
imshow(u_exact);
title("Original image", "Interpreter", "latex", "FontSize", 14);
axes(ts(2));
imshow(f);
txt = "Noisy image with $\sigma=\,$" + num2str(sigma);
title(txt, "Interpreter", "latex", "FontSize", 14);
for k = 1:4
u_sol = ROFDenoising(f, Lambda(k), gamma, tol, maxIter);
psnr = ComputePSNR(u_sol, u_exact);
axes(ts(k+2));
imshow(u_sol);
txt = "$\lambda=\,$" + num2str(Lambda(k)) +...
", PSNR$=\,$" + num2str(psnr);
title(txt, "Interpreter", "latex", "FontSize", 14)
fprintf("The PSNR of denosing image with lambda = %d is %.4d\n", ...
Lambda(k), psnr);
end