2020-11-25 14:20:13 +00:00
|
|
|
close all;
|
|
|
|
clear; clc;
|
2020-11-27 22:19:51 +00:00
|
|
|
addpath /Users/maggicl/Git/matlab2tikz/src/;
|
2020-11-25 14:20:13 +00:00
|
|
|
|
|
|
|
%% Load Default Img Data
|
|
|
|
load('blur_data/B.mat');
|
|
|
|
B=double(B);
|
2020-11-27 22:19:51 +00:00
|
|
|
load('blur_data/A.mat');
|
|
|
|
A=double(A);
|
|
|
|
ciao = A;
|
2020-11-25 14:20:13 +00:00
|
|
|
|
|
|
|
% Show Image
|
|
|
|
figure
|
|
|
|
im_l=min(min(B));
|
|
|
|
im_u=max(max(B));
|
|
|
|
imshow(B,[im_l,im_u])
|
|
|
|
title('Blured Image')
|
|
|
|
|
|
|
|
% Vectorize the image (row by row)
|
|
|
|
b=B';
|
|
|
|
b=b(:);
|
|
|
|
|
2020-11-27 22:19:51 +00:00
|
|
|
AT = A * A';
|
|
|
|
bt = A' * b;
|
|
|
|
|
|
|
|
IL = ichol(AT, struct('type', 'nofill', 'diagcomp', 0.01));
|
|
|
|
y = IL \ b;
|
|
|
|
x0 = IL' \ y;
|
|
|
|
|
|
|
|
[x, rvec] = myCG(AT, bt, x0, 200, 1e-6);
|
|
|
|
[x2, ~, ~, ~, rvec2] = pcg(AT, bt, 1e-6, 200, IL, IL');
|
|
|
|
|
|
|
|
figure;
|
|
|
|
semilogy(rvec);
|
|
|
|
hold on;
|
|
|
|
semilogy(rvec2);
|
|
|
|
hold off;
|
|
|
|
title('Residual norms over iteration (y is log)')
|
|
|
|
matlab2tikz('showInfo', false, '../res_log.tex');
|
|
|
|
|
|
|
|
|
|
|
|
X = zeros(250, 250);
|
|
|
|
for i = 0:249
|
|
|
|
for j = 1:250
|
|
|
|
X(i + 1, j) = x(i * 250 + j);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
figure;
|
|
|
|
im_l=min(min(X));
|
|
|
|
im_u=max(max(X));
|
|
|
|
imshow(X,[im_l,im_u])
|
|
|
|
title('Sharp Image (myCG)')
|
|
|
|
matlab2tikz('showInfo', false, '../img_my.tex');
|
|
|
|
|
|
|
|
|
|
|
|
X2 = zeros(250, 250);
|
|
|
|
for i = 0:249
|
|
|
|
for j = 1:250
|
|
|
|
X2(i + 1, j) = x2(i * 250 + j);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
figure;
|
|
|
|
im_l=min(min(X2));
|
|
|
|
im_u=max(max(X2));
|
|
|
|
imshow(X2,[im_l,im_u])
|
|
|
|
title('Sharp Image (rcg)')
|
|
|
|
matlab2tikz('showInfo', false, '../img_rcg.tex');
|
|
|
|
|
2020-11-25 14:20:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
%% Validate Test values
|
|
|
|
load('test_data/A_test.mat');
|
|
|
|
load('test_data/x_test_exact.mat');
|
|
|
|
load('test_data/b_test.mat');
|
|
|
|
|
|
|
|
%res=||x^*-A^{-1}b||
|
2020-11-27 22:19:51 +00:00
|
|
|
res=x_test_exact-inv(A_test)*b_test;
|
|
|
|
norm(res);
|
2020-11-25 14:20:13 +00:00
|
|
|
%(Now do it with your CG and Matlab's PCG routine!!!)
|