Skip to content

Commit cc75213

Browse files
authored
Add files via upload
1 parent b0e9208 commit cc75213

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

ct/leap_ct.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from leapctype import *
2+
import numpy as np
3+
import time
4+
from leaptorch import Projector
5+
import copy
6+
from tqdm import tqdm
7+
import math
8+
import torch
9+
10+
class leap_ct():
11+
def __init__(self, cam_infos, recon_args, use_device='cuda:0'):
12+
13+
self.use_device = use_device
14+
self.device = torch.device(use_device)
15+
self.projector = Projector(forward_project=True, use_static=True, use_gpu=True, gpu_device=self.device)
16+
# self.projector.leapct.set_projector('VD')
17+
18+
# set up the projection geometry
19+
numAngles = len(cam_infos)
20+
numRows = cam_infos[0].height
21+
numCols = cam_infos[0].width
22+
pixelHeight = cam_infos[0].sy
23+
pixelWidth = cam_infos[0].sx
24+
sod = cam_infos[0].sad
25+
sdd = cam_infos[0].sid
26+
centerRow = 0.5*(numRows-1)
27+
centerCol = 0.5*(numCols-1)
28+
29+
projs = []
30+
PrimaryAngles = []
31+
for cam in cam_infos:
32+
projs.append(cam.image.squeeze())
33+
PrimaryAngles.append(cam.PrimaryAngle)
34+
projs = np.stack(projs, axis=0)
35+
PrimaryAngles = np.stack(PrimaryAngles, axis=0)
36+
self.projs = np.ascontiguousarray(projs, dtype=np.float32)
37+
PrimaryAngles = np.rad2deg(PrimaryAngles)
38+
PrimaryAngles += 90.0 # align DSA imaging system with LEAP-toolbox convention
39+
self.PrimaryAngles = np.ascontiguousarray(PrimaryAngles, dtype=np.float32)
40+
41+
self.projector.leapct.set_conebeam(numAngles, numRows, numCols, pixelHeight, pixelWidth,
42+
centerRow, centerCol, self.PrimaryAngles, sod, sdd)
43+
44+
numX, numY, numZ = recon_args["volume_resolution"]
45+
voxelWidth, voxelHeight = recon_args["volume_spacing"][0], recon_args["volume_spacing"][-1]
46+
47+
self.projector.leapct.set_volume(numX, numY, numZ, voxelWidth, voxelHeight)
48+
49+
self.projector.allocate_batch_data() # necessary for torch version
50+
51+
def fdk(self, projs_, PrimaryAngles_, VERSE=False):
52+
if VERSE:
53+
print('Reconstruction with LEAP-toolbox fdk...')
54+
55+
startTime = time.time()
56+
57+
projs = copy.deepcopy(projs_) # do not let inner operation influence input
58+
projs = np.flip(projs, axis=1)
59+
g = np.ascontiguousarray(projs, dtype=np.float32) # shape is numAngles, numRows, numCols
60+
61+
PrimaryAngles = copy.deepcopy(PrimaryAngles_)
62+
self.projector.leapct.set_phis(PrimaryAngles)
63+
self.projector.allocate_batch_data()
64+
65+
f = self.projector.leapct.allocate_volume() # shape is numZ, numY, numX
66+
f[:] = 0.0 # initialize the volume to zero
67+
self.projector.leapct.FBP(g, f)
68+
69+
if VERSE:
70+
print('fdk Reconstruction Elapsed Time: ' + str(time.time()-startTime))
71+
72+
return f
73+
74+
75+

0 commit comments

Comments
 (0)