• ITK Read Dicom


    https://itk.org/ITKExamples/src/IO/GDCM/ReadDICOMSeriesAndWrite3DImage/Documentation.html
    #!/usr/bin/env python
    
    import sys
    import os
    import itk
    import argparse
    
    parser = argparse.ArgumentParser(description="Read DICOM Series And Write 3D Image.")
    parser.add_argument(
        "dicom_directory",
        nargs="?",
        help="If DicomDirectory is not specified, current directory is used",
    )
    parser.add_argument("output_image", nargs="?")
    parser.add_argument("series_name", nargs="?")
    args = parser.parse_args()
    
    # current directory by default
    dirName = "."
    if args.dicom_directory:
        dirName = args.dicom_directory
    
    PixelType = itk.ctype("signed short")
    Dimension = 3
    
    ImageType = itk.Image[PixelType, Dimension]
    
    namesGenerator = itk.GDCMSeriesFileNames.New()
    namesGenerator.SetUseSeriesDetails(True)
    namesGenerator.AddSeriesRestriction("0008|0021")
    namesGenerator.SetGlobalWarningDisplay(False)
    namesGenerator.SetDirectory(dirName)
    
    seriesUID = namesGenerator.GetSeriesUIDs()
    
    if len(seriesUID) < 1:
        print("No DICOMs in: " + dirName)
        sys.exit(1)
    
    print("The directory: " + dirName)
    print("Contains the following DICOM Series: ")
    for uid in seriesUID:
        print(uid)
    
    seriesFound = False
    for uid in seriesUID:
        seriesIdentifier = uid
        if args.series_name:
            seriesIdentifier = args.series_name
            seriesFound = True
        print("Reading: " + seriesIdentifier)
        fileNames = namesGenerator.GetFileNames(seriesIdentifier)
    
        reader = itk.ImageSeriesReader[ImageType].New()
        dicomIO = itk.GDCMImageIO.New()
        reader.SetImageIO(dicomIO)
        reader.SetFileNames(fileNames)
        reader.ForceOrthogonalDirectionOff()
    
        writer = itk.ImageFileWriter[ImageType].New()
        outFileName = os.path.join(dirName, seriesIdentifier + ".nrrd")
        if args.output_image:
            outFileName = args.output_image
        writer.SetFileName(outFileName)
        writer.UseCompressionOn()
        writer.SetInput(reader.GetOutput())
        print("Writing: " + outFileName)
        writer.Update()
    
        if seriesFound:
            break
  • 相关阅读:
    Eclipse上安装Activiti插件
    Java之Map的使用场景
    Java之Set的使用场景
    Java之List使用场景
    Java重写toString和泛型的使用
    Java学习之静态代码块
    Java学习之StringBuffer
    Java学习之基本数据类型和引用数据类型区别
    Java学习之String
    Java基础整理之字节、数组、字符串、面向对象
  • 原文地址:https://www.cnblogs.com/imoon22/p/15473186.html
Copyright © 2020-2023  润新知