【发布时间】: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