本文整理汇总了Python中msct_image.Image.save_quality_control方法的典型用法代码示例。如果您正苦于以下问题:Python Image.save_quality_control方法的具体用法?Python Image.save_quality_control怎么用?Python Image.save_quality_control使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msct_image.Image
的用法示例。
在下文中一共展示了Image.save_quality_control方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: segment
# 需要导入模块: from msct_image import Image [as 别名]
# 或者: from msct_image.Image import save_quality_control [as 别名]
def segment(self):
before = time.time()
sct.run('mkdir ' + self.tmp_dir)
self.segmentation_pipeline()
# Generate output files:
for res_fname in self.res_names.values():
sct.generate_output_file(self.tmp_dir+res_fname, self.seg_param.output_path+res_fname)
if self.ref_gm_seg_fname is not None:
sct.generate_output_file(self.tmp_dir+self.dice_name, self.seg_param.output_path+self.dice_name)
sct.generate_output_file(self.tmp_dir+self.hausdorff_name, self.seg_param.output_path+self.hausdorff_name)
if compute_ratio:
sct.generate_output_file(self.tmp_dir+self.ratio_name, self.seg_param.output_path+self.ratio_name)
after = time.time()
sct.printv('Done! (in ' + str(after-before) + ' sec) \nTo see the result, type :')
if self.seg_param.res_type == 'binary':
wm_col = 'Red'
gm_col = 'Blue'
b = '0,1'
else:
wm_col = 'Blue-Lightblue'
gm_col = 'Red-Yellow'
b = '0.3,1'
sct.printv('fslview ' + self.target_fname + ' '+self.seg_param.output_path+self.res_names['wm_seg']+' -l '+wm_col+' -t 0.4 -b '+b+' '+self.seg_param.output_path+self.res_names['gm_seg']+' -l '+gm_col+' -t 0.4 -b '+b+' &', self.seg_param.verbose, 'info')
if self.seg_param.qc:
# output QC image
im = Image(self.target_fname)
im_gmseg = Image(self.seg_param.output_path+self.res_names['gm_seg'])
im.save_quality_control(plane='axial', n_slices=5, seg=im_gmseg, thr=float(b.split(',')[0]), cmap_col='red-yellow', path_output=self.seg_param.output_path)
if self.seg_param.remove_tmp:
sct.printv('Remove temporary folder ...', self.seg_param.verbose, 'normal')
sct.run('rm -rf '+self.tmp_dir)
示例2: __init__
# 需要导入模块: from msct_image import Image [as 别名]
# 或者: from msct_image.Image import save_quality_control [as 别名]
def __init__(self, fname_src, fname_transfo, warp_atlas, warp_spinal_levels, folder_out, path_template, verbose, qc):
# Initialization
self.fname_src = fname_src
self.fname_transfo = fname_transfo
self.warp_atlas = warp_atlas
self.warp_spinal_levels = warp_spinal_levels
self.folder_out = folder_out
self.path_template = path_template
self.folder_template = param.folder_template
self.folder_atlas = param.folder_atlas
self.folder_spinal_levels = param.folder_spinal_levels
self.verbose = verbose
self.qc = qc
start_time = time.time()
# Check file existence
sct.printv('\nCheck file existence...', self.verbose)
sct.check_file_exist(self.fname_src)
sct.check_file_exist(self.fname_transfo)
# add slash at the end of folder name (in case there is no slash)
self.path_template = sct.slash_at_the_end(self.path_template, 1)
self.folder_out = sct.slash_at_the_end(self.folder_out, 1)
self.folder_template = sct.slash_at_the_end(self.folder_template, 1)
self.folder_atlas = sct.slash_at_the_end(self.folder_atlas, 1)
self.folder_spinal_levels = sct.slash_at_the_end(self.folder_spinal_levels, 1)
# print arguments
print '\nCheck parameters:'
print ' Destination image ........ '+self.fname_src
print ' Warping field ............ '+self.fname_transfo
print ' Path template ............ '+self.path_template
print ' Output folder ............ '+self.folder_out+'\n'
# Extract path, file and extension
path_src, file_src, ext_src = sct.extract_fname(self.fname_src)
# create output folder
if os.path.exists(self.folder_out):
sct.printv('WARNING: Output folder already exists. Deleting it...', self.verbose, 'warning')
sct.run('rm -rf '+self.folder_out)
sct.run('mkdir '+self.folder_out)
# Warp template objects
sct.printv('\nWarp template objects...', self.verbose)
warp_label(self.path_template, self.folder_template, param.file_info_label, self.fname_src, self.fname_transfo, self.folder_out)
# Warp atlas
if self.warp_atlas == 1:
sct.printv('\nWarp atlas of white matter tracts...', self.verbose)
warp_label(self.path_template, self.folder_atlas, param.file_info_label, self.fname_src, self.fname_transfo, self.folder_out)
# Warp spinal levels
if self.warp_spinal_levels == 1:
sct.printv('\nWarp spinal levels...', self.verbose)
warp_label(self.path_template, self.folder_spinal_levels, param.file_info_label, self.fname_src, self.fname_transfo, self.folder_out)
# to view results
sct.printv('\nDone! To view results, type:', self.verbose)
sct.printv('fslview '+self.fname_src+' '+self.folder_out+self.folder_template+'MNI-Poly-AMU_T2.nii.gz -b 0,4000 '+self.folder_out+self.folder_template+'MNI-Poly-AMU_level.nii.gz -l MGH-Cortical -t 0.5 '+self.folder_out+self.folder_template+'MNI-Poly-AMU_GM.nii.gz -l Red-Yellow -b 0.5,1 '+self.folder_out+self.folder_template+'MNI-Poly-AMU_WM.nii.gz -l Blue-Lightblue -b 0.5,1 &\n', self.verbose, 'info')
if self.qc:
from msct_image import Image
# output QC image
im = Image(self.fname_src)
im_wm = Image(self.folder_out+self.folder_template+'MNI-Poly-AMU_WM.nii.gz')
im.save_quality_control(plane='axial', n_slices=4, seg=im_wm, thr=0.5, cmap_col='blue-cyan', path_output=self.folder_out)
示例3: __init__
# 需要导入模块: from msct_image import Image [as 别名]
# 或者: from msct_image.Image import save_quality_control [as 别名]
def __init__(self, fname_src, fname_transfo, warp_atlas, warp_spinal_levels, folder_out, path_template, verbose, qc):
# Initialization
self.fname_src = fname_src
self.fname_transfo = fname_transfo
self.warp_atlas = warp_atlas
self.warp_spinal_levels = warp_spinal_levels
self.folder_out = folder_out
self.path_template = path_template
self.folder_template = param.folder_template
self.folder_atlas = param.folder_atlas
self.folder_spinal_levels = param.folder_spinal_levels
self.verbose = verbose
self.qc = qc
start_time = time.time()
# add slash at the end of folder name (in case there is no slash)
# self.path_template = sct.slash_at_the_end(self.path_template, 1)
# self.folder_out = sct.slash_at_the_end(self.folder_out, 1)
# self.folder_template = sct.slash_at_the_end(self.folder_template, 1)
# self.folder_atlas = sct.slash_at_the_end(self.folder_atlas, 1)
# self.folder_spinal_levels = sct.slash_at_the_end(self.folder_spinal_levels, 1)
# print arguments
print '\nCheck parameters:'
print ' Working directory ........ '+os.getcwd()
print ' Destination image ........ '+self.fname_src
print ' Warping field ............ '+self.fname_transfo
print ' Path template ............ '+self.path_template
print ' Output folder ............ '+self.folder_out+'\n'
# create output folder
if os.path.exists(self.folder_out):
sct.printv('WARNING: Output folder already exists. Deleting it...', self.verbose, 'warning')
sct.run('rm -rf '+self.folder_out)
sct.run('mkdir '+self.folder_out)
# Warp template objects
sct.printv('\nWARP TEMPLATE:', self.verbose)
warp_label(self.path_template, self.folder_template, param.file_info_label, self.fname_src, self.fname_transfo, self.folder_out)
# Warp atlas
if self.warp_atlas == 1:
sct.printv('\nWARP ATLAS OF WHITE MATTER TRACTS:', self.verbose)
warp_label(self.path_template, self.folder_atlas, param.file_info_label, self.fname_src, self.fname_transfo, self.folder_out)
# Warp spinal levels
if self.warp_spinal_levels == 1:
sct.printv('\nWARP SPINAL LEVELS:', self.verbose)
warp_label(self.path_template, self.folder_spinal_levels, param.file_info_label, self.fname_src, self.fname_transfo, self.folder_out)
# to view results
sct.printv('\nDone! To view results, type:', self.verbose)
sct.printv('fslview '+self.fname_src+' ' \
+ self.folder_out + self.folder_template + get_file_label(self.folder_out + self.folder_template, 'T2') + ' -b 0,4000 ' \
+ self.folder_out + self.folder_template + get_file_label(self.folder_out + self.folder_template, 'vertebral') + ' -l MGH-Cortical -t 0.5 ' \
+ self.folder_out + self.folder_template + get_file_label(self.folder_out + self.folder_template, 'gray matter') + ' -l Red-Yellow -b 0.5,1 ' \
+ self.folder_out + self.folder_template + get_file_label(self.folder_out + self.folder_template, 'white matter') + ' -l Blue-Lightblue -b 0.5,1 &\n', self.verbose, 'info')
if self.qc:
from msct_image import Image
# output QC image
im = Image(self.fname_src)
im_wm = Image(self.folder_out + self.folder_template + get_file_label(self.folder_out + self.folder_template, 'white matter'))
im.save_quality_control(plane='axial', n_slices=4, seg=im_wm, thr=0.5, cmap_col='blue-cyan', path_output=self.folder_out)
示例4: segment
# 需要导入模块: from msct_image import Image [as 别名]
# 或者: from msct_image.Image import save_quality_control [as 别名]
def segment(self):
self.copy_data_to_tmp()
# go to tmp directory
os.chdir(self.tmp_dir)
# load model
self.model.load_model()
self.target_im, self.info_preprocessing = pre_processing(self.param_seg.fname_im, self.param_seg.fname_seg, self.param_seg.fname_level, new_res=self.param_data.axial_res, square_size_size_mm=self.param_data.square_size_size_mm, denoising=self.param_data.denoising, verbose=self.param.verbose, rm_tmp=self.param.rm_tmp)
printv('\nRegister target image to model data...', self.param.verbose, 'normal')
# register target image to model dictionary space
path_warp = self.register_target()
printv('\nNormalize intensity of target image...', self.param.verbose, 'normal')
self.normalize_target()
printv('\nProject target image into the model reduced space...', self.param.verbose, 'normal')
self.project_target()
printv('\nCompute similarities between target slices and model slices using model reduced space...', self.param.verbose, 'normal')
list_dic_indexes_by_slice = self.compute_similarities()
printv('\nLabel fusion of model slices most similar to target slices...', self.param.verbose, 'normal')
self.label_fusion(list_dic_indexes_by_slice)
printv('\nWarp back segmentation into image space...', self.param.verbose, 'normal')
self.warp_back_seg(path_warp)
printv('\nPost-processing...', self.param.verbose, 'normal')
self.im_res_gmseg, self.im_res_wmseg = self.post_processing()
if (self.param_seg.path_results != './') and (not os.path.exists('../'+self.param_seg.path_results)):
# create output folder
printv('\nCreate output folder ...', self.param.verbose, 'normal')
os.chdir('..')
os.mkdir(self.param_seg.path_results)
os.chdir(self.tmp_dir)
if self.param_seg.fname_manual_gmseg is not None:
# compute validation metrics
printv('\nCompute validation metrics...', self.param.verbose, 'normal')
self.validation()
if self.param_seg.ratio is not '0':
printv('\nCompute GM/WM CSA ratio...', self.param.verbose, 'normal')
self.compute_ratio()
# go back to original directory
os.chdir('..')
printv('\nSave resulting GM and WM segmentations...', self.param.verbose, 'normal')
fname_res_gmseg = self.param_seg.path_results+add_suffix(''.join(extract_fname(self.param_seg.fname_im)[1:]), '_gmseg')
fname_res_wmseg = self.param_seg.path_results+add_suffix(''.join(extract_fname(self.param_seg.fname_im)[1:]), '_wmseg')
self.im_res_gmseg.setFileName(fname_res_gmseg)
self.im_res_wmseg.setFileName(fname_res_wmseg)
self.im_res_gmseg.save()
self.im_res_wmseg.save()
# save quality control and print info
if self.param_seg.type_seg == 'bin':
wm_col = 'Red'
gm_col = 'Blue'
b = '0,1'
else:
wm_col = 'Blue-Lightblue'
gm_col = 'Red-Yellow'
b = '0.4,1'
if self.param_seg.qc:
# output QC image
printv('\nSave quality control images...', self.param.verbose, 'normal')
im = Image(self.tmp_dir+self.param_seg.fname_im)
im.save_quality_control(plane='axial', n_slices=5, seg=self.im_res_gmseg, thr=float(b.split(',')[0]), cmap_col='red-yellow', path_output=self.param_seg.path_results)
printv('\nDone! To view results, type:', self.param.verbose)
printv('fslview '+self.param_seg.fname_im_original+' '+fname_res_gmseg+' -b '+b+' -l '+gm_col+' -t 0.7 '+fname_res_wmseg+' -b '+b+' -l '+wm_col+' -t 0.7 & \n', self.param.verbose, 'info')
if self.param.rm_tmp:
# remove tmp_dir
shutil.rmtree(self.tmp_dir)