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.17k stars 497 forks source link

How to select the ROI from multiple ROIs in one segmentation file? #802

Open Leylaastro opened 1 year ago

Leylaastro commented 1 year ago

Hi, For each study I have one 3D CT file and one segmentation file with multiple ROIs. I have two questions: 1- How can I know how many ROIs are in the segmenation file. 2- How can I extract radiomics for the ROIs one by one? I know that to select the desired ROI in which I am interested to extract the radiomics I should identify 'label', and each time I can only extract the radiomics for one ROI, right? But how can I know about the value of the labels? Imagine that I have 5 ROIs in one segmentation file and I only need to extract the features for the 2nd ROI or for the one which is labelled as 'Tumor' in the SEG dicom file. How can I specify it with 'label' in the execute function of pyradiomics?

Ianyliu commented 1 year ago

Hi @Leylaastro I might be able to answer some of your questions.

  1. To know how many ROIs are in a segmentation file you might want to count the number of labels in the segmentation file.
  2. One way to extract radiomics for the ROI one by one is to separate the segmentation file into multiple files so that each file only has 1 label or ROI. Below is an example of in which I load the AAL atlas (consists of 116 labels/ROIs) and save them as separate masks/segmentation files.
# Load the AAL atlas
atlas_img = nib.load(aal_file_path)

# Get the atlas data
atlas_data = atlas_img.get_fdata()

# Loop through the region labels and create binary masks
for region in range(1, 117):
    # Create a binary mask for the current region
    mask = np.zeros_like(atlas_data)
    mask[atlas_data == region] = 1

    # Save the mask to a file
    nib.save(nib.Nifti1Image(mask, atlas_img.affine), f'{region}.nii.gz')

Regarding the other questions, such as how to determine which ROI is the one we're interested in, you might want to try opening up the semgentation file 3D Slicer, which has a SlicerRadiomics extension. In 3D Slicer, you should be able to visually see the labels of each ROI and conduct radiomics feature extraction on one of the segmentations. (If not then you might have to split the segmentation file into multiple files like aforementioned so that each file only has 1 label or ROI).

I'm not sure if this is directly related but I hope this helps!