Skip to content

Commit 84df350

Browse files
committed
DOC: Add full Python example
Add a new Python example that illustrate the full reconstruction workflow, from the GATE simulation until the final FDK reconstruction.
1 parent a44b861 commit 84df350

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

documentation/docs/getting_started.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ The resulting image can be visualized by any MHD image viewer, such as [vv](http
136136

137137
Note that to keep the running times in this guide fast enough, not enough statistics are generated to yield a nice output image. This is just an illustration of the PCT reconstruction workflow.
138138

139+
PCT also provides Python functions that behave exactly like the applications described above. For illustration, the exact same simulation than the one described in this page is reimplemented in Python in the file [`examples/Reconstruction/Reconstruction.py`](https://github.com/RTKConsortium/PCT/tree/main/examples/Reconstruction/Reconstruction.py).
140+
139141
## Conclusion
140142

141143
This guide gives an overview of a complete workflow that uses GATE to generate proton CT data, and PCT to process the data all the way to image reconstruction. To further familiarize yourself with PCT, you can explore the other applications offered by PCT, customize the current workflow with additional parameters using the `--help` flag, or implement your own simulation in GATE and try to produce a reconstruction.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
import itk
5+
from itk import PCT as pct
6+
from itk import RTK as rtk
7+
from opengate.contrib.protonct.protonct import protonct
8+
9+
output_folder = "/tmp/output"
10+
number_of_projections = 720
11+
12+
# # Generate some data
13+
gate_folder = os.path.join(output_folder, "gate")
14+
protonct(gate_folder, projections=number_of_projections, verbose=False)
15+
16+
# TODO example on how to make data noisy
17+
18+
# Convert GATE data to PCT list-mode
19+
pairs_folder = os.path.join(output_folder, "pairs")
20+
os.makedirs(pairs_folder, exist_ok=True)
21+
pct.pctpairprotons(
22+
input_in=os.path.join(gate_folder, "PhaseSpaceIn.root"),
23+
input_out=os.path.join(gate_folder, "PhaseSpaceOut.root"),
24+
output=os.path.join(pairs_folder, "pairs.mhd"),
25+
psin="PhaseSpaceIn",
26+
psout="PhaseSpaceOut",
27+
plane_in=-110.0,
28+
plane_out=110.0,
29+
verbose=True,
30+
)
31+
32+
# TODO cut the pairs (pctpaircuts is not converted to Python yet)
33+
34+
# Bin the pairs into projections
35+
projections_folder = os.path.join(output_folder, "projections")
36+
os.makedirs(projections_folder, exist_ok=True)
37+
for p in range(number_of_projections):
38+
pct.pctbinning(
39+
input=os.path.join(pairs_folder, f"pairs{p:04d}.mhd"),
40+
output=os.path.join(projections_folder, f"projections{p}.mhd"),
41+
source=-1000.0,
42+
size=[200, 1, 200],
43+
spacing=[2.0, 1.0, 1.0],
44+
verbose=True,
45+
)
46+
47+
# Build geometry
48+
geometry = os.path.join(output_folder, "geometry.xml")
49+
rtk.rtksimulatedgeometry(
50+
nproj=number_of_projections, output=geometry, sdd=1000.0 + 110.0, sid=1000.0
51+
)
52+
53+
# Reconstruct
54+
pct.pctfdk(
55+
geometry=geometry,
56+
path=projections_folder,
57+
regexp=r"projections.*\.mhd",
58+
output=os.path.join(output_folder, "recon.mhd"),
59+
size=[210, 1, 210],
60+
verbose=True,
61+
)

0 commit comments

Comments
 (0)