AIM-Harvard / pyradiomics

Open-source python package for the extraction of Radiomics features from 2D and 3D images and binary masks. Support: https://discourse.slicer.org/c/community/radiomics
http://pyradiomics.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.14k stars 494 forks source link

How to get the features from several labels as a whole #531

Closed kevin-why closed 2 years ago

kevin-why commented 4 years ago

Describe the bug When I use the pyradiomics,I wonder how to merge several labels into one label.(There are 4 labels in my test image, I need to extract the features of them as a whole)

PyRadiomics configuration I used the 【Params.yaml】download from here, I tried to modify the label number in the file. 【label:1→label:1,2.3.4】but unfortunately it doesn't work.

Version (please complete the following information):

JoostJM commented 4 years ago

@kevin-why,

currently, this is not possible if you use PyRadiomics on the command-line. However, in interactive Python it'll be quite easy:

import SimpleITK as sitk

from radiomics import featureextractor

ma = sitk.ReadImage(r'path/to/mask.nrrd')
ma_arr = sitk.GetArrrayFromImage(ma)
for l in (2, 3, 4):
  ma_arr[ma_arr == l] = 1

ma_merged = sitk.GetImageFromArray(ma_arr)
ma_merged.CopyInformation(ma)  # geometric information

extractor = featureextractor.RadiomicsFeatureExtractor(r'path/to/params.yaml')
features = extractor.execute(r'path/to/image.nrrd', ma_merged, label=1)  # You can pass in a SimpleITK.Image object directly for image and/or mask

# Features will be a dict with featurename:feature value