forked from CRossSchmidtlein/PETSTEP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosemSimData.m
157 lines (142 loc) · 5.89 KB
/
osemSimData.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
function OS = osemSimData(nFWPTtotal,RS,CTAC,initPT, ...
wcc,vox,iterNUM,subNUM)
%"mlemSimData"
% Reconstructs PET-like images via OS-MLEM
%
% CRS, 09/18/2013
%
%Usage:
% [ML] = mlemSimData(nFWPTtotal,RS,CTAC,POST,wcc,radBin,tanBin,simSize,zSlice,iterNUM,reconType)
% nFWPTtotal = Projection data
% RS = scatter + random projection reference data
% CTAC = CT attenuation correction data
% POST = FWHM of post filter
% wcc = "Well-counter correction"
% radBin = radial bins
% tanBin = projection bins
% simSize = Final image size
% zSlice = number of slices
% iterNUM = number of iterations
% subNUM = number of subsets
%
% Copyright 2010, Joseph O. Deasy, on behalf of the CERR development team.
%
% This file is part of The Computational Environment for Radiotherapy Research (CERR).
%
% CERR development has been led by: Aditya Apte, Divya Khullar, James Alaly, and Joseph O. Deasy.
%
% CERR has been financially supported by the US National Institutes of Health under multiple grants.
%
% CERR is distributed under the terms of the Lesser GNU Public License.
%
% This version of CERR is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% CERR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
% without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% See the GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with CERR. If not, see <http://www.gnu.org/licenses/>.%
%
%% Reconstructs ML images
supportCoeff = 0.99;
% resize images to odd dimensions
OddMat = true;
if (mod(vox.petOut.nxn(1),2) == 0)
vox.petOut.nxn(1:2) = vox.petOut.nxn(1:2) + 1;
vox.petOut.rtz(1) = 2*ceil(norm( vox.petOut.nxn(1:2) - floor(( vox.petOut.nxn(1:2)-1 )/2)-1)) + 3;
initPTup = initPT;
initPT = zeros(vox.petOut.nxn);
for i = 1:vox.petOut.nxn(3)
initPT(:,:,i) = imresize(initPTup(:,:,i),[vox.petOut.nxn(1:2)]);
end
OddMat = false;
end
nn = (vox.petOut.nxn(1)-1)/2;
x2 = linspace(-nn,nn,vox.petOut.nxn(1)).^2;
disk = x2(ones(vox.petOut.nxn(1),1),:) + x2(ones(1,vox.petOut.nxn(1)),:)' <= (vox.petOut.nxn(1)/2)^2;
% extraineous projection padding for corners
radPadA = floor((vox.petOut.rtz(1) - vox.petOut.nxn(1))/2) + 1;
radPadB = radPadA + vox.petOut.nxn(1) - 1;
radRefPadA = floor((vox.petSim.rtz(1) - vox.petSim.nxn(1))/2) + 1;
radRefPadB = radRefPadA + vox.petSim.nxn(1) - 1;
% Build subset angles
subTanBin = vox.petOut.rtz(2)/subNUM;
if (mod(subTanBin,1) ~= 0)
fprintf('ERROR: projection angles not divisible by subsets\n');
fprintf('\tProjections = %3d, \tSubsets = %2d, \t Number of angle bins = %3.2f\n', ...
vox.petOut.rtz(2),subNum,subTanBin);
return;
end
PHIref = 0:180/vox.petOut.rtz(2):180*(1-1/vox.petOut.rtz(2));
PHI = zeros([subTanBin subNUM]);
PHIbins = zeros([subTanBin subNUM]);
phiVec = randperm(subNUM) - 1;
for i = 1:subNUM
j = phiVec(i);
PHI(:,i) = j*180/vox.petOut.rtz(2) : subNUM*180/vox.petOut.rtz(2) : ...
180*(1-(subNUM-j)/vox.petOut.rtz(2));
PHIbins(:,i) = j+1 : subNUM : vox.petOut.rtz(2)-subNUM+j+1;
end
% Build data/additive noise/normalization subsets
nFW = zeros([vox.petSim.rtz(1) subTanBin subNUM vox.petSim.rtz(3)]);
rs = zeros([vox.petSim.rtz(1) subTanBin subNUM vox.petSim.rtz(3)]);
subFWAC = zeros([vox.petSim.rtz(1) subTanBin subNUM vox.petSim.rtz(3)]);
% CTsupport = zeros([vox.petSim.rtz(1) subTanBin subNUM vox.petSim.rtz(3)]);
subH1 = zeros([vox.petOut.nxn(1:2) subNUM vox.petOut.nxn(3)]);
for i = 1:vox.petSim.rtz(3)
for j = 1:subNUM
nFW(:,:,j,i) = nFWPTtotal(:,PHIbins(:,j),i);
rs(:,:,j,i) = RS(:,PHIbins(:,j),i);
subFWAC(:,:,j,i) = CTAC(:,PHIbins(:,j),i);
CTACtmp = imresize(subFWAC(:,:,j,i),[vox.petOut.rtz(1) subTanBin],'bilinear');
CTACtmp(CTACtmp < 0) = 0;
CTsuptmp = CTACtmp;
CTsuptmp(CTsuptmp >= supportCoeff) = 0; CTsuptmp(CTsuptmp > 0) = 1;
CTsupport(:,:,j,i) = CTsuptmp;
subH1(:,:,j,i) = disk.*iradon(CTACtmp,PHI(:,j),'linear','none',vox.petOut.nxn(1));
end
end
subH1(subH1 < 1E-12) = 1;
clear CTAC nFWPTtotal RS
if (OddMat)
OS = zeros([vox.petOut.nxn iterNUM]);
else
OS = zeros([vox.petOut.nxn(1:2)-1 vox.petOut.nxn(3) iterNUM]);
end
hf = zeros(vox.petSim.rtz(1),subTanBin);
gfRatio = zeros(vox.petOut.rtz(1),subTanBin);
for i = 1:vox.petOut.rtz(3)
tic
f = initPT(:,:,i)*wcc*subNUM;
for j = 1:iterNUM
for k = 1:subNUM
% Resizes image data to match projection size to perserve
% Poisson characteristict
hfTmp = radon(f/subNUM,PHI(:,k));
hf(radRefPadA:radRefPadB,:) = ...
imresize(hfTmp(radPadA:radPadB,:),[vox.petSim.nxn(1) subTanBin],'bilinear') + ...
rs(radRefPadA:radRefPadB,:,k,i)./subFWAC(radRefPadA:radRefPadB,:,k,i);
% Resizes projection data to match image size
gfRatio(radPadA:radPadB,:) = ...
imresize(nFW(radRefPadA:radRefPadB,:,k,i)./hf(radRefPadA:radRefPadB,:), ...
[vox.petOut.nxn(1) subTanBin],'bilinear');
gfRatio = gfRatio.*CTsupport(:,:,k,i);
hTg = iradon(gfRatio,PHI(:,k),'linear','none',vox.petOut.nxn(1));
f = disk.*f.*hTg./subH1(:,:,k,i);
f(f < 0) = 0;
f(isnan(f)) = 0;
f(isinf(f)) = 0;
end
if (OddMat)
OS(:,:,i,j) = disk.*f/wcc/subNUM;
else
OS(:,:,i,j) = imresize(disk.*f/wcc/subNUM,size(f)-1);
end
end
toc
end
end