本文整理汇总了Python中SimpleITK.ImageSeriesReader方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleITK.ImageSeriesReader方法的具体用法?Python SimpleITK.ImageSeriesReader怎么用?Python SimpleITK.ImageSeriesReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleITK
的用法示例。
在下文中一共展示了SimpleITK.ImageSeriesReader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _transform
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import ImageSeriesReader [as 别名]
def _transform(dcm_dir,save_dir):
### from dcm to nii
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(dcm_dir)
reader.SetFileNames(dicom_names)
image2 = reader.Execute()
### transform 3D image to array
image_array = sitk.GetArrayFromImage(image2) # z,y,x
### crop the dark voxel
# new_array,range_list = get_bound(image_array)
### transform array to 3D image
image3 = sitk.GetImageFromArray(image_array)
### save 3D image
name = dcm_dir.split('/')[-1] + '.nii'
save_path = os.path.join(save_dir,name) # get the save path
sitk.WriteImage(image3,save_path)
示例2: _read_dicom
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import ImageSeriesReader [as 别名]
def _read_dicom(directory: TypePath):
directory = Path(directory)
if not directory.is_dir(): # unreachable if called from _read_sitk
raise FileNotFoundError(f'Directory "{directory}" not found')
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(str(directory))
if not dicom_names:
message = (
f'The directory "{directory}"'
' does not seem to contain DICOM files'
)
raise FileNotFoundError(message)
reader.SetFileNames(dicom_names)
image = reader.Execute()
return image
示例3: main
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import ImageSeriesReader [as 别名]
def main():
path='/home/dongnie/warehouse/pelvicSeg/newData/pelvic_0118/'
subpath='atkinson_lafayette'
outfn=subpath+'.nii.gz'
inputdir=path+subpath
scan=ScanFile(path)
subdirs=scan.scan_subdir()
for subdir in subdirs:
if subdir==path or subdir=='..':
continue
print 'subdir is, ',subdir
ss=subdir.split('/')
print 'ss is, ',ss, 'and s7 is, ',ss[7]
outfn=ss[7]+'.nii.gz'
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(subdir)
reader.SetFileNames(dicom_names)
image = reader.Execute()
size = image.GetSize()
print( "Image size:", size[0], size[1], size[2] )
print( "Writing image:", outfn)
sitk.WriteImage(image,outfn)
示例4: load_dcm
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import ImageSeriesReader [as 别名]
def load_dcm(fpath):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(fpath)
reader.SetFileNames(dicom_names)
reader.MetaDataDictionaryArrayUpdateOn()
reader.LoadPrivateTagsOn()
image = reader.Execute()
image_array = sitk.GetArrayFromImage(image) # z, y, x
return image_array, reader
示例5: read_scan
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import ImageSeriesReader [as 别名]
def read_scan(path):
uid = os.path.basename(path)
if uid.split('.')[-1] == 'mhd':
uid = uid[:-4]
return sitk.ReadImage(path), uid
reader = sitk.ImageSeriesReader()
image_files = reader.GetGDCMSeriesFileNames(path)
assert len(image_files) > 0
if len(image_files) < settings.chunk_size:
print('Ignoring %s - only %d slices' % (path, len(image_files)))
return None, uid
reader.SetFileNames(image_files)
return reader.Execute(), uid
示例6: ReadImageAndLabel
# 需要导入模块: import SimpleITK [as 别名]
# 或者: from SimpleITK import ImageSeriesReader [as 别名]
def ReadImageAndLabel(CasePath,inverted=False):
#Reading Images
Reader = sitk.ImageSeriesReader()
name=findfiles(CasePath+'img/','*.dcm')
for i in range(len(name)):
name[i]=int(name[i][0:-4])
name=sorted(name)
name=name[::-1]
for i in range(len(name)):
#print name[i],'\n'
name[i]=CasePath+'img/'+str(name[i])+'.dcm'
Reader.SetFileNames(name)
Image = Reader.Execute()
Spacing=Image.GetSpacing()
Origin = Image.GetOrigin()
Direction = Image.GetDirection()
#Reading Labels
name=findfiles(CasePath+'label/','*.PNG')
name=sorted(name)
for i in range(len(name)):
name[i]=CasePath+'label/'+name[i]
#print name
#Sometimes labels are inverted along Z axis and should be rectified in this dataset
if inverted:
pass
else:
name=name[::-1]
# for i in range(len(name)):
# print name[i]+'\n'
Reader.SetFileNames(name)
Label = Reader.Execute()
LabelArray=sitk.GetArrayFromImage(Label)
LabelArray=((255-LabelArray[:,:,:,1])).astype(np.uint8)/255
Label=sitk.GetImageFromArray(LabelArray)
Label.SetSpacing(Spacing)
Label.SetOrigin(Origin)
Label.SetDirection(Direction)
return Image,Label