
本文共 2901 字,大约阅读时间需要 9 分钟。
��������������� DICOM ������
��������������������� DICOM ��������������������������������� PyDICOM ������������������������������ DICOM ������������������������������������������������
������ DICOM ������
������1������������������������
���������������������������������������
pip install pydicom pillow numpy
������������������������
import osfrom pydicom import dcmreadfrom PIL import Imageimport 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_arrayprint("������������:", 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 Imageimage = 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 arraypixel_data = new_dcm.pixel_arrayprint("������������������������:", pixel_data)
������
������������������������������������������������������������������������ DICOM ���������������PyDICOM
��� PIL.Image
������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
