事情起因是:
用模型训练分割肝脏,效果还不错。但是训练分割肝脏肿瘤时,dice系数很低。由于已经经过ROI处理,和图像预处理过程,所以只可能是数据层面出现了问题。经过查看,发现很多ct图是即使用肉眼也无法分辨出肿瘤的。论文中给出的那种图片,肿瘤与肝脏对比度很高,但这种情况只是数据集中的少数。为了验证自己的想法,在LITS2017的数据集上,做出了130个病人对应的肝脏与肿瘤的hu直方图,发现果然如此。
但这样的话,论文里是如何获得那么好的结果的呢??
(更新:2019-4-2,已完成肿瘤分割实验,写在博客:医学图像分割 基于深度学习的肝脏肿瘤分割 实战(二) )

下面是代码,可以作为工具类使用:

import numpy as np
import SimpleITK as sitk
import matplotlib.pyplot as pltonServer = False
if onServer:niiSegPath = './LITS17/seg/'niiImagePath = './LITS17/ct/'
else:niiSegPath = '~/LITS17/seg/'niiImagePath = '~/LITS17/ct/'def getRangeImageDepth(image):z = np.any(image, axis=(1,2)) # z.shape:(depth,)#print("all index:",np.where(z)[0])if len(np.where(z)[0]) >0:startposition,endposition = np.where(z)[0][[0,-1]]else:startposition = endposition = 0return startposition, endposition
"""
会画出每个病人肿瘤区域最大切片的直方图
与汇总的直方图
"""
total_liver = []
total_tumor = []
colors = ['b','g']
for i in range(0, 131, 1):seg = sitk.ReadImage(niiSegPath+ "segmentation-" + str(i) + ".nii", sitk.sitkUInt8)segimg = sitk.GetArrayFromImage(seg)src = sitk.ReadImage(niiImagePath+"volume-" + str(i) + ".nii")srcimg = sitk.GetArrayFromImage(src)seg_liver = segimg.copy()seg_liver[seg_liver>0] = 1seg_tumorimage = segimg.copy()seg_tumorimage[segimg == 1] = 0seg_tumorimage[segimg == 2] = 1# 获取含有肿瘤切片的起、止位置start,end = getRangeImageDepth(seg_tumorimage)if start==0 and end == 0:print("continue")continueprint("start:",start," end:",end)max_tumor=0 # 记录肿瘤的最大占比max_tumor_index = -1 # 记录最大肿瘤所在切片for j in range(start, end+1):if np.mean(seg_tumorimage[j]) > max_tumor:max_tumor = np.mean(seg_tumorimage[j])max_tumor_index = j#        batch_image.append(srcimg[j,:,:])
#        batch_mask.append(seg_tumorimage[j,:,:])src_flatten = srcimg[max_tumor_index].flatten()liver_flatten = seg_liver[max_tumor_index].flatten()tumor_flatten = seg_tumorimage[max_tumor_index].flatten()liver = [] # liver hu valuetumor = []for j in range(src_flatten.shape[0]):if liver_flatten[j]>0:liver.append(src_flatten[j])if tumor_flatten[j]>0:tumor.append(src_flatten[j])total_liver.append(liver)total_tumor.append(tumor)"""    # 因为肝脏区域很多而肿瘤很少,所以画直方图使用相同的y-axis就会导致# 几乎看不到肿瘤的直方图plt.hist(flat_total_liver, color = "skyblue", bins=100, alpha=0.5,      label='liver hu')plt.hist(flat_total_tumor, color = "red", bins=100, alpha=0.5, label='tumor hu')plt.legend(loc='upper right')"""fig, ax1 = plt.subplots()ax2 = ax1.twinx()ax1.hist([liver, tumor], bins=100,color=colors)n, bins, patches = ax1.hist([liver,tumor], bins=100)ax1.cla() #clear the axis#plots the histogram datawidth = (bins[1] - bins[0]) * 0.4bins_shifted = bins + widthax1.bar(bins[:-1], n[0], width, align='edge', color=colors[0])ax2.bar(bins_shifted[:-1], n[1], width, align='edge', color=colors[1])#finishes the plotax1.set_ylabel("liver hu Count", color=colors[0])ax2.set_ylabel("tumor hu Count", color=colors[1])ax1.tick_params('y', colors=colors[0])ax2.tick_params('y', colors=colors[1])plt.tight_layout()plt.title("person[%d],slice[%d]"%(i,max_tumor_index))plt.savefig("LITS/person%d_slice%d.png"%(i,max_tumor_index))plt.clf() # 用来展平total_liver和total_tumor里面的值
flat_total_liver = [item for sublist in total_liver for item in sublist]
flat_total_tumor = [item for sublist in total_tumor for item in sublist]
#plt.hist(flat_total_liver, color = "skyblue", bins=100, alpha=0.5, label='liver hu')
#plt.hist(flat_total_tumor, color = "red", bins=100, alpha=0.5, label='tumor hu')
#plt.legend(loc='upper right')
#plt.title("total hu")
#plt.savefig("LITS/total.png")
#plt.clf() fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.hist([flat_total_liver, flat_total_tumor], bins=100,color=colors)
n, bins, patches = ax1.hist([flat_total_liver,flat_total_tumor], bins=100)
ax1.cla() #clear the axis#plots the histogram data
width = (bins[1] - bins[0]) * 0.4
bins_shifted = bins + width
ax1.bar(bins[:-1], n[0], width, align='edge', color=colors[0])
ax2.bar(bins_shifted[:-1], n[1], width, align='edge', color=colors[1])#finishes the plot
ax1.set_ylabel("liver hu Count", color=colors[0])
ax2.set_ylabel("tumor hu Count", color=colors[1])
ax1.tick_params('y', colors=colors[0])
ax2.tick_params('y', colors=colors[1])
plt.tight_layout()
plt.title("total")
plt.savefig("LITS/total.png")
plt.clf()

