-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_color.m
executable file
·106 lines (74 loc) · 1.96 KB
/
demo_color.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
close all;
clear;
clc;
% Starfish
xs = im2double(imread('images/starfish.png'));
% noisy motion blurry
noise_mean = 0;
noise_var = 0.00001;
h = im2double(rgb2gray(imread('./kernels/testkernel2.bmp')));
h = h./sum(h(:));
N = size(xs,1); M = size(xs,2); C = size(xs,3); Hf = psf2otf(h, [N M C]);
f = @(x) real(ifft2(fft2(x(:,:,:)).*Hf));
F = @(x) imnoise(f(x),'gaussian',noise_mean,noise_var);
y = F(xs);
lm = mLM(F, y); % modified LM
W = mW(F, y);
dfl_opts.maxiter = 500; % follows the paper
dfL = aL(F, y, dfl_opts); % approximate Landweber
figure();
imshow(xs);
title('Input image');
figure();
imshow(y);
title('Blurred image');
fprintf("PSNR of blurred: %f\n", psnr(y, xs));
figure();
imshow(lm);
title('LM');
fprintf("PSNR of modified LM: %f\n", psnr(lm, xs));
figure();
imshow(W);
title('Modified Wiener');
fprintf("PSNR of modified Wiener: %f\n", psnr(W, xs));
figure();
imshow(dfL);
title('Approx. Landweber');
fprintf("PSNR of approximate Landweber: %f\n", psnr(dfL, xs));
% Parrot
%close all;
clear;
%clc;
xs = im2double(imread('images/parrots.png'));
% noisy motion blurry
noise_mean = 0;
noise_var = 0.00001;
h = im2double(rgb2gray(imread('./kernels/testkernel2.bmp')));
h = h./sum(h(:));
N = size(xs,1); M = size(xs,2); C = size(xs,3); Hf = psf2otf(h, [N M C]);
f = @(x) real(ifft2(fft2(x(:,:,:)).*Hf));
F = @(x) imnoise(f(x),'gaussian',noise_mean,noise_var);
y = F(xs);
lm = mLM(F, y); % modified LM
W = mW(F, y);
dfl_opts.maxiter = 500; % follows the paper
dfL = aL(F, y, dfl_opts); % approximate Landweber
figure();
imshow(xs);
title('Input image');
figure();
imshow(y);
title('Blurred image');
fprintf("PSNR of blurred: %f\n", psnr(y, xs));
figure();
imshow(lm);
title('LM');
fprintf("PSNR of modified LM: %f\n", psnr(lm, xs));
figure();
imshow(W);
title('Modified Wiener');
fprintf("PSNR of modified Wiener: %f\n", psnr(W, xs));
figure();
imshow(dfL);
title('Approx. Landweber');
fprintf("PSNR of approximate Landweber: %f\n", psnr(dfL, xs));