-
Notifications
You must be signed in to change notification settings - Fork 0
/
KmultT_channels.m
59 lines (48 loc) · 1.64 KB
/
KmultT_channels.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
function x = KmultT_channels(y, db_chs, w_tv, w_cross_channels, w_regularization)
% This function compute the computation of transposed matrix K.
x = [];
for ch = 1:length(y)
x = cat(3, x, KmultT(y, ch, db_chs, w_tv, w_cross_channels(ch,:), w_regularization));
end
end
function x = KmultT(y, ch, db_chs, w_tv, w_cross_channels, w_regularization)
%Result
n_ch = length(y);
y = y{ch};
x = zeros(size(y,1), size(y,2));
% derivative filters
dxf=[-1 1];
dyf=[-1;1];
i = 0; % regularization term counter
i = i + 1;
x_tv = - w_tv * div(y(:,:,i:i+1));
% gather result
x = x + x_tv;
i = i + 1;
i = i + 1; % overall weighting term(???)
xpr = w_regularization * y(:,:,i);
x = x + xpr;
%Cross-Terms for all adjacent channels
for adj_ch = 1:n_ch
%Continue for current channel and zero channels
if adj_ch == ch || w_cross_channels(adj_ch) < eps()
continue;
end
adjChImg = db_chs(adj_ch).Image; %Curr cross channel
%Compute cross terms
i = i + 1;
y(:,:,i) = (w_cross_channels(adj_ch) * 0.5) * y(:,:,i);
diag_term = imfilter(adjChImg, fliplr(flipud(dxf)), 'conv', 'full');
diag_term = diag_term(:, 2:end) .* y(:,:,i);
conv_term = imfilter(adjChImg.*y(:,:,i), dxf, 'conv', 'full');
Sxtf = ( conv_term(:,1:(end-1)) - diag_term );
i = i + 1;
y(:,:,i) = (w_cross_channels(adj_ch) * 0.5) * y(:,:,i);
diag_term = imfilter(adjChImg, fliplr(flipud(dyf)), 'conv', 'full');
diag_term = diag_term(2:end, :) .* y(:,:,i);
conv_term = imfilter(adjChImg.*y(:,:,i), dyf, 'conv', 'full');
Sytf = ( conv_term(1:(end-1),:) - diag_term );
%Gather result
x = x + Sxtf + Sytf;
end
end