使用PIL(枕头)Python库显示Dicom图像

2024-04-29 07:07:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用以下代码读取和显示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('tuple index out of range',)

我正在使用python库进行图像处理


Tags: pathinimageimportselfindexscandisplay