python-读取dcm文件-2021.5.24

  • 读取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

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值