使用 pyradiomics 进行医学影像学图像的特征提取

1. 安装 pyradiomics 包

1.1. 运行环境配置

  1. 确保计算机已经安装了python,并且版本在3.5以上
  2. 下载并解压项目到本地
    项目地址https://github.com/AIM-Harvard/pyradiomics
  3. 安装terminal终端(微软应用商店搜索 terminal ),傻瓜式安装。
  4. 安装 MSVC 依赖包,这一步至关重要
    大多数 windows 系统都没有预装 MSVC 依赖。当然你可以通过安装 Visual Studio 的简单粗暴的方式来安装这个依赖,但是奈何VS本身体积过大,为了一个building tool装一整个VS,未免有些杀鸡用牛刀之嫌。这里介绍两种方式:

1.2. 依赖安装与检验

  1. 使用 terminal 进入 1.1.3 中提到的文件的位置(如果使用 GitHub Desktop 下载,位置应该在 Doucments\Github\pyradiomics 文件夹内)
    进入方法cd xxxx ,此略
  2. terminal 中输入:
    python -m pip install -r requirements.txt
    
    若输出
    Requirement already satisfied: numpy>=1.9.2 in c:\users\repo\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 1)) (1.22.4)
    Requirement already satisfied: SimpleITK>=0.9.1 in c:\users\repo\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 2)) (2.1.1.2)
    Requirement already satisfied: PyWavelets>=0.4.0 in c:\users\repo\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 3)) (1.3.0)
    Requirement already satisfied: pykwalify>=1.6.0 in c:\users\repo\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 4)) (1.8.0)
    Requirement already satisfied: six>=1.10.0 in c:\users\repo\appdata\local\programs\python\python38\lib\site-packages (from -r requirements.txt (line 5)) (1.16.0)
    Requirement already satisfied: ruamel.yaml>=0.16.0 in c:\users\repo\appdata\local\programs\python\python38\lib\site-packages (from pykwalify>=1.6.0->-r requirements.txt (line 4)) (0.17.21)       
    Requirement already satisfied: python-dateutil>=2.8.0 in c:\users\repo\appdata\local\programs\python\python38\lib\site-packages (from pykwalify>=1.6.0->-r requirements.txt (line 4)) (2.8.2)      
    Requirement already satisfied: docopt>=0.6.2 in c:\users\repo\appdata\local\programs\python\python38\lib\site-packages (from pykwalify>=1.6.0->-r requirements.txt (line 4)) (0.6.2)
    Requirement already satisfied: ruamel.yaml.clib>=0.2.6 in c:\users\repo\appdata\local\programs\python\python38\lib\site-packages (from ruamel.yaml>=0.16.0->pykwalify>=1.6.0->-r requirements.txt (line 4)) (0.2.6)    
    
    之类,不报错,则说明安装成功。
  3. 继续在 terminal 中输入:
    python setup.py install
    
    若前文没有安装MSVC,则会提醒你如下错误:
    error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/ Tools":
    
    若稳定地输出了很多东西,回溯记录的时候也没有发现诸如“error”、“fatal”、“unexpected”之类的错误报告行的话,就说明运行成功。
  4. terminal 中输入 python ,在三箭头后输入 import radiomics,若无任何输出(注:什么也没有),则安装完成。

2. pyradiomics使用案例

2.1. 运行准备

创建test.py,内容如下

import radiomics
import radiomics.featureextractor as FEE
 
# 文件名
main_path =  '.'
ori_name = r'\brain1_image.nrrd'
lab_name = r'\brain1_label.nrrd'
para_name = r'\Params.yaml'
 
# 文件全部路径
ori_path = main_path + ori_name  
lab_path = main_path + lab_name
para_path = main_path + para_name
print("originl path: " + ori_path)
print("label path: " + lab_path)
print("parameter path: " + para_path)
 
# 使用配置文件初始化特征抽取器
extractor = FEE.RadiomicsFeatureExtractor(para_path)
print ("Extraction parameters:\n\t", extractor.settings)
print ("Enabled filters:\n\t", extractor.enabledImagetypes)
print ("Enabled features:\n\t", extractor.enabledFeatures)
 
# 运行
result = extractor.execute(ori_path,lab_path)  #抽取特征
print ("Result type:", type(result))  # result is returned in a Python ordered dictionary
print ("")
print ("Calculated features")
for key, value in result.items():  #输出特征
    print ("\t", key, ":", value)

找到以下三个文件:

测试用图片:
pyradiomics\data\brain1_image.nrrd
pyradiomics\data\brain1_label.nrrd
测试用配置文件:'
pyradiomics\examples\exampleSettings\Params.yaml

在电脑任意位置,新建一文件夹,将上述提到的四个文件全部放入其中。

2.2. 运行

使用 terminal 打开上述文件夹,输入以下代码:

python test.py
回车运行之,即可正常输出。

—-

任何运行中出现的问题,烦请致电邮 repoexr@163.com

posted @ 2022-05-27 23:34  RepoXu  阅读(1210)  评论(0编辑  收藏  举报