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 492 forks source link

how to get the quantity of ROIs in a mask #747

Open duduufonsecaa opened 2 years ago

duduufonsecaa commented 2 years ago

Hello everyone! I have several masks and several ROIs in each mask and I'm getting difficult to catch the number of labels (i.e some has 5 ROIs other 3, 2...). I'm doing an interative code to calculate the radiomics. I'm using windows 10, python 3.9 Thanks

JoostJM commented 2 years ago

I assume you're using the featureextractor? In the execute() function, you can pass the value of the label. Best way to extract then would be:

extractor = featureextractor.RadiomicsFeatureExtractor(params)
results = {}
for case_idx, im, mask in cases:
  labels = np.unique(sitk.GetArrayFromImage(mask))
  for l in labels:
    if l == 0:
      continue # don't extract for the background
    results[(case_idx, l) = extractor.execute(im, ma, label=l)
duduufonsecaa commented 2 years ago

I've done a directory in my Computer to save the color labels (ROIs) (in my code is 'labels'), then I've done a loop to read the .txt files and get the labels. Here is my code. The masks and labels is getting from 3DSlicer erythemaROI.txt Thanks for your answer.