-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_spatial.m
More file actions
96 lines (73 loc) · 1.93 KB
/
test_spatial.m
File metadata and controls
96 lines (73 loc) · 1.93 KB
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
% Comparison of the CVX and ADMM Spatial solver accuracy
%
% Copyright, Henryk Blasinski, 2015
close all;
clear variables;
clc;
%% This is a test script to show that the ADMM and cvx solutions are the same
% For this purpose we create random camera, basis function and measurement
% matrices.
% Choose problem size
nChannels = 7;
nWaves = 30;
nBasis = 5;
h = 5;
w = 5;
% Generate data
cameraMat = rand(nChannels,nWaves);
basisFcns = rand(nWaves,nBasis);
measImg = randn([h,w,nChannels]);
% Select solution regularizers. We only want to enforce spatial and spectral
% smoothness
alpha = 0.1;
beta = 0.1;
gamma = 0;
%% CVX solution
Xcvx = spectralEstCVX(measImg, cameraMat, basisFcns, alpha, beta, gamma);
% Reflectance estimates
reflCvx = basisFcns*reshape(Xcvx,h*w,nBasis)';
figure;
hold on; grid on; box on;
plot(reflCvx);
xlabel('Wavelength, au');
title('Reflectance estimates cvx');
% Spatial arrangement of basis weights
figure;
for i=1:nBasis
subplot(2,3,i);
imagesc(Xcvx(:,:,i),[min(Xcvx(:)) max(Xcvx(:))]); axis image;
title(sprintf('Basis %i',i));
end
%% ADMM solution
[Xadmm, hist] = spectralEstADMM( measImg, cameraMat, basisFcns, alpha, beta, gamma,...
'tol',0,...
'rescaleRho',true,...
'maxIter',1000,...
'verbose',true,...
'reference',Xcvx);
% Reflectance estimates
reflAdmm = basisFcns*reshape(Xadmm,h*w,nBasis)';
figure;
hold on; grid on; box on;
plot(reflAdmm);
xlabel('Wavelength, au');
title('Reflectance estimates ADMM');
% Convergence
figure;
hold on; grid on; box on;
plot([hist.prRes hist.dualRes hist.conv]);
xlabel('Iteration');
legend('Primal','Dual','Solution');
title('ADMM residuals');
figure;
hold on; grid on; box on;
plot(hist.rho);
xlabel('Iteration');
title('Rho');
% Accuracy comparison with cvx
figure;
grid on; box on; hold on; axis square;
plot(Xadmm(:),Xcvx(:),'.');
xlabel('ADMM');
ylabel('CVX');
title(sprintf('ADMM vs. CVX accuracy (RMSE %f)',rms(Xcvx(:) - Xadmm(:))));