-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyBackprojection
37 lines (25 loc) · 1.08 KB
/
myBackprojection
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
function BPI = myBackprojection(sinogram,thetas)
% figure out how big our picture is going to be.
numOfParallelProjections = size(sinogram,1);
numOfAngularProjections = length(thetas);
% convert thetas to radians
thetas = (pi/180)*thetas;
% set up the backprojected image
BPI = zeros(numOfParallelProjections,numOfParallelProjections);
% find the middle index of the projections
midindex = floor(numOfParallelProjections/2) + 1;
% set up the coords of the image
[xCoords,yCoords] = meshgrid(ceil(-numOfParallelProjections/2):ceil(numOfParallelProjections/2-1));
% loop over each projection
for i = 1:numOfAngularProjections
% figure out which projections to add to which spots
rotCoords = round(midindex + xCoords*sin(thetas(i)) + yCoords*cos(thetas(i)));
% check which coords are in bounds
indices = find((rotCoords > 0) & (rotCoords <= numOfParallelProjections));
newCoords = rotCoords(indices);
% summation
BPI(indices) = BPI(indices) + sinogram(newCoords,i)./numOfAngularProjections;
% visualization on the fly
imagesc(BPI)
drawnow
end