-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdemo_CSC_constrained.m
63 lines (48 loc) · 1.79 KB
/
demo_CSC_constrained.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
clear
clc
close all
%% load dictionary
load('dictK16m8.mat')
%% highpassed input image
hsize = size(D,1);
S = imread('.\Data\lena_std.tif');
S = double(rgb2gray(S))/255;
Smean = conv2(S,ones(hsize)/hsize^2,'same');
Sh = S - Smean;
[H, W, ~] = size(Sh);
%% parameters and setting
opts.MaxIter = 200;
opts.AutoRho= 0;
%% Unconstrained CSC
lamb = 0.05;
[X,Res_uncons] = CSC_unconstrained(D,Sh,lamb,opts);
S_rec_uncons = ifft2(sum(fft2(D,H,W).*fft2(X),3),'symmetric');
rt_uncons = Res_uncons.iterinf(end,end); % runtime unconstrained CSC
Err_uncons = norm(Sh(:)-S_rec_uncons(:))^2; % approximation error unconstrained CSC
L1_uncons = sum(abs(X(:))); % L1-norm unconstrained CSC
%% Constrained CSC
Eps = Err_uncons;
opts.lamb = lamb;
[X_cons,Res_cons] = CSC_constrained(D, Sh, Eps,opts);
S_rec_cons = ifft2(sum(fft2(D,H,W).*fft2(X_cons),3),'symmetric');
rt_cons = Res_cons.iterinf(end,end);
Err_cons = norm(Sh(:)-S_rec_cons(:))^2; % approximation error constrained CSC
L1_cons = sum(abs(X_cons(:))); % L1-norm constrained CSC
%% printing results
fprintf('Results: \n')
fprintf('%s %11s %10s %12s \n', 'CSC method','L1_norm','Error','runtime')
fprintf('%s %10s %10s %10s \n', 'Unconstrained',num2str(L1_uncons),num2str(Err_uncons),num2str(rt_uncons))
fprintf('%s %12s %10s %10s \n', 'Constrained',num2str(L1_cons),num2str(Err_cons),num2str(rt_cons))
%% reconstruction
S_rec_cons = ifft2(sum(fft2(D,size(X_cons,1),size(X_cons,2)).*fft2(X_cons),3),'symmetric') + Smean;
S_rec_uncons = ifft2(sum(fft2(D,size(X,1),size(X,2)).*fft2(X),3),'symmetric') + Smean;
figure(2)
subplot(131)
imshow(S,[])
title('Original')
subplot(132)
imshow(S_rec_cons, [])
title('Reconstructed (constrained)')
subplot(133)
imshow(S_rec_uncons, [])
title('Reconstructed (unconstrained)')