-
Notifications
You must be signed in to change notification settings - Fork 3
/
T1rho_maps3.m
220 lines (219 loc) · 6.56 KB
/
T1rho_maps3.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
%#######################################################################
%
% * T1rho Map Sensitivity 3 Program *
%
% M-File which reads knee T1rho data with different spinlock
% times in the cartilage regions from T1rho_maps_S501.mat which was
% generated by T1rho_maps.m. The difference in T1rho values
% between using four or five spin lock times and the values from
% using all seven spin lock times are plotted as histograms. The
% T1rho values are split between superficial and deep cartilage
% layers. Summary statistics on the T1rho differences are included
% on the plots and written to a MS-Excel spreadsheet,
% T1rho_maps3_S501.xlsx.
%
% NOTES: 1. Must have MAT files T1rho_maps_S501.mat and
% T1rho_S501.mat in the current directory.
%
% 03-Sep-2020 * Mack Gardner-Morse
%
%#######################################################################
%
% Load T1rho Values for Series 501 MRI Data
%
load T1rho_maps_S501.mat;
load T1rho_S501.mat fs slt;
%
% Initialize Arrays for Calculating the T1rho Differences
%
dT1rhonlss = cell(nrsl,1);
idv = cell(nrsl,1);
id1l = cell(nrsl,1);
id2l = cell(nrsl,1);
%
% Loop through Slices with ROIs to Calculate the T1rho Differences
%
for k = 1:nrsl % Loop through slices with ROIs
%
id1 = find(mask1(:,k));
id2 = find(mask2(:,k));
idc = find(maskc(:,k));
%
id1l{k} = ismember(idc,id1); % [~,id1l2] = intersect(idc,id1); - Logical index uses less space
id2l{k} = ismember(idc,id2);
%
idv{k} = T1rhonlss{k}(:,nt)>0&T1rhonlss{k}(:,nt)<100; % Use values based on all seven (7) spin lock times
%
dT1rhonlss{k} = T1rhonlss{k}-repmat(T1rhonlss{k}(:,nt),1,nt);
%
end
%
% Get Four and Five Spin Lock Times Combinations
%
idx = nszc(3)+1:nszc(5); % Get 4 and 5 spin lock times combinations
nc = size(idx,2);
%
% Initialize Arrays for Looping Through the Spin Lock Times Combinations
%
binedg = -15:0.5:15; % Bin edges for histograms
hnam = ['T1rho_maps3_hist_' fs '.ps']; % Histograms print file name
xnam = ['T1rho_maps3_' fs '.xlsx']; % MS-Excel File
%
sltc = cell(nc,1);
%
n0 = zeros(nc,1);
mn0 = zeros(nc,1);
md0 = zeros(nc,1);
sd0 = zeros(nc,1);
%
n1 = zeros(nc,1);
mn1 = zeros(nc,1);
md1 = zeros(nc,1);
sd1 = zeros(nc,1);
%
n2 = zeros(nc,1);
mn2 = zeros(nc,1);
md2 = zeros(nc,1);
sd2 = zeros(nc,1);
%
% Loop through Combinations with Four or Five Spin Lock Times
%
for k = 1:nc % Loop through combinations
%
idxc = idx(k); % Index to trial column
%
[l,m] = ncombi(idx(k),nszc);
sltc{k} = ncomb{l}(m,:);
sltc{k} = int2str(slt(sltc{k})'); % Combination of spin lock times
sltc{k} = regexprep(sltc{k},' +',', ');
sltct = ['Spin lock times = ' sltc{k} ' ms']; % For plot titles
%
hdat0 = [dT1rhonlss{1}(idv{1},idxc); ...
dT1rhonlss{2}(idv{2},idxc); ...
dT1rhonlss{3}(idv{3},idxc)]; % All three slices
%
n0(k) = size(hdat0,1);
mn0(k) = mean(hdat0);
md0(k) = median(hdat0);
sd0(k) = std(hdat0);
%
% Plot Histograms of the Cartilage T1rho Differences
%
hf = figure;
orient tall;
%
hdat1 = [dT1rhonlss{1}(idv{1}&id1l{1},idxc); ...
dT1rhonlss{2}(idv{2}&id1l{2},idxc); ...
dT1rhonlss{3}(idv{3}&id1l{3},idxc)]; % All three slices
%
n1(k) = size(hdat1,1);
mn1(k) = mean(hdat1);
md1(k) = median(hdat1);
sd1(k) = std(hdat1);
%
htxt1 = ['N = ' int2str(n1(k))];
htxt2 = ['Mean \DeltaT1\rho = ' sprintf('%.2f',mn1(k))];
htxt3 = ['Median \DeltaT1\rho = ' sprintf('%.2f',md1(k))];
htxt4 = ['SD \DeltaT1\rho = ' sprintf('%.2f',sd1(k))];
htxt = {htxt1; htxt2; htxt3; htxt4};
%
h1 = subplot(2,1,1);
histogram(hdat1,binedg,'FaceAlpha',1,'FaceColor',[0 0 0.8]);
axlim = axis;
text(75,axlim(4)/2,htxt,'FontSize',11,'FontWeight','bold');
ylabel('Frequency','FontSize',12,'FontWeight','bold');
title({[fs ' Trial ' int2str(idxc)]; sltct; ...
'Superficial Layer'},'FontSize',16,'FontWeight','bold');
axlim1 = axis;
ht1 = text(-15,0.8*axlim1(4),htxt,'FontSize',11, ...
'FontWeight','bold');
%
hdat2 = [dT1rhonlss{1}(idv{1}&id2l{1},idxc); ...
dT1rhonlss{2}(idv{2}&id2l{2},idxc); ...
dT1rhonlss{3}(idv{3}&id2l{3},idxc)]; % All three slices
%
n2(k) = size(hdat2,1);
mn2(k) = mean(hdat2);
md2(k) = median(hdat2);
sd2(k) = std(hdat2);
%
htxt1 = ['N = ' int2str(n2(k))];
htxt2 = ['Mean \DeltaT1\rho = ' sprintf('%.2f',mn2(k))];
htxt3 = ['Median \DeltaT1\rho = ' sprintf('%.2f',md2(k))];
htxt4 = ['SD \DeltaT1\rho = ' sprintf('%.2f',sd2(k))];
htxt = {htxt1; htxt2; htxt3; htxt4};
%
h2 = subplot(2,1,2);
histogram(hdat2,binedg,'FaceAlpha',1,'FaceColor',[0 0 0.8]);
axlim = axis;
text(75,axlim(4)/2,htxt,'FontSize',11,'FontWeight','bold');
xlabel('T1rho Differences (ms)','FontSize',12, ...
'FontWeight','bold');
ylabel('Frequency','FontSize',12,'FontWeight','bold');
title('Deep Layer','FontSize',16,'FontWeight','bold');
axlim2 = axis;
ht2 = text(-15,0.8*axlim2(4),htxt,'FontSize',11, ...
'FontWeight','bold');
%
if axlim2(4)<axlim1(4)
set(h1,'YLimMode','manual');
axis(h2,axlim1);
ht2.Position(2) = 0.8*axlim1(4);
else
axis(h1,axlim2);
set(h2,'YLimMode','manual');
ht1.Position(2) = 0.8*axlim2(4);
end
%
if k==1
print('-dpsc2','-r600','-fillpage',hnam);
else
print('-dpsc2','-r600','-fillpage','-append',hnam);
end
%
end
%
% Find Best SD for Both Four and Five Spin Lock Times
%
[~,ids1] = sort(sd0(1:nsz(3)));
[~,ids2] = sort(sd0(nsz(3)+1:nc));
ids2 = ids2+nsz(3);
ids = [ids1; ids2];
%
% Get Variables in Sorted Order and Formatted for a Table
%
varnams = {'Trial #','Spin Lock Times','N SLTs','Layer','N','Mean', ...
'Median','SD'};
%
idx = idx(ids);
idx = [idx; idx; idx]; % Trials
idx = idx(:);
%
sltc = sltc(ids);
sltc = [sltc'; sltc'; sltc'];
sltc = sltc(:);
%
nslts = [repmat(4,3*nsz(3),1); repmat(5,3*nsz(4),1)];
%
layer = repmat((1:3)',nc,1);
lays = {'Superficial';'Deep';'Combined'};
lays2 = lays(layer);
%
n = [n1(ids)'; n2(ids)'; n0(ids)'];
n = n(:);
%
mn = [mn1(ids)'; mn2(ids)'; mn0(ids)'];
mn = mn(:);
%
md = [md1(ids)'; md2(ids)'; md0(ids)'];
md = md(:);
%
sd = [sd1(ids)'; sd2(ids)'; sd0(ids)'];
sd = sd(:);
%
% Generate a Table and Write Data to a MS-Excel Spreadsheet
%
tabs = table(idx,sltc,nslts,lays2,n,mn,md,sd,'VariableNames',varnams);
writetable(tabs,xnam);
%
return