【问题标题】:Image note correctly displayed after transforming to Hounsfield Units转换为 Hounsfield 单位后正确显示图像注释
【发布时间】:2022-05-25 08:56:01
【问题描述】:

我正在做 CT 扫描,对肝脏区域特别感兴趣。我正在尝试使用 python 中的以下函数将像素值转换为 Hounsfield 单位:

def transform_to_hu(slices): 
    images = np.stack([file.pixel_array for file in slices], axis=-1) #axis=-1 for depth in the last channel
    images = images.astype(np.int16)

    for n in range(len(slices)):
        
        intercept = slices[n].RescaleIntercept
        slope = slices[n].RescaleSlope
        
        if slope != 1:
            images[n] = slope * images[n].astype(np.float64)
            images[n] = images[n].astype(np.int16)
            
        images[n] += np.int16(intercept)
    
    return np.array(images, dtype=np.int16)

转换为 HU 后,为什么图像看起来像是分成了两个区域?

【问题讨论】:

    标签: python-3.x normalization pixel dicom medical-imaging


    【解决方案1】:

    您的 n 变量是 numpy 数组的第一个索引(对应于冠状切片),而您在应用重新缩放操作时迭代切片的数量。因为切片数小于行数,所以重新缩放操作不会覆盖整个卷。

    您应该遍历轴向切片(即使用 numpy 数组 images[..., n] 的最后一个索引)。这是一个如何使用 pydicom 的 apply_rescale() 函数的示例:

    from pydicom.data import get_testdata_file
    from pydicom.pixel_data_handlers import apply_rescale
    import numpy as np
    
    ds = get_testdata_file("CT_small.dcm")
    ds_stack = [ds, ds, ds]
    
    images = np.stack([ds.pixel_array for ds in ds_stack], axis=-1).astype('float64')
    for idx, ds in enumerate(ds_stack):
        images[..., idx] = apply_rescale(images[..., idx], ds)
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多