LUNA16数据集肺结节显示亲测

ps主要是基于该博主https://home.cnblogs.com/u/wzyuan/feed/blog/2.html  的LUNA16数据集系列上的亲测为更加小白的我一样。博主的方法可行但是有些还有补全才能出结果,希望对你有帮助。

1.数据集太大了我就上传我用的这个序列

链接:https://pan.baidu.com/s/1pcGQlQkE7ykGMczyz3JONw 
提取码:1h9k 
 

2.改了之后的代码(相关库可要自己装了,可以看之前的博客或百度)

import SimpleITK as sitk
import matplotlib.pyplot as plt
import numpy as np
filename='E:\\JLS\\dcm_data\\luna\\subset1\\1.3.6.1.4.1.14519.5.2.1.6279.6001.173106154739244262091404659845.mhd'
itkimage = sitk.ReadImage(filename)#读取.mhd文件
OR=itkimage.GetOrigin()
print(OR)
SP=itkimage.GetSpacing()
print(SP)
numpyImage = sitk.GetArrayFromImage(itkimage)#获取数据,自动从同名的.raw文件读取

def show_nodules(ct_scan, nodules,Origin,Spacing,radius=20, pad=2, max_show_num=4):  # radius是正方形边长一半,pad是边的宽度,max_show_num最大展示数

    show_index = []
    for idx in range(nodules.shape[0]):  # lable是一个nx4维的数组,n是肺结节数目,4代表x,y,z,以及直径
        if idx < max_show_num:
            if abs(nodules[idx, 0]) + abs(nodules[idx, 1]) + abs(nodules[idx, 2]) + abs(nodules[idx, 3]) == 0: continue

            x, y, z = int((nodules[idx, 0]-Origin[0])/SP[0]), int((nodules[idx, 1]-Origin[1])/SP[1]), int((nodules[idx, 2]-Origin[2])/SP[2])
            print(x, y, z)
            data = ct_scan[z]
            radius=int(nodules[idx, 3]/SP[0]/2)
            #pad = 2*radius
            # 注意 y代表纵轴,x代表横轴
            data[max(0, y - radius):min(data.shape[0], y + radius),
            max(0, x - radius - pad):max(0, x - radius)] = 3000  # 竖线
            data[max(0, y - radius):min(data.shape[0], y + radius),
            min(data.shape[1], x + radius):min(data.shape[1], x + radius + pad)] = 3000  # 竖线
            data[max(0, y - radius - pad):max(0, y - radius),
            max(0, x - radius):min(data.shape[1], x + radius)] = 3000  # 横线
            data[min(data.shape[0], y + radius):min(data.shape[0], y + radius + pad),
            max(0, x - radius):min(data.shape[1], x + radius)] = 3000  # 横线

            if z in show_index:  # 检查是否有结节在同一张切片,如果有,只显示一张
                continue
            show_index.append(z)
            plt.figure(idx)
            plt.imshow(data, cmap='gray')

    plt.show()
b = np.array([[-116.2874457,21.16102581,-124.619925,10.88839157],[-111.1930507,-1.264504521,-138.6984478,17.39699158],[73.77454834,37.27831567,-118.3077904,8.648347161]])
show_nodules(numpyImage,b,OR,SP)

3.结果图像

比较好的割出了结果。

4.针对这个数据很好的理解mhd参数和dcm的文章https://blog.csdn.net/zyc2017/article/details/84030903

 

  • 12
    点赞
  • 69
    收藏
    觉得还不错? 一键收藏
  • 47
    评论
评论 47
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值