- 读取dcm文件
# 采用pydicom模块
import pydicom
# 数据路径
file_path = r"C:\Users\孔啊吱\Desktop\kaggle_covid19\data\3dcdfc352a06.dcm"
# read_file
data0 = pydicom.read_file(file_path)
# file_data = data0.pixel_array
# print(file_data)
# dcmread
data1 = pydicom.dcmread(file_path)
分别采用了read_file和dcmread两种方式读取数据,两种方式读取效果相同,
读取出来的data0和data1数据均如下所示
前面为患者的基本信息
data0.keys()可以查看数据的键
根据对应的键,可以查询相应的值
读取影像数据,打印出图片
- 借助numpy与PIL.Image
import numpy as np
data = np.array(data0.pixel_array)
from PIL import Image
data_img = Image.fromarray(data0.pixel_array)
data_img_rotated = data_img.rotate(angle=45,resample=Image.BICUBIC)
from matplotlib import pyplot
pyplot.imshow(data0.pixel_array,cmap=pyplot.cm.bone)
pyplot.show()
参考:
https://blog.csdn.net/weixin_40451627/article/details/105574348