當前位置: 首頁>>代碼示例>>Python>>正文


Python SimpleITK.ImageSeriesReader方法代碼示例

本文整理匯總了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) 
開發者ID:wcfzl,項目名稱:3D-CNNs-for-Liver-Classification,代碼行數:23,代碼來源:crop_transform.py

示例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 
開發者ID:fepegar,項目名稱:torchio,代碼行數:17,代碼來源:io.py

示例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) 
開發者ID:ginobilinie,項目名稱:medSynthesisV1,代碼行數:33,代碼來源:dicom2Nii.py

示例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 
開發者ID:microsoft,項目名稱:Recursive-Cascaded-Networks,代碼行數:11,代碼來源:demo.py

示例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 
開發者ID:anlthms,項目名稱:dsb-2017,代碼行數:17,代碼來源:convert.py

示例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 
開發者ID:huangyjhust,項目名稱:3D-RU-Net,代碼行數:44,代碼來源:Step1_PreProcessing.py


注:本文中的SimpleITK.ImageSeriesReader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。