gpt4 book ai didi

python - 使用 PIL(PILLOW) Python 库显示 Dicom 图像

转载 作者:行者123 更新时间:2023-12-01 06:25:50 26 4
gpt4 key购买 nike

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

我正在使用pillow python库来处理图像。

最佳答案

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

C.8.3.1.1.3 Photometric Interpretation

Enumerated Values:

  • MONOCHROME1
  • MONOCHROME2

关于python - 使用 PIL(PILLOW) Python 库显示 Dicom 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60147367/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com