Skip to content

Commit ae0ec6c

Browse files
committed
examples/python/Vision_files_preprocess.py: write uniform-1 image for initializing; add optional argument 'file_prefix'
1 parent b67c9f4 commit ae0ec6c

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

examples/python/Vision_files_preprocess.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464

6565

6666
def process_files(prompts_header_filename,
67+
file_prefix = '',
6768
mu_map_header = 'umap_00.h33', # the *.h33 header
6869
randoms_data_filename = 'smoothed_rand_00.s',
6970
scatter_2D_header_filename = 'scat_00_00.s.hdr',
@@ -98,31 +99,31 @@ def process_files(prompts_header_filename,
9899
# header-name for prompts as we don't want to overwrite the Siemens header
99100
prompts_header_to_read_withSTIR = prompts_header_filename[:-6] + '_readwSTIR.s.hdr'
100101
# STIR writes the (DOI-adapted) prompts out to a STIR-file:
101-
prompts_filename_STIR_corr_DOI = 'prompts.hs'
102+
prompts_filename_STIR_corr_DOI = file_prefix + 'prompts.hs'
102103
# STIR writes a non-TOF sinogram, name:
103104
nonTOF_template_sinogram_name = 'template_nonTOF.hs'
104105
# header-name for attenuation correction factors as we don't want to overwrite the Siemens header
105106
attenuation_corr_factor_header_to_read_withSTIR = attenuation_corr_factor_data_filename[:-2] + '_readwSTIR.s.hdr'
106107
# header-name for randoms as we don't want to overwrite the Siemens header
107108
norm_sino_to_read_withSTIR = norm_sino_data_filename[:-2] + '_readwSTIR.s.hdr'
108109
# STIR writes the DOI-adapted, negative corrected norm-sino to
109-
norm_filename_fSTIR = 'norm_sino_fSTIR.hs'
110+
norm_filename_fSTIR = file_prefix + 'norm_sino_fSTIR.hs'
110111
# STIR writes the DOI-adapted detection efficiencies to
111-
det_effs_filename_fSIRF = 'detection_efficiencies_forSIRF.hs'
112+
det_effs_filename_fSIRF = file_prefix + 'detection_efficiencies_forSIRF.hs'
112113
# header-name for randoms as we don't want to overwrite the Siemens header
113114
randoms_header_to_read_withSTIR = randoms_data_filename[:-2] + '_readwSTIR.s.hdr'
114115
# header-name for randoms as we don't want to overwrite the Siemens header
115116
scatter_2D_header_to_read_withSTIR = scatter_2D_header_filename[:-6] + '_readwSTIR.s.hdr'
116117
# STIR writes the (DOI-adapted) randoms to
117-
randoms_adapted_DOI_filename = randoms_data_filename[:-2] + '_fSTIR.hs'
118+
randoms_adapted_DOI_filename = file_prefix + randoms_data_filename[:-2] + '_fSTIR.hs'
118119
# STIR writes the (DOI-adapted), iSSRBd, unnormalized scatter to
119-
scatter_3D_unnorm_filename = 'scatter_3D_unnormalized.hs'
120+
scatter_3D_unnorm_filename = file_prefix + 'scatter_3D_unnormalized.hs'
120121
# STIR writes the additive term (that's normalized scatter + normalized randoms, attenuation corrected) to:
121-
additive_term_filename_fSTIR = 'additive_term.hs'
122+
additive_term_filename_fSTIR = file_prefix + 'additive_term.hs'
122123
# STIR writes the multiplicative term (that's norm_sino * attenuation_CORRECTION_factors) to:
123-
multi_term_filename_fSTIR = 'mult_factors_forSTIR.hs'
124+
multi_term_filename_fSTIR = file_prefix + 'mult_factors_forSTIR.hs'
124125
# STIR writes the multiplicative term for SIRF (that's detection_efficiency_sino * attenuation_factors) to:
125-
multi_term_filename_fSIRF = 'mult_factors_forSIRF.hs'
126+
multi_term_filename_fSIRF = file_prefix + 'mult_factors_forSIRF.hs'
126127

127128
#%%
128129
try:
@@ -182,13 +183,24 @@ def process_files(prompts_header_filename,
182183

183184
#### now let's read it from file and plot to see if it worked
184185
mu_map = stir.FloatVoxelsOnCartesianGrid.read_from_file(mu_map_header[:-3]+'hv')
186+
mu_map.write_to_file(os.path.join(STIR_output_folder, file_prefix + 'mu_map.hv'))
185187
mu_map_arr = stirextra.to_numpy(mu_map)
186188

187189
plt.figure()
188-
plot_2d_image([1,1,1],mu_map_arr[mu_map_arr.shape[0]//2,:,:],'mu-map')
189-
plt.savefig(os.path.join(STIR_output_folder,'mu_map.png'), transparent=False, facecolor='w')
190+
plot_2d_image([1,2,1],mu_map_arr[mu_map_arr.shape[0]//2,:,:],'mu-map', cmap='Greys_r')
191+
plot_2d_image([1,2,2],mu_map_arr[:,mu_map_arr.shape[1]//2,:],'mu-map', cmap='Greys_r')
192+
plt.savefig(os.path.join(STIR_output_folder, file_prefix + 'mu_map.png'), transparent=False, facecolor='w')
190193
plt.close()
191194

195+
#%%
196+
###################### UNI 1 image ############################
197+
## to get a uniform 1 image for initialising, use mu-map
198+
## This is important to match Siemens Image dimensions!!
199+
200+
uni1 = mu_map.get_empty_copy()
201+
uni1.fill(1)
202+
uni1.write_to_file(os.path.join(STIR_output_folder, file_prefix + 'uni1_img.hv'))
203+
192204

193205
# %%
194206
###################### NORMALIZATION ############################
@@ -609,6 +621,7 @@ def remove_tof_dimension(header_name_new, header_name):
609621
prog='Vision_files_preprocess.py',
610622
description='Converts e7tools sinogram files for the Vision into sinogram files that can be read by STIR')
611623
parser.add_argument('--prompts_filename_inclPath', required=True, help="The filename of the prompts file, including path")
624+
parser.add_argument('--file_prefix', default='', help="A prefix added to all output files")
612625
parser.add_argument('--mu_map_header', default='umap_00.h33', help="The filename of the mu-map header")
613626
parser.add_argument('--randoms_data_filename', default='smoothed_rand_00.s', help="The filename of the randoms data")
614627
parser.add_argument('--scatter_2D_header_filename', default='scat_00_00.s.hdr', help="The filename of the 2D scatter header")
@@ -619,9 +632,10 @@ def remove_tof_dimension(header_name_new, header_name):
619632
args = parser.parse_args()
620633

621634
process_files(args.prompts_filename_inclPath,
635+
file_prefix=args.file_prefix,
622636
mu_map_header=args.mu_map_header,
623637
randoms_data_filename=args.randoms_data_filename,
624638
scatter_2D_header_filename=args.scatter_2D_header_filename,
625639
norm_sino_data_filename=args.norm_sino_data_filename,
626640
attenuation_corr_factor_data_filename=args.attenuation_corr_factor_data_filename,
627-
STIR_output_folder=args.STIR_output_folder)
641+
STIR_output_folder=args.STIR_output_folder)

0 commit comments

Comments
 (0)