-
Notifications
You must be signed in to change notification settings - Fork 0
/
watersup_sim.m
47 lines (43 loc) · 1.12 KB
/
watersup_sim.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
function csiws = watersup_sim( csi, wat, beta)
% redisual water/lipid removal by L2 regularization
% csi: mrsi data with redisual water
% wat: water/lipid matrix
% delta: regularization parameter
beta = 10^(-beta);
NN = size(csi);
LL = length(NN);
%% single-voxel mrs
if LL == 1 || LL == 2
N = size(csi);
Water = wat;
Water_inv = inv(eye(N(1))+beta*(Water*Water'));
csiws = Water_inv*csi;
end
%% one-slice MRSI
if LL == 3
csi = permute(csi,[3 2 1]);
N = size(csi);
Water = wat;
Water_inv = inv(eye(N(1))+beta*(Water*Water'));
csi = reshape(csi,N(1),N(2)*N(3));
csi = Water_inv*csi;
csi = reshape(csi,N(1),N(2),N(3));
csi = permute(csi,[3 2 1]);
csiws = csi;
end
%% multiple-slice MRSI
if LL == 4
Water = wat;
Water_inv = inv( eye(NN(3)) + beta * (Water * Water'));
for ii = 1:NN(4)
csi1 = permute(csi(:,:,:,ii),[3 2 1 4]);
N = size(csi1);
csi1 = reshape(csi1,N(1),N(2)*N(3));
csi1 = Water_inv * csi1;
csi1 = reshape(csi1,N(1),N(2),N(3));
csi1 = permute(csi1,[3 2 1]);
csi(:,:,:,ii) = csi1;
end
csiws = csi;
end
end