【问题标题】:Display Dicom image using PIL(PILLOW) Python Library使用 PIL(PILLOW) Python 库显示 Dicom 图像
【发布时间】:2020-02-10 09:25:48
【问题描述】:

我正在尝试使用以下代码读取和显示 DICOM(.dcm) 图像:-

import pydicom as dicom
import numpy as np
from PIL import Image, ImageEnhance, ImageOps
from PIL.ImageQt import ImageQt

def display_dicom_images(self, folder_Path):
    try:
        # Image parameters
        image_width = 382
        image_height = 382

        image_depth = 3
        self.total_images_in_folder = len(glob.glob1(folder_Path,"*"))

        # Select the center image for display
        self.current_image_number = round(self.total_images_in_folder / 2)
        self.display_number = self.current_image_number

        image_dtype = np.uint8
        pixel_array = np.ndarray([self.total_images_in_folder, image_height, image_width, image_depth]).astype(image_dtype)
        # load images here, once better MR images are acquired
        for image_index in range(0, self.total_images_in_folder):
            # for DICOM
            image_path = folder_Path + "/" + str(image_index) + ".dcm"

            scan_image = dicom.dcmread(image_path)
            scan_image = scan_image.pixel_array.astype(image_dtype)

            pixel_array[image_index, :scan_image.shape[0], :scan_image.shape[1], :scan_image.shape[2]] = scan_image

        return pixel_array

但出现错误:-

IndexError('元组索引超出范围',)

我正在为图像使用枕头 python 库。

【问题讨论】:

  • 你能发布完整的回溯吗?它将显示导致问题的行。此外,您还有一个 try 块,没有 except...
  • @scaramallion 这一行通过错误:- pixel_array[image_index, :scan_image.shape[0], :scan_image.shape[1], :scan_image.shape[2]] = scan_image
  • @scaramallion:- Second Last line throughing 错误。

标签: python python-3.x python-imaging-library dicom pydicom


【解决方案1】:

你怎么知道scan_image.shape 的长度为 3? MR 图像should only be monochrome,这将使image_depth = 1scan_image.shape 的长度等于2。

C.8.3.1.1.3 光度解释

枚举值:

  • 单色1
  • 单色2

【讨论】:

  • 你能告诉我 dicom 图像的模式是什么吗?例如- L, I. RGB, 1 or etc..?
  • 这取决于dataset.BitsAllocated的值,如果是8则可以使用L,如果是16则必须使用I;16
  • @scarmallion:- 那mode = 'RGB'
  • 这将适用于 Samples Per Pixel = 3,而不适用于 MR 图像。这也偏离了轨道,我的回答在诊断您的原始问题时是否正确?
  • 这取决于,如果您只是在处理 MR Image 数据集,那么是的,那应该没问题。但总的来说,在处理 DICOM 数据时,最好尽量减少您的假设(因为最终会出现您意想不到的情况)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-28
  • 1970-01-01
  • 2022-12-21
  • 1970-01-01
  • 1970-01-01
  • 2020-04-13
相关资源
最近更新 更多