01_preprocess.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:kaggle-lung-cancer 作者: mdai 项目源码 文件源码
def to_volume(slices):
    """Creates ndarray volume in Hounsfield units (HU) from array of pydicom slices.
    """
    volume = np.stack([s.pixel_array for s in slices])
    volume = volume.astype(np.int16)

    # Set outside-of-scan pixels to 0
    # The intercept is usually -1024, so air is approximately 0
    volume[volume == -2000] = 0

    # Convert to Hounsfield units (HU)
    for n in range(len(slices)):
        intercept = slices[n].RescaleIntercept
        slope = slices[n].RescaleSlope
        if slope != 1:
            volume[n] = slope * volume[n].astype(np.float64)
            volume[n] = volume[n].astype(np.int16)
        volume[n] += np.int16(intercept)

    volume = np.array(volume, dtype=np.int16)
    spacing = tuple(map(float, ([slices[0].SliceThickness] + slices[0].PixelSpacing)))
    return volume, spacing
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号