Skip to content

Commit

Permalink
data_QC: centre VOI images and add COM to plots
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisThielemans committed Jul 13, 2024
1 parent e21ff31 commit 2a741e9
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions SIRF_data_preparation/data_QC.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@ def plot_image(image, save_name=None,
alpha_cor = alpha_arr[:, coronal_slice, :]
alpha_sag = alpha_arr[:, :, sagittal_slice]

plt.subplot(131)
ax = plt.subplot(131)
plt.imshow(arr[transverse_slice, :, :], vmin=vmin, vmax=vmax, alpha=alpha_trans, **kwargs)
plt.subplot(132)
ax.set_title(f"T={transverse_slice}")
ax = plt.subplot(132)
plt.imshow(arr[:, coronal_slice, :], vmin=vmin, vmax=vmax, alpha=alpha_cor, **kwargs)
plt.subplot(133)
ax.set_title(f"C={coronal_slice}")
ax = plt.subplot(133)
plt.imshow(arr[:, :, sagittal_slice], vmin=vmin, vmax=vmax, alpha=alpha_sag, **kwargs)
ax.set_title(f"S={sagittal_slice}")
plt.colorbar(shrink=.6)
if save_name is not None:
plt.savefig(save_name + '_slices.png')
Expand All @@ -101,6 +104,8 @@ def VOI_mean(image, VOI):
return float((image * VOI).sum() / VOI.sum())


from scipy import ndimage

def VOI_checks(allVOInames, OSEM_image=None, reference_image=None, srcdir='.', **kwargs):
if len(allVOInames) == 0:
return
Expand All @@ -111,10 +116,18 @@ def VOI_checks(allVOInames, OSEM_image=None, reference_image=None, srcdir='.', *
VOIkwargs['vmax'] = 1
VOIkwargs['vmin'] = 0
for VOIname in allVOInames:
VOI = plot_image_if_exists(os.path.join(srcdir, VOIname), **VOIkwargs)
if VOI is None:
filename = os.path.join(srcdir, VOIname + '.hv')
if not os.path.isfile(filename):
print(f"VOI {VOIname} does not exist")
continue
VOI = STIR.ImageData(filename)
COM = np.rint(ndimage.center_of_mass(VOI.as_array()))
plt.figure()
plot_image(VOI, save_name=VOIname, vmin=0, vmax=1,
transverse_slice = int(COM[0]),
coronal_slice = int(COM[1]),
sagittal_slice = int(COM[2]))

# construct transparency image
if VOIname == 'VOI_whole_object':
VOI /= 2
Expand All @@ -130,9 +143,7 @@ def VOI_checks(allVOInames, OSEM_image=None, reference_image=None, srcdir='.', *

if OSEM_image is not None:
plt.figure()
plot_image(OSEM_image, **kwargs)
plt.figure()
plot_image(OSEM_image, alpha=allVOIs, **kwargs)
plot_image(OSEM_image, alpha=allVOIs, save_name="OSEM_image and VOIs", **kwargs)

# unformatted print of VOI values for now
print(allVOInames)
Expand Down

0 comments on commit 2a741e9

Please sign in to comment.