|
34 | 34 | "--img_shape", |
35 | 35 | type=int, |
36 | 36 | nargs=3, |
37 | | - default=[55, 55, 19], |
| 37 | + default=None, |
38 | 38 | help="Shape of the image to be reconstructed", |
39 | 39 | ) |
40 | 40 | parser.add_argument( |
|
77 | 77 | args = parser.parse_args() |
78 | 78 |
|
79 | 79 | fname = args.fname |
80 | | -img_shape = tuple(args.img_shape) |
| 80 | +img_shape: list[int] | None = args.img_shape |
81 | 81 | voxel_size = tuple(args.voxel_size) |
82 | 82 | fwhm_mm = args.fwhm_mm |
83 | 83 | store_energy_bins = args.store_energy_bins |
|
113 | 113 | print("Calculating all detector centers ...") |
114 | 114 | all_detector_centers = get_all_detector_centers(scanner_geom, ax=ax) |
115 | 115 |
|
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 | | -) |
122 | 116 |
|
123 | 117 | if not ax is None: |
124 | 118 | min_coords = all_detector_centers[0].reshape(-1, 3).min(0) |
|
139 | 133 | ) |
140 | 134 | fig.show() |
141 | 135 |
|
| 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 | + |
142 | 179 | # %% |
143 | 180 | ################################################################################ |
144 | 181 | ### CALCULATE THE SENSITIVTY IMAGE ############################################# |
|
257 | 294 |
|
258 | 295 | print("Starting parallelproj LM OSEM reconstruction ...") |
259 | 296 |
|
260 | | - |
261 | 297 | lm_subset_projs = [] |
262 | 298 | subset_slices = [slice(i, None, num_subsets) for i in range(num_subsets)] |
263 | 299 |
|
|
0 commit comments