Skip to content

Commit 96f687f

Browse files
committed
add auto estimation of image size (FOV)
1 parent 47967fe commit 96f687f

File tree

1 file changed

+45
-9
lines changed

1 file changed

+45
-9
lines changed

python/02_reconstruct_petsird.py

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"--img_shape",
3535
type=int,
3636
nargs=3,
37-
default=[55, 55, 19],
37+
default=None,
3838
help="Shape of the image to be reconstructed",
3939
)
4040
parser.add_argument(
@@ -77,7 +77,7 @@
7777
args = parser.parse_args()
7878

7979
fname = args.fname
80-
img_shape = tuple(args.img_shape)
80+
img_shape: list[int] | None = args.img_shape
8181
voxel_size = tuple(args.voxel_size)
8282
fwhm_mm = args.fwhm_mm
8383
store_energy_bins = args.store_energy_bins
@@ -113,12 +113,6 @@
113113
print("Calculating all detector centers ...")
114114
all_detector_centers = get_all_detector_centers(scanner_geom, ax=ax)
115115

116-
# calculate the scanner iso center to set the image origin that we need for the projectors
117-
scanner_iso_center = xp.asarray(all_detector_centers[0].reshape(-1, 3).mean(0))
118-
119-
img_origin = scanner_iso_center - 0.5 * (xp.asarray(img_shape) - 1) * xp.asarray(
120-
voxel_size
121-
)
122116

123117
if not ax is None:
124118
min_coords = all_detector_centers[0].reshape(-1, 3).min(0)
@@ -139,6 +133,49 @@
139133
)
140134
fig.show()
141135

136+
# %%
137+
################################################################################
138+
### DETERMINE IMAGE ORIGIN AND IMAGE SHAPE IF NOT GIVEN #######################
139+
################################################################################
140+
141+
142+
if img_shape is not None:
143+
img_shape = tuple(img_shape)
144+
else:
145+
# get the bounding box of the scanner detection elements
146+
scanner_bbox = all_detector_centers[0].reshape(-1, 3).max(0) - all_detector_centers[
147+
0
148+
].reshape(-1, 3).min(0)
149+
150+
i_ax = int(
151+
np.argmin(
152+
np.array(
153+
[
154+
np.abs(scanner_bbox[1] - scanner_bbox[2]),
155+
np.abs(scanner_bbox[0] - scanner_bbox[2]),
156+
np.abs(scanner_bbox[0] - scanner_bbox[1]),
157+
]
158+
)
159+
)
160+
)
161+
162+
img_shape = (0.53 * scanner_bbox / np.array(voxel_size)).astype(int)
163+
img_shape[i_ax] = int(scanner_bbox[i_ax] / voxel_size[i_ax])
164+
if img_shape[i_ax] % 2 == 0:
165+
img_shape[i_ax] += 1 # make sure the image shape is odd
166+
img_shape = tuple(img_shape.tolist())
167+
168+
# calculate the scanner iso center to set the image origin that we need for the projectors
169+
scanner_iso_center = xp.asarray(all_detector_centers[0].reshape(-1, 3).mean(0))
170+
img_origin = scanner_iso_center - 0.5 * (xp.asarray(img_shape) - 1) * xp.asarray(
171+
voxel_size
172+
)
173+
174+
if verbose:
175+
print(f"Image shape: {img_shape}")
176+
print(f"Image origin: {img_origin}")
177+
print(f"Voxel size: {voxel_size}")
178+
142179
# %%
143180
################################################################################
144181
### CALCULATE THE SENSITIVTY IMAGE #############################################
@@ -257,7 +294,6 @@
257294

258295
print("Starting parallelproj LM OSEM reconstruction ...")
259296

260-
261297
lm_subset_projs = []
262298
subset_slices = [slice(i, None, num_subsets) for i in range(num_subsets)]
263299

0 commit comments

Comments
 (0)