【pyradiomics学习】——安装pyradiomics以及简单示例
作者:互联网
目录
数据集下载:
- https://www.jianguoyun.com/p/DcEwQq0Q45bOBxj09JYC (访问密码: gd8dmv)
示例代码
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2022/1/10 20:27
# @Author : @linlianqin
# @Site :
# @File : main.py
# @Software: PyCharm
# @description:
'''
pyradiomics学习
'''
import radiomics
from radiomics import featureextractor as FEE
# 文件名
ori_name = r'brain1_image.nrrd'
lab_name = r'brain1_label.nrrd'
para_name = r'Params.yaml'
# 文件全部路径
ori_path =ori_name
lab_path = lab_name
para_path = para_name
print("originl path: " + ori_path)
print("label path: " + lab_path)
print("parameter path: " + para_path)
# 使用配置文件初始化特征抽取器
# extractor = FEE.RadiomicsFeaturesExtractor(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)
参考文献:
注:在以上文章中会出现以下几个问题,目前均已经解决,上述我写的代码没有问题
bug修复
1、报错AttributeError: module 'radiomics.featureextractor' has no attribute 'RadiomicsFeaturesExtractor'
将RadiomicsFeaturesExtractor库修改为RadiomicsFeatureExtractor
2、ruamel.yaml.constructor.DuplicateKeyError: while constructing a mapping in "D:/Params.yaml", line 34, column 3 found duplicate key "shape" with value "None" (original value: "None") in "D:/Params.yaml", line 37, column 3 To suppress this check see: Departure from previous API — Python YAML package documentation-keys Duplicate keys will become an error in future releases, and are errors by default when using the new API.
将yaml配置文件中的第37行注释掉即可
3、AttributeError: 'RadiomicsFeatureExtractor' object has no attribute '_enabledImagetypes'
将:
print("Enabled filters:\n\t", extractor._enabledImagetypes) print("Enabled features:\n\t", extractor._enabledFeatures)修改为:
print("Enabled filters:\n\t", extractor.enabledImagetypes) print("Enabled features:\n\t", extractor.enabledFeatures)
运行结果:
标签:pyradiomics,name,extractor,示例,yaml,print,path,安装 来源: https://blog.csdn.net/qq_45769063/article/details/122418916