医工互联

 找回密码
 注册[Register]

手机动态码快速登录

手机号快速登录

微信登录

微信扫一扫,快速登录

QQ登录

只需一步,快速开始

查看: 229|回复: 0
收起左侧

基于2D超声影像的影像组学特征提取-影像组学(radiomics)小李教学系列视频

[复制链接]

  在线 

发表于 2022-10-25 19:25:30 | 显示全部楼层 |阅读模式 <
本节(35)主要介绍:2D超声影像组学的特征提取
视频中情境再现了小白研究者可能碰到的各种技术难题,并演示了解决这些问题的思路。

  • 将dicom格式的2D 超声图像转为压缩的nifti格式,将其命名为test.nii.gz; 勾画ROI后同样保存为压缩的nifti格式,命名为mask.nii.gz
203004g4nd43318ho2o3dn.jpeg


  • 尝试提取影像学特征
import radiomics from radiomics import featureextractorimageFile = &#34;/Users/Mac/Documents/JianShuNotes/2D_Ultrasound/test.nii.gz&#34;maskFile = &#34;/Users/Mac/Documents/JianShuNotes/2D_Ultrasound/mask.nii.gz&#34;extractor = featureextractor.RadiomicsFeatureExtractor()featureVector = extractor.execute(imageFile, maskFile)#print(featureVector.items())for featureName in featureVector.keys():    print(&#34;%s: %s&#34; % (featureName, featureVector[featureName]))出现了如下报错信息:
sitk::ERROR: Pixel type: vector of 8-bit unsigned integer is not supported in 3D byN3itk6simple26LabelStatisticsImageFilterE


  • 按照提示,有可能是数据格式的问题。回到源代码,修改文件相应的格式,将其命名为 test1.nii.gz
import SimpleITK as sitkimport numpy as npfolderPath = &#34;/Users/Mac/Documents/JianShuNotes/2D_Ultrasound/&#34;reader = sitk.ImageSeriesReader()dicom_names = reader.GetGDCMSeriesFileNames(folderPath)reader.SetFileNames(dicom_names)image = reader.Execute()image_arr = sitk.GetArrayFromImage(image) # Note: order:z, y, x !!size = image.GetSize()origin = image.GetOrigin() #order: x, y, zspacing = image.GetSpacing() #order:x, y, zdirection = image.GetDirection()#print(spacing) pixelType = sitk.sitkInt8 #注意这里是Int8image_new = sitk.Image(size,pixelType)#image_arr_new = image_arr[:,:,::-1] #镜像翻转操作image_arr_new = image_arr#print(image_arr_new.shape)image_new = sitk.GetImageFromArray(image_arr_new)image_new.SetDirection(direction)image_new.SetSpacing(spacing)image_new.SetOrigin(origin)sitk.WriteImage(image_new,folderPath + &#34;test1.nii.gz&#34;)

  • 将步骤[2]中的test.nii.gz替换为test1.nii.gz,再次执行该步骤
    此时又出现了报错信息:
sitk::ERROR: Input &#34;labelImage&#34; for &#34;LabelStatisticsImageFilter&#34; has dimension of 3 which does not match the primary input&#39;s dimension of 2!


  • 执行 print(image_arr_new.shape) 后显示为:
(1, 900, 1600, 3)
Notes: 这里涉及python读入nifti文件的格式问题,其顺序为 z,y,x(对应这里的1,900,1600); 这里的3为不同的slice

  • 将test-slice0.nii.gz,test-slice1.nii.gz,test-slice2.nii.gz在软件中打开,查看它们之间的差异(肉眼似乎看不出啥区别)
  • 使用写代码的方法来探索test-slice0.nii.gz,test-slice1.nii.gz,test-slice2.nii.gz之间的差异(视频里演示了对比前二者)
