pydicom数据的处理
发布日期:2021-05-14 15:21:43 浏览次数:19 分类:精选文章

本文共 2901 字,大约阅读时间需要 9 分钟。

��������������� DICOM ������

��������������������� DICOM ��������������������������������� PyDICOM ������������������������������ DICOM ������������������������������������������������


������ DICOM ������

������1������������������������

���������������������������������������

pip install pydicom pillow numpy

������������������������

import os
from pydicom import dcmread
from PIL import Image
import numpy as np

������2������������������������������������

������������������������������������

folder_path = r"D:\project"
file_name = "IM62.dcm"
file_path = os.path.join(folder_path, file_name)
dcm = dcmread(file_path)

������ DICOM ������

������3���������������������

������ DICOM ���������������������������������������

img_arr = dcm.pixel_array
print("������������:", img_arr)

������4���������������������

������������������������

print("������������:", img_arr.shape)

������5���������������������

������������������������������

print("������������:", img_arr.dtype)

���������������

���������������������������������������������������������������������������


������������������ matplotlib ���������������

������6���������������������������

from matplotlib import pyplot as plt

������7���������������������

plt.figure(figsize=(10, 5))
plt.imshow(img_arr, cmap='bone') # ���������������������
plt.title('���������')
plt.xlabel('������')
plt.ylabel('������')
plt.show()

���������������������������������������������������

��������������������������������������������������������������������������������������������������������� PIL.Image ��� matplotlib ���������

������������ PIL.Image:

from PIL import Image
image = Image.fromarray(img_arr)
image.show()

���������������������

��������������������������������������������������������� PIL.Image ������������������

������8���������������

# ������45���
rotated_image = image.rotate(45)
rotated_image.show()

���������������������

������������������������������������������������������������������������������������

������9������������ numpy.ndarray ���������������

��������������������������������������������������������� PIL.Image ��������� numpy.ndarray���

rotated_ndarray = np.array(rotated_image)
# ��������������� DICOM ������
new_name = "rotated_dcm.dcm"
dcm.PixelData = rotated_ndarray.tobytes()
dcm.Rows = rotated_ndarray.shape[0]
dcm.Columns = rotated_ndarray.shape[1]
dcm.save_as(os.path.join(folder_path, new_name))

������������

������10������������������������������

������������������������������������������������������������ DICOM ������������������������

new_dcm = dcmread(os.path.join(folder_path, new_name))
# ������ pixel array
pixel_data = new_dcm.pixel_array
print("������������������������:", pixel_data)

������

������������������������������������������������������������������������ DICOM ���������������PyDICOM ��� PIL.Image ������������������������������������������������������������������������������������������������������

上一篇:pydicom图像数据的保存
下一篇:pydicom数据的读取

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2025年04月16日 06时52分46秒