-
Notifications
You must be signed in to change notification settings - Fork 1
/
grappa_gfactor.m
150 lines (120 loc) · 5.13 KB
/
grappa_gfactor.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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
%%
% for grappa_v2, data dimension order is [PE, RO, CHA]
%%
clear;
load('brain.mat')
kspace2D = ksp;
%% Generate downsampling and estimate CSM
rfac = 4;
[d1,d2,d3] = size(kspace2D);
ndim = d1; %phase encoding direction
off = 0; %starting sampling location % check the influence of off 01.02
nencode = 36; % The number of ACS lines
num_block = 3;
num_column = 5;
acs_line_loc = (round(ndim/2)+1-nencode/2):(round(ndim/2)+nencode/2);
pe_loc = (off+1):rfac:(d1-off);
acq_idx = zeros(d1,1);
acq_idx(pe_loc) = 1;
acq_idx(acs_line_loc) = 1;
NetR = d1 / sum(acq_idx)
%% g-factor analysis
sp = zeros(d1,d2);
sp(acs_line_loc,:) = 2;
csm = ismrm_estimate_csm(kspace2D,sp);
k_space_red = kspace2D(pe_loc,:,:);
acs_data = kspace2D(acs_line_loc,:,:);
tic
[full_fourier_data0] = grappa_v2(k_space_red, rfac, pe_loc, acs_data, acs_line_loc, num_block, num_column);
toc
if size(full_fourier_data0,1) < size(kspace2D,1)
kspace2D_recon = zeros(size(kspace2D));
kspace2D_recon(1:1:size(full_fourier_data0,1),:,:) = full_fourier_data0;
end
if size(full_fourier_data0,1) > size(kspace2D,1)
kspace2D_recon = full_fourier_data0(1:1:size(kspace2D,1),:,:);
end
if size(full_fourier_data0,1) == size(kspace2D,1);
kspace2D_recon = full_fourier_data0;
end
im_recon = sum(ismrm_transform_kspace_to_image(kspace2D_recon,[1,2]).*conj(csm),3);
as(im_recon)
% tic
% times_comp = 3;
% [full_fourier_data0, ImgRecon0, coef0] = nonlinear_grappa(k_space_red, rfac, pe_loc, acs_data, acs_line_loc, num_block, num_column,times_comp);
% toc
% if size(full_fourier_data0,1) < size(kspace2D,1)
% kspace2D_nlrecon = zeros(size(kspace2D));
% kspace2D_nlrecon(1:1:size(full_fourier_data0,1),:,:) = full_fourier_data0;
% end
% if size(full_fourier_data0,1) > size(kspace2D,1)
% kspace2D_nlrecon = full_fourier_data0(1:1:size(kspace2D,1),:,:);
% end
% if size(full_fourier_data0,1) == size(kspace2D,1);
% kspace2D_nlrecon = full_fourier_data0;
% end
% im_nlrecon = sum(ismrm_transform_kspace_to_image(kspace2D_nlrecon,[1,2]).*conj(csm),3);
% as(im_nlrecon)
im_true_coil = ismrm_transform_kspace_to_image(kspace2D,[1,2]);
im_true = sum(im_true_coil .* conj(csm),3);
im_diff_grappa = mat2gray(abs(im_true)) - mat2gray(abs(im_recon));
rmse_grappa = norm(im_diff_grappa(:))/norm(im_true(:))
% im_diff_nlgrappa = mat2gray(abs(im_true)) - mat2gray(abs(im_nlrecon));
% rmse_nlgrappa = norm(im_diff_nlgrappa(:))/norm(im_true(:))
is_pseudo_replica = 1;
if (is_pseudo_replica)
noise_level = 0.001*max(abs(im_recon(:)));
reps = 500;
im_size = [size(kspace2D,1),size(kspace2D,2)];
img_noise_rep = zeros([im_size,reps]);
noise_rep = zeros([im_size,reps]);
ref_img_noise_rep = zeros([im_size,reps]);
tic
parfor r = 1:reps
% white gaussian noise scaled by noise_level
noise_white = noise_level*complex(randn(size(kspace2D)),randn(size(kspace2D)));
% add noise to image
im_ref_noise = im_true_coil + noise_white;
% simulate noisy k-space data
data_noise = ismrm_transform_image_to_kspace(im_ref_noise,[1,2]);
% simulate GRAPPA downsampling
k_space_red = data_noise(pe_loc,:,:);
acs_data = data_noise(acs_line_loc,:,:);
%% GRAPPA reconstruction
tic
[full_fourier_data0] = grappa_v2(k_space_red, rfac, pe_loc, acs_data, acs_line_loc, num_block, num_column);
toc
%%% nonlinear grappa reconstruction
% tic
% times_comp = 3;
% [full_fourier_data0] = nonlinear_grappa(k_space_red, rfac, pe_loc, acs_data, acs_line_loc, num_block, num_column,times_comp);
% toc
%
if size(full_fourier_data0,1) < size(kspace2D,1)
kspace2D_recon1 = zeros(size(kspace2D));
kspace2D_recon1(1:1:size(full_fourier_data0,1),:,:) = full_fourier_data0;
end
if size(full_fourier_data0,1) > size(kspace2D,1)
kspace2D_recon1 = full_fourier_data0(1:1:size(kspace2D,1),:,:);
end
if size(full_fourier_data0,1) == size(kspace2D,1);
kspace2D_recon1 = full_fourier_data0;
end
im_recon = sum(ismrm_transform_kspace_to_image(kspace2D_recon1,[1,2]).*conj(csm),3);
% recorded image
img_noise_rep(:,:,r) = im_recon;
ref_img_noise_rep(:,:,r) = sum(im_ref_noise.*conj(csm),3);
noise_rep(:,:,r) = sum(noise_white.*conj(csm),3);
end
toc
%% Calculating g-factor
img_noise_rep = reshape(img_noise_rep,[im_size,reps]);
rep_dim = length(size(img_noise_rep));
std_pseudo = std(abs(img_noise_rep + max(abs(img_noise_rep(:)))),[],rep_dim); %Measure variation, but add offset to create "high snr condition"
std_noise = std(abs(noise_rep + max(abs(noise_rep(:)))),[],rep_dim);
std_full = std(abs(ref_img_noise_rep + max(abs(ref_img_noise_rep(:)))),[],rep_dim);
gmap_pseudo = std_pseudo ./(std_full.*sqrt(rfac)); % Be careful about the scaling factor sqrt(NetR)
gmap_pseudo(gmap_pseudo < eps) = 1;
as(gmap_pseudo)
sprintf('GRAPPA g_mean by Pseudo Replica : %f, g_max : %f',mean(gmap_pseudo(:)),max(gmap_pseudo(:)))
end