【问题标题】:How to sort DICOM Slices in correct order?如何以正确的顺序对 DICOM 切片进行排序?
【发布时间】:2019-12-23 16:53:50
【问题描述】:

我正在尝试以正确的顺序对 DICOM 文件进行排序,但我无法使用图像位置患者描述符,因为它给了我一个错误“AttributeError: 'FileDataset' object has no attribute 'sort'”。

代码:

for paths in a:
    for root, dirs, files in os.walk(paths):
        for file in files:
            if file.endswith('.dcm'):
                k = dcm.read_file(os.path.join(root, file))
                k.sort
                k = dcm.read_file(os.path.join(root, file)).pixel_array
                PixelArrays.append(k)

除了排序属性 pydicom lib 工作正常。

【问题讨论】:

    标签: dicom pydicom


    【解决方案1】:

    这个例子展示了如何对切片进行排序。

    https://github.com/pydicom/pydicom/blob/master/examples/image_processing/reslice.py

    import pydicom
    import numpy as np
    import matplotlib.pyplot as plt
    import sys
    import glob
    
    # load the DICOM files
    files = []
    print('glob: {}'.format(sys.argv[1]))
    for fname in glob.glob(sys.argv[1], recursive=False):
        print("loading: {}".format(fname))
        files.append(pydicom.dcmread(fname))
    
    print("file count: {}".format(len(files)))
    
    # skip files with no SliceLocation (eg scout views)
    slices = []
    skipcount = 0
    for f in files:
        if hasattr(f, 'SliceLocation'):
            slices.append(f)
        else:
            skipcount = skipcount + 1
    
    print("skipped, no SliceLocation: {}".format(skipcount))
    
    # ensure they are in the correct order
    slices = sorted(slices, key=lambda s: s.SliceLocation)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-15
      • 1970-01-01
      • 2018-06-25
      • 2020-10-10
      相关资源
      最近更新 更多