-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccp_steep_desc.m
90 lines (74 loc) · 2.99 KB
/
ccp_steep_desc.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
function ccp_steep_desc
% Based on demo9
%
%
% GRAPPA reconstruction with the steepest descent step
% to illustrate the use of Acquisition Model projections.
if ~libisloaded('mutilities')
fprintf('loading mutilities library...\n')
[notfound, warnings] = loadlibrary('mutilities');
end
if ~libisloaded('mgadgetron')
fprintf('loading mgadgetron library...\n')
[notfound, warnings] = loadlibrary('mgadgetron');
end
%try
% define raw data source
filenm = pref_uigetfile('ccp_steep_desc','filename') ;
input_data = gadgetron.MR_Acquisitions(filenm);
% pre-process acquisitions
prep_gadgets = [{'NoiseAdjustGadget'} {'AsymmetricEchoGadget'} ...
{'RemoveROOversamplingGadget'}];
acq_proc = gadgetron.AcquisitionsProcessor(prep_gadgets);
fprintf('---\n pre-processing acquisitions...\n')
preprocessed_data = acq_proc.process(input_data);
pp_norm = preprocessed_data.norm();
% perform reconstruction
recon = gadgetron.MR_BasicGRAPPAReconstruction();
recon.set_input(preprocessed_data);
fprintf('---\n reconstructing...\n');
recon.process();
output = recon.get_output();
complex_images = output.select(2);
% compute coil sensitivity maps
csms = gadgetron.MR_CoilSensitivityMaps();
fprintf('---\n sorting acquisitions...\n')
preprocessed_data.sort()
fprintf('---\n calculating sensitivity maps...\n')
csms.calculate(preprocessed_data)
% create acquisition model based on the acquisition parameters
% stored in preprocessed_data and image parameters stored in complex_images
am = gadgetron.MR_AcquisitionModel(preprocessed_data, complex_images);
am.set_coil_sensitivity_maps(csms)
% use the acquisition model (forward projection) to simulate acquisitions
fwd_data = am.forward(complex_images);
fwd_norm = fwd_data.norm();
% compute the difference between real and simulated acquisitions
diff = fwd_data - preprocessed_data * (fwd_norm/pp_norm);
rr = diff.norm()/fwd_norm;
fprintf('---\n reconstruction residual norm (rel): %e\n', rr)
% try to improve the reconstruction by the steepest descent step
g = am.backward(diff);
w = am.forward(g);
alpha = (g*g)/(w*w);
r_complex_imgs = complex_images - g*alpha;
% get real-valued reconstructed and refined images
images = gadgetron.MR_extract_real_images(complex_images);
r_imgs = gadgetron.MR_extract_real_images(r_complex_imgs);
% plot images
data1 = images.image_as_array(1);
rdata1 = r_imgs.image_as_array(1);
nim = images.number() ;
data = zeros(size(data1,1), size(data1,2),nim) ;
rdata = zeros(size(rdata1,1), size(rdata1,2),nim) ;
for im = 1:nim
data(:,:,im) = images.image_as_array(im);
rdata(:,:,im) = r_imgs.image_as_array(im);
end
eshow(data,'Name','initial recon')
eshow(rdata,'Name','refined recon')
% catch err
% % display error information
% fprintf('%s\n', err.message)
% fprintf('error id is %s\n', err.identifier)
% end