diff --git a/SIRF_data_preparation/Siemens_mMR_ACR/VOI_prep.py b/SIRF_data_preparation/Siemens_mMR_ACR/VOI_prep.py index a712b27..e7b7bfe 100644 --- a/SIRF_data_preparation/Siemens_mMR_ACR/VOI_prep.py +++ b/SIRF_data_preparation/Siemens_mMR_ACR/VOI_prep.py @@ -1,17 +1,16 @@ -#%% file to prepare VOIs from the original ACR NEMA VOIs supplied by Pawel Markiewicz -#%% -import numpy as np -import matplotlib.pyplot as plt +# %% file to prepare VOIs from the original ACR NEMA VOIs supplied by Pawel Markiewicz +# %% import os -import sys + +import matplotlib.pyplot as plt +import numpy as np + import sirf.STIR as STIR -from sirf.Utilities import examples_data_path -from scipy.ndimage import binary_erosion -from pathlib import Path +import SIRF_data_preparation.data_QC as data_QC from SIRF_data_preparation.data_utilities import the_data_path, the_orgdata_path from SIRF_data_preparation.dataset_settings import get_settings -import SIRF_data_preparation.data_QC as data_QC -#%% + +# %% scanID = 'Siemens_mMR_ACR' org_VOI_path = the_orgdata_path(scanID, 'output', 'sampling_masks') data_path = the_data_path(scanID) @@ -19,73 +18,78 @@ os.makedirs(output_path, exist_ok=True) settings = get_settings(scanID) slices = settings.slices -#%% +# %% OSEM_image = STIR.ImageData(os.path.join(data_path, 'OSEM_image.hv')) cmax = OSEM_image.max() -#%% read in original VOIs +# %% read in original VOIs orgVOIs = STIR.ImageData(os.path.join(org_VOI_path, 'acr-all-sampling-0-2mm_dipy.nii')) data_QC.plot_image(orgVOIs, **slices) -#%% +# %% orgVOIs_arr = orgVOIs.as_array() print(np.unique(orgVOIs_arr)) -#%% output + + +# %% output # [ 0, 10-29, 40-81, 90- 101, 300- 317] -#%% +# %% def plotMask(mask): plt.figure() plt.subplot(141) - plt.imshow(mask[:,109,:]) + plt.imshow(mask[:, 109, :]) plt.subplot(142) - plt.imshow(mask[85,:,:]) + plt.imshow(mask[85, :, :]) plt.subplot(143) - plt.imshow(mask[99,:,:]) + plt.imshow(mask[99, :, :]) plt.subplot(144) - plt.imshow(mask[40,:,:]) -#%% background mask: slices in uniform part (idx 300-317), taking slightly eroded mask -mask = (orgVOIs_arr>=300) * (orgVOIs_arr<316) + plt.imshow(mask[40, :, :]) + + +# %% background mask: slices in uniform part (idx 300-317), taking slightly eroded mask +mask = (orgVOIs_arr >= 300) * (orgVOIs_arr < 316) plotMask(mask) -#%% +# %% background_mask = OSEM_image.clone() background_mask.fill(mask) -#%% 6 cylinder masks -mask = (orgVOIs_arr>=10) * (orgVOIs_arr<101) +# %% 6 cylinder masks +mask = (orgVOIs_arr >= 10) * (orgVOIs_arr < 101) plotMask(mask) -#%% cold cylinder mask -mask = (orgVOIs_arr>=90) * (orgVOIs_arr<100) +# %% cold cylinder mask +mask = (orgVOIs_arr >= 90) * (orgVOIs_arr < 100) plotMask(mask) cold_cyl_mask = OSEM_image.clone() cold_cyl_mask.fill(mask) -#%% faint hot cylinder mask -mask = (orgVOIs_arr>=20) * (orgVOIs_arr<29) +# %% faint hot cylinder mask +mask = (orgVOIs_arr >= 20) * (orgVOIs_arr < 29) plotMask(mask) hot_cyl_mask = OSEM_image.clone() hot_cyl_mask.fill(mask) -#%% Jasczcak part, not available so derive from "background mask" -mask = (orgVOIs_arr>=300) * (orgVOIs_arr<316) +# %% Jasczcak part, not available so derive from "background mask" +mask = (orgVOIs_arr >= 300) * (orgVOIs_arr < 316) # get single cylinder from a slice in the background -oneslice = mask[85,:,:].copy() -mask[35:45,:,:] = oneslice[:,:] -mask[46:127,:,:] = False +oneslice = mask[85, :, :].copy() +mask[35:45, :, :] = oneslice[:, :] +mask[46:127, :, :] = False plotMask(mask) rods_mask = OSEM_image.clone() rods_mask.fill(mask) -#%% whole phantom -mask = OSEM_image.as_array() > cmax/20 +# %% whole phantom +mask = OSEM_image.as_array() > cmax / 20 plotMask(mask) whole_object_mask = OSEM_image.clone() whole_object_mask.fill(mask) -#%% +# %% plotMask(OSEM_image.as_array()) -#%% write PETRIC VOIs +# %% write PETRIC VOIs whole_object_mask.write(os.path.join(output_path, 'VOI_whole_object.hv')) background_mask.write(os.path.join(output_path, 'VOI_background.hv')) cold_cyl_mask.write(os.path.join(output_path, 'VOI_cold_cylinder.hv')) hot_cyl_mask.write(os.path.join(output_path, 'VOI_hot_cylinder.hv')) rods_mask.write(os.path.join(output_path, 'VOI_rods.hv')) -#%% +# %% VOIs = (whole_object_mask, background_mask, cold_cyl_mask, hot_cyl_mask, rods_mask) -#%% -[ data_QC.plot_image(VOI, **slices) for VOI in VOIs] -#%% -data_QC.VOI_checks(['VOI_whole_object', 'VOI_background', 'VOI_cold_cylinder', 'VOI_hot_cylinder', 'VOI_rods'], OSEM_image, srcdir=output_path, **slices) +# %% +[data_QC.plot_image(VOI, **slices) for VOI in VOIs] +# %% +data_QC.VOI_checks(['VOI_whole_object', 'VOI_background', 'VOI_cold_cylinder', 'VOI_hot_cylinder', 'VOI_rods'], + OSEM_image, srcdir=output_path, **slices) diff --git a/SIRF_data_preparation/Siemens_mMR_ACR/download.py b/SIRF_data_preparation/Siemens_mMR_ACR/download.py index d073039..2d74ea6 100644 --- a/SIRF_data_preparation/Siemens_mMR_ACR/download.py +++ b/SIRF_data_preparation/Siemens_mMR_ACR/download.py @@ -6,9 +6,10 @@ from zenodo_get import zenodo_get +from sirf.Utilities import examples_data_path + # %% from SIRF_data_preparation.data_utilities import the_data_path -from sirf.Utilities import examples_data_path sirf_data_path = os.path.join(examples_data_path('PET'), 'mMR') diff --git a/SIRF_data_preparation/Siemens_mMR_ACR/register_mumap.py b/SIRF_data_preparation/Siemens_mMR_ACR/register_mumap.py index 8735d9d..e748a30 100644 --- a/SIRF_data_preparation/Siemens_mMR_ACR/register_mumap.py +++ b/SIRF_data_preparation/Siemens_mMR_ACR/register_mumap.py @@ -2,7 +2,8 @@ import sirf.Reg as Reg import sirf.STIR as STIR -from SIRF_data_preparation.data_utilities import the_data_path, the_orgdata_path +from SIRF_data_preparation.data_utilities import the_orgdata_path + # %% set paths filenames scanID = 'Siemens_mMR_ACR' intermediate_data_path = the_orgdata_path(scanID, 'processing') diff --git a/SIRF_data_preparation/Siemens_mMR_NEMA_IQ/Siemens_mMR_NEMA_VOIs.py b/SIRF_data_preparation/Siemens_mMR_NEMA_IQ/Siemens_mMR_NEMA_VOIs.py index 0976d4e..a3cf1b8 100644 --- a/SIRF_data_preparation/Siemens_mMR_NEMA_IQ/Siemens_mMR_NEMA_VOIs.py +++ b/SIRF_data_preparation/Siemens_mMR_NEMA_IQ/Siemens_mMR_NEMA_VOIs.py @@ -5,9 +5,7 @@ from pathlib import Path import matplotlib.pyplot as plt -import numpy -from data_QC import VOI_mean, plot_image -from scipy import ndimage +from data_QC import VOI_mean from scipy.ndimage import binary_erosion import sirf.STIR as STIR @@ -78,9 +76,9 @@ plt.figure() data_QC.plot_image(reference_image, **slices, alpha=allVOIs) -#%% -VOI_checks(['VOI_whole_object', 'VOI_sphere5'], OSEM_image, srcdir=os.path.join(datadir, 'PETRIC'), **slices) -#%% -[ VOI_mean(OSEM_image, VOI) for VOI in VOIs] -#%% -[ VOI_mean(reference_image, VOI) for VOI in VOIs] \ No newline at end of file +# %% +data_QC.VOI_checks(['VOI_whole_object', 'VOI_sphere5'], OSEM_image, srcdir=os.path.join(datadir, 'PETRIC'), **slices) +# %% +[VOI_mean(OSEM_image, VOI) for VOI in VOIs] +# %% +[VOI_mean(reference_image, VOI) for VOI in VOIs] diff --git a/SIRF_data_preparation/create_initial_images.py b/SIRF_data_preparation/create_initial_images.py index aac29c0..e1d7522 100644 --- a/SIRF_data_preparation/create_initial_images.py +++ b/SIRF_data_preparation/create_initial_images.py @@ -7,7 +7,8 @@ path to data files Options: - -t , --template_image= filename (relative to ) of image to use for data sizes [default: PETRIC/VOI_whole_phantom.hv] + -t , --template_image= filename (relative to ) of image to use + for data sizes [default: PETRIC/VOI_whole_phantom.hv] -s , --xy-size= force xy-size (do not use when using VOIs as init) [default: -1] -S , --subsets= number of subsets [default: 2] -i , --subiterations= number of sub-iterations [default: 14] diff --git a/SIRF_data_preparation/data_utilities.py b/SIRF_data_preparation/data_utilities.py index 817c6b1..e7d04db 100644 --- a/SIRF_data_preparation/data_utilities.py +++ b/SIRF_data_preparation/data_utilities.py @@ -29,6 +29,7 @@ def the_data_path(*folders): ''' return os.path.join(DATA_PATH, *folders) + def the_orgdata_path(*folders): ''' Returns the path to original data (for downloads/processing) @@ -37,6 +38,7 @@ def the_orgdata_path(*folders): ''' return os.path.join(ORG_DATA_PATH, *folders) + def fix_siemens_norm_EOL(in_filename, out_filename): with open(in_filename, mode="rb") as f: data = bytearray(f.read()) diff --git a/SIRF_data_preparation/dataset_settings.py b/SIRF_data_preparation/dataset_settings.py index 1d0e04e..0891e24 100644 --- a/SIRF_data_preparation/dataset_settings.py +++ b/SIRF_data_preparation/dataset_settings.py @@ -14,7 +14,7 @@ def get_settings(scanID: str): slices = {'transverse_slice': 72, 'coronal_slice': 109} # , 'sagittal_slice': 89} num_subsets = 7 elif scanID == 'Siemens_mMR_ACR': - slices = { 'transverse_slice': 99} + slices = {'transverse_slice': 99} num_subsets = 7 elif scanID == 'NeuroLF_Hoffman_Dataset': slices = {'transverse_slice': 72}