-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into Siemens_mMR_ACR2
- Loading branch information
Showing
14 changed files
with
171 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 51 additions & 60 deletions
111
SIRF_data_preparation/Siemens_mMR_NEMA_IQ/Siemens_mMR_NEMA_VOIs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,86 @@ | ||
#%% | ||
%load_ext autoreload | ||
#%% | ||
2 | ||
# #%% | ||
import numpy | ||
import matplotlib.pyplot as plt | ||
# %% | ||
# %load_ext autoreload | ||
# %% | ||
import os | ||
import sys | ||
import sirf.STIR as STIR | ||
from sirf.Utilities import examples_data_path | ||
from scipy.ndimage import binary_erosion | ||
from pathlib import Path | ||
#%% | ||
%autoreload 2 | ||
|
||
#%% | ||
from petric import get_data, SRCDIR | ||
import data_QC | ||
#%% | ||
#%matplotlib ipympl | ||
#%% | ||
import matplotlib.pyplot as plt | ||
import numpy | ||
from data_QC import VOI_mean, plot_image | ||
from scipy import ndimage | ||
from scipy.ndimage import binary_erosion | ||
|
||
import sirf.STIR as STIR | ||
from petric import SRCDIR | ||
from SIRF_data_preparation import data_QC | ||
|
||
# %% | ||
# %autoreload 2 | ||
|
||
# %% | ||
# %matplotlib ipympl | ||
# %% | ||
STIR.AcquisitionData.set_storage_scheme('memory') | ||
# set-up redirection of STIR messages to files | ||
#_ = STIR.MessageRedirector('BSREM_info.txt', 'BSREM_warnings.txt', 'BSREM_errors.txt') | ||
# _ = STIR.MessageRedirector('BSREM_info.txt', 'BSREM_warnings.txt', 'BSREM_errors.txt') | ||
# fewer messages from STIR and SIRF (set to higher value to diagnose have problems) | ||
STIR.set_verbosity(0) | ||
|
||
#%% read | ||
# %% read | ||
if not SRCDIR.is_dir(): | ||
PETRICDIR = Path('~/devel/PETRIC').expanduser() | ||
SRCDIR = PETRICDIR / 'data' | ||
datadir = str(SRCDIR /'Siemens_mMR_NEMA_IQ/') | ||
#%% | ||
datadir = str(SRCDIR / 'Siemens_mMR_NEMA_IQ/') | ||
# %% | ||
OSEM_image = STIR.ImageData(datadir + 'OSEM_image.hv') | ||
im_slice = 72 | ||
cor_slice = 109 | ||
sag_slice = OSEM_image.dimensions()[2]//2 | ||
sag_slice = OSEM_image.dimensions()[2] // 2 | ||
cmax = OSEM_image.max() | ||
#%% | ||
slices = {'transverse_slice':72, 'coronal_slice':109} | ||
#%% read in original VOIs | ||
orgVOIs=[] | ||
for i in range(1,8): | ||
orgVOIs.append(STIR.ImageData(datadir+f"S{i}.hv")) | ||
data_QC.plot_image(orgVOIs[i-1], **slices) | ||
#%% | ||
reference_image = STIR.ImageData(datadir+'PETRIC/reference_image.hv') | ||
# %% | ||
slices = {'transverse_slice': 72, 'coronal_slice': 109} | ||
# %% read in original VOIs | ||
orgVOIs = [] | ||
for i in range(1, 8): | ||
orgVOIs.append(STIR.ImageData(datadir + f"S{i}.hv")) | ||
data_QC.plot_image(orgVOIs[i - 1], **slices) | ||
# %% | ||
reference_image = STIR.ImageData(datadir + 'PETRIC/reference_image.hv') | ||
data_QC.plot_image(reference_image, **slices) | ||
#%% create PETRIC VOIs | ||
# %% create PETRIC VOIs | ||
whole_object_mask = reference_image.clone() | ||
whole_object_mask.fill(binary_erosion(reference_image.as_array()> reference_image.max()*.05, iterations=2)) | ||
whole_object_mask.fill(binary_erosion(reference_image.as_array() > reference_image.max() * .05, iterations=2)) | ||
data_QC.plot_image(whole_object_mask, **slices) | ||
#%% | ||
# %% | ||
background_mask = orgVOIs[6] | ||
VOI1_mask = orgVOIs[4] | ||
VOI2_mask = orgVOIs[2] | ||
VOI3_mask = orgVOIs[0] | ||
#%% write PETRIC VOIs | ||
whole_object_mask.write(datadir+'PETRIC/VOI_whole_object.hv') | ||
background_mask.write(datadir+'PETRIC/VOI_background.hv') | ||
VOI1_mask.write(datadir+'PETRIC/VOI_sphere5.hv') | ||
VOI2_mask.write(datadir+'PETRIC/VOI_sphere3.hv') | ||
VOI3_mask.write(datadir+'PETRIC/VOI_sphere1.hv') | ||
#%% | ||
# %% write PETRIC VOIs | ||
whole_object_mask.write(datadir + 'PETRIC/VOI_whole_object.hv') | ||
background_mask.write(datadir + 'PETRIC/VOI_background.hv') | ||
VOI1_mask.write(datadir + 'PETRIC/VOI_sphere5.hv') | ||
VOI2_mask.write(datadir + 'PETRIC/VOI_sphere3.hv') | ||
VOI3_mask.write(datadir + 'PETRIC/VOI_sphere1.hv') | ||
# %% | ||
VOIs = (whole_object_mask, background_mask, VOI1_mask, VOI2_mask, VOI3_mask) | ||
#%% | ||
[ data_QC.plot_image(VOI, **slices) for VOI in VOIs] | ||
#%% | ||
allVOIs = whole_object_mask.clone()*.2 | ||
# %% | ||
[data_QC.plot_image(VOI, **slices) for VOI in VOIs] | ||
# %% | ||
allVOIs = whole_object_mask.clone() * .2 | ||
allVOIs += background_mask | ||
for VOI in VOIs: | ||
allVOIs+= VOI | ||
allVOIs += VOI | ||
allVOIs /= allVOIs.max() | ||
#%% | ||
# %% | ||
plt.figure() | ||
data_QC.plot_image(reference_image, **slices) | ||
plt.figure() | ||
data_QC.plot_image(reference_image, **slices, alpha=allVOIs) | ||
#%% | ||
from data_QC import plot_image_if_exists, VOI_checks | ||
from data_QC import plot_image | ||
from data_QC import VOI_mean | ||
|
||
from scipy import ndimage | ||
|
||
#%% | ||
VOI_checks(['VOI_whole_object', 'VOI_sphere5'], OSEM_image, srcdir=os.path.join(datadir, 'PETRIC'), **slices) | ||
#%% | ||
[ data_QC.VOI_mean(OSEM_image, VOI) for VOI in VOIs] | ||
[ VOI_mean(OSEM_image, VOI) for VOI in VOIs] | ||
#%% | ||
[ data_QC.VOI_mean(reference_image, VOI) for VOI in VOIs] | ||
# %% | ||
data_QC.main(['--srcdir', datadir]) | ||
# %% | ||
[ VOI_mean(reference_image, VOI) for VOI in VOIs] |
Empty file.
Oops, something went wrong.