论文里的图片通常是这样的:

但实际上很多图是这样的(已经经过预处理):

为了验证想法,作出原始hu值,发现确实如此,大约一半的病人肝脏与肿瘤的hu分布是对比度很强的,但另一半的情况是二者几乎重叠。(问了下学医的同学,说肝脏肿瘤分为很多种,连医生很多时候也无法通过ct判断,这时候就要做增强ct)下面是代码运行的部分结果展示

医学图像预处理(五) 器官与病灶的直方图相关推荐

  1. 用于深度学习的医学图像预处理

    用于深度学习的医学图像数据,往往非常庞大,如果从网上下载公开数据集数据,往往有几十GB的图象数据,我们需要先进行预处理,将其转换成适合深度学习网络训练的形式:        变为      或者我们还 ...

  2. 医学图像预处理(三)——windowing(ct对比增强)

    若是dicom格式的图片,得先转化为hu值(即ct图像值,若图片本来就是ct,则不需要转换)(见下面更新内容) ,因为hu值是与设备无关的,不同范围之内的值可以代表不同器官.常见的对应如下(w代表ct ...

  3. 医学图像预处理(二)——重采样(resampling)

    之所以需要重采样是由于不同的病人体型不同,但最后数字成像的分辨率是一样的,这就导致了一定程度的失真变形. 但医学图像例如dcm或nii格式,都会带有SliceThickness,PixelSpacin ...

  4. 医学图像预处理(四)—— 提取包含目标的切片(比如仅提取包含肿瘤或肝脏的切片)

    在训练网络时,一般目标区域越有针对性效果越好,因此经常会在训练前对数据进行预处理,提取出包含有目标的那些切片. 下面是示例代码(原始数据是3D ct images) 简单的方法: def getRan ...

  5. 医学图像预处理----重采样(Resample)

    前言: 在医学图像中,重采样是指将医疗图像中大小不同的体素归一化到相同的大小.体素是体积元素(Volume Pixel)的简称,一张3D医学图像可以看成是由若干个体素构成的,体素是一张3D医疗图像在空 ...

  6. 【深度学习入门到精通系列】医学图像预处理—CLAHE变换代码

    import cv2mri_img = cv2.imread('./images/cla.png')lab = cv2.cvtColor(mri_img, cv2.COLOR_BGR2LAB)lab_ ...

  7. 【深度学习入门到精通系列】医学图像预处理—伽马变化代码

    import cv2 as cv import numpy as npimport matplotlib.pyplot as pltdef grayHist(img):h, w = img.shape ...

  8. 【深度学习入门到精通系列】医学图像预处理—灰度转换代码(G通道)

    def image_channel_feature():'''读取图像,转为bytes'''image = tf.read_file(image_path)'''图像解码'''image = tf.i ...

  9. 医学图像分割 基于深度学习的肝脏肿瘤分割 实战(二)

    在医学图像分割 基于深度学习的肝脏肿瘤分割 实战(一)中,实现了对肝脏的分割,但是后续在使用相同的处理方法与模型进行肿瘤分割的时候,遇到了两次问题. 第一次,网络的dice系数,训练集上一直只能达到4 ...

最新文章

  1. 我在Archlinux下使用的软件
  2. python培训班 北京-北京python培训机构那个好?这几个坑千万别踩
  3. python安装第三方库-安装第三方模块
  4. Javascript称球
  5. 奇怪的问题,疑惑?不用的 User agent 居然gzip不一样?
  6. ubuntu进行apt-get时候出现Package ssh is not available, but is referred to by another package 错误...
  7. 今天完成了share memory的测试
  8. python 内建函数basestring笔记
  9. Linux 配置Tomcat
  10. 2022-2028年中国环保减速机行业运行动态及投资机会分析报告
  11. (附源码)计算机毕业设计ssm基于JAVA宠物店管理系统
  12. 第一课:ASP.NET Core入门之简单快速搭建ASP.NET Core项目结构
  13. java的8年来工作汇总
  14. 电脑桌面的文件突然不见了怎么办
  15. android 熄屏后仍然可以点击,Android - 在不触发睡眠/锁定屏幕的情况下关闭显示屏 - 使用触摸屏打开...
  16. poj:Freda的越野跑 求正序对数
  17. 6. 大尾数法或小尾数法
  18. 校园二手交易android软件 基于AndroidStudio
  19. 【机器人学】逆运动学
  20. 关于__construct()和__destruct

热门文章

  1. Unity 模型导入材质丢失解决方案
  2. latex 表格 调整单元格文本垂直居中
  3. numpy求矩阵的逆和伪逆
  4. 渗透攻击MS08-067
  5. error: (-215:Assertion failed)解决方案
  6. 极客日报:iPhone13系列9月15日正式推出;微信视频号支持发布1小时视频;Firefox 92正式发布
  7. 团体程序设计天梯赛-练习集L1-058 6翻了 (15 分)
  8. 修改电脑C:\User\用户名文件夹的名字
  9. 刷完这50个标准库模块:没人比我更懂Python了
  10. 微信平台公众号推送文章撰写建议