【影像组学pyradiomics教程】(三) 使用配置文件进行特征提取

该系列是为了记录自己学习的过程

一、配置文件的格式及内容

为了对图像进行处理,pyradiomics 允许将特征提取设置作为一个配置文件来进行处理图像,这个配置文件使用了yaml格式
具体可配置的主要是在简介中提到的一些允许提取的特征
如下示例:

# Settings to use, possible settings are listed in the documentation (section "Customizing the extraction").
setting:
  binWidth: 15
  label: 1
  interpolator: 'sitkBSpline' # This is an enumerated value, here None is not allowed
  resampledPixelSpacing: # This disables resampling, as it is interpreted as None, to enable it, specify spacing in x, y, z as [x, y , z]
  weightingNorm: # If no value is specified, it is interpreted as None
  geometryTolerance: 0.0001
  normalize: False

# Image types to use: "Original" for unfiltered image, for possible filters, see documentation.
imageType:
  Original: {}
  LoG:
    # If the in-plane spacing is large (> 2mm), consider removing sigma value 1.
    sigma: [3.0, 5.0]
  Wavelet: {}
  #Gradient: {}
# Featureclasses, from which features must be calculated. If a featureclass is not mentioned, no features are calculated
# for that class. Otherwise, the specified features are calculated, or, if none are specified, all are calculated.
featureClass:
  shape2D:  # disable redundant Compactness 1 and Compactness 2 features by specifying all other shape features
  firstorder: 
  glcm:  
  glrlm: # for lists none values are allowed, in this case, all features are enabled
  glszm:
  ngtdm:
  gldm:

二、使用配置文件初始化特征提取器

对于yaml问价配置和直接代码的设置具有同样的功效
代码中调用使用配置文件来初始化特征提取器即可:

import six
import numpy as np
from radiomics import featureextractor

img = "./brain1_image.nrrd"
lab = "./brain1_label.nrrd"

# 初始化特性提取器
extractor = featureextractor.RadiomicsFeatureExtractor('RadiomicsParams.yaml')

# 进行特征提取
result = extractor.execute(img, lab)
row = []
row_next = []
for idx, (key, val) in enumerate(six.iteritems(result)):
    if idx<11:  # 前面属于 数据的基本属性不属于提取的特征
        continue
    if not isinstance(val,(float,int,np.ndarray)):
        continue
    if np.isnan(val):
        val=0
    row.append(key)
    row_next.append(val)
print(row)
print(np.array(row_next))

三、结果

#特征名:
[ 'diagnostics_Image-original_Mean', 'diagnostics_Image-original_Minimum',....., 'wavelet-LLL_gldm_SmallDependenceLowGrayLevelEmphasis']
#特征值:
[3.85656408e+02 6.70325518e-01  .....  8.57149239e-04]

你可能感兴趣的:(【影像组学pyradiomics教程】(三) 使用配置文件进行特征提取)