import SimpleITK as sitkimport numpy as npslicer0 = sitk.ReadImage(&#34;test-slice0.nii.gz&#34;)slicer1 = sitk.ReadImage(&#34;test-slice1.nii.gz&#34;)slicer0_arr = sitk.GetArrayFromImage(slicer0)slicer1_arr = sitk.GetArrayFromImage(slicer1)comp = slicer0_arr == slicer1_arrprint(comp)
203005h95n59s9rzrcds5w.jpeg


  • 将差异的部分保存为影像导出
image_arr = slicer0_arr - slicer1_arrimage_arr[image_arr != 0] = 1size = slicer0.GetSize()origin = slicer0.GetOrigin() #order: x, y, zspacing = slicer0.GetSpacing() #order:x, y, zdirection = slicer0.GetDirection()image_new = sitk.GetImageFromArray(image_arr)image_new.SetDirection(direction)image_new.SetSpacing(spacing)image_new.SetOrigin(origin)sitk.WriteImage(image_new,&#34;comp.nii.gz&#34;)

  • 此时在软件中打开comp.nii.gz文件,查看差异(在于右下角的水印部分)(视频中是左下角的水印)。换句话说,这3张test-slice0.nii.gz,test-slice1.nii.gz,test-slice2.nii.gz是一样的,差别仅在于右下角的水印。所以,后续的工作只需选择其中的一个即可。
  • 再次查看test-slice0.nii.gz和mask文件,发现mask文件和源文件不对应。mask.nii.gz是基于test.nii.gz文件画出并保存的,但是在test.nii.gz保存为test1.nii.gz时存在一个翻转(我没有搞明白这一点),所以应重新保存一下mask文件
203005fdp6shnwdcy22dy6.jpeg
import SimpleITK as sitkimport numpy as npfolderPath = &#34;/Users/Mac/Documents/JianShuNotes/2D_Ultrasound/&#34;mask = sitk.ReadImage(&#39;mask.nii.gz&#39;)mask_arr = sitk.GetArrayFromImage(mask)reader = sitk.ImageSeriesReader()dicom_names = reader.GetGDCMSeriesFileNames(folderPath)reader.SetFileNames(dicom_names)image = reader.Execute()image_arr = sitk.GetArrayFromImage(image) # Note: order:z, y, x !!size = image.GetSize()origin = image.GetOrigin() #order: x, y, zspacing = image.GetSpacing() #order:x, y, zdirection = image.GetDirection()pixelType = sitk.sitkInt8 #注意这里是Int8image_new = sitk.Image(size,pixelType)mask_new = sitk.Image(size,pixelType)#image_arr_new = image_arr[:,:,::-1] #镜像翻转操作image_arr_new = image_arr[:,:,:,0]print(image_arr.shape)image_new = sitk.GetImageFromArray(image_arr_new)image_new.SetDirection(direction)image_new.SetSpacing(spacing)image_new.SetOrigin(origin)mask_new = sitk.GetImageFromArray(mask_arr) # 视频里勘误为mask_new,其实就应该是mask_arr, print二者可以看出区别来mask_new.SetDirection(direction)mask_new.SetSpacing(spacing)mask_new.SetOrigin(origin)sitk.WriteImage(image_new,&#34;test0.nii.gz&#34;)sitk.WriteImage(mask_new,&#34;mask0.nii.gz&#34;)
203006hk9odsq2r3aazee7.jpeg


  • 再次尝试提取影像组学特征(代码[2]),发现代码可以运行。但是这里有一个隐藏的bug,就是mask文件虽然重新保存了,但是并不能和原来的位置匹配。通过软件查看图像可以发现其中的区别
203006c77262q1k2k9kll7.jpeg


  • 再次回到原始代码里查找问题来源
import SimpleITK as sitkimport numpy as npfolderPath = &#34;/Users/Mac/Documents/JianShuNotes/2D_Ultrasound/&#34;mask = sitk.ReadImage(&#39;mask.nii.gz&#39;)mask_arr = sitk.GetArrayFromImage(mask)#reader = sitk.ImageSeriesReader()#dicom_names = reader.GetGDCMSeriesFileNames(folderPath)#reader.SetFileNames(dicom_names)#image = reader.Execute()image = sitk.ReadImage(&#39;test.nii.gz&#39;)image_arr = sitk.GetArrayFromImage(image) # Note: order:z, y, x !!size = image.GetSize()origin = image.GetOrigin() #order: x, y, zspacing = image.GetSpacing() #order:x, y, zdirection = image.GetDirection()pixelType = sitk.sitkInt8 #注意这里是Int8image_new = sitk.Image(size,pixelType)mask_new = sitk.Image(size,pixelType)#image_arr_new = image_arr[:,:,::-1] #镜像翻转操作image_arr_new = image_arr[:,:,:,0]print(image_arr.shape)image_new = sitk.GetImageFromArray(image_arr_new)image_new.SetDirection(direction)image_new.SetSpacing(spacing)image_new.SetOrigin(origin)mask_new = sitk.GetImageFromArray(mask_arr)mask_new.SetDirection(direction)mask_new.SetSpacing(spacing)mask_new.SetOrigin(origin)sitk.WriteImage(image_new,&#34;test0.nii.gz&#34;)sitk.WriteImage(mask_new,&#34;mask0.nii.gz&#34;)

  • 历尽周折,现在test0.nii.gz文件和mask0.nii.gz文件相匹配了!可以愉快地提取影像组学特征了
203006m6lgif8bbktlsls6.jpeg
import radiomics from radiomics import featureextractorimageFile = &#34;/Users/Mac/Documents/JianShuNotes/2D_Ultrasound/test0.nii.gz&#34;maskFile = &#34;/Users/Mac/Documents/JianShuNotes/2D_Ultrasound/mask0.nii.gz&#34;extractor = featureextractor.RadiomicsFeatureExtractor()featureVector = extractor.execute(imageFile, maskFile)#print(featureVector.items())for featureName in featureVector.keys():    print(&#34;%s: %s&#34; % (featureName, featureVector[featureName]))
203007mtyyudtt5y9qg6z2.jpeg
邮箱:l-ry@hotmail.com(请将问题描述完整)
个人精力有限,无法私聊答疑,有问题请发送邮件,请互相尊重。
如需添加影像组学微信讨论组,请添加微信:hochzeitstorte

来源:https://zhuanlan.zhihu.com/p/389341780
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

提醒:禁止复制他人回复等『恶意灌水』行为,违者重罚!
您需要登录后才可以回帖 登录 | 注册[Register] 手机动态码快速登录 微信登录

本版积分规则

发布主题 快速回复 收藏帖子 返回列表 客服中心 搜索
简体中文 繁體中文 English 한국 사람 日本語 Deutsch русский بالعربية TÜRKÇE português คนไทย french

QQ|RSS订阅|小黑屋|处罚记录|手机版|联系我们|Archiver|医工互联 |粤ICP备2021178090号 |网站地图

GMT+8, 2024-11-22 20:39 , Processed in 0.265511 second(s), 61 queries .

Powered by Discuz!

Copyright © 2001-2023, Discuz! Team.

快速回复 返回顶部 返回列表