PyRadiomics for 2D images (png or nrrd)

(Leonardo Machado) #1

Hi everyone,

I am trying to extract radiomic features from 2D images (PNG or Nrrd) but I start to get a series of errors saying basically “3D array expected”. When I do that directly on slicer it works well.

I’m using a python script, and I am importing PyRadiomics, but no success so far.
I’ve been adding “force2D”, “force2Dextraction”, and “force2Ddomension”, but none gave positive results.
Does anyone have extracted 2D radiomic features using Python Pyradiomics package or have any guess on how to solve it all?


(Andrey Fedorov) #2

Sounds like you are using this by calling extraction programmatically. Note that for using a 2d input, you would still need to read that 2d input into a 3d array with 3rd dimension = 1. Maybe that is what you are doing differently? Sharing the code snipped that you use would probably help.

1 Like
(Leonardo Machado) #3

Hey Andrey,

thanks, man.

Sorry for not posting parts of code as well. I thought it was a general problem. I guess, you got it right, though. I was inputting PNG files which are raw 2D files. I’ll try nrrd 3D files version and see how that goes. Thanks for the clue.


(Andrey Fedorov) #4

Let me try to clarify - you do not need to save input image as NRRD. What you do need is to read the PNG image as a 3d image. When you instantiate the ITK reader, you can make a reader that reads a 2d image, or 3d image. If you read PNG with a 3d image reader, you should get a 3d image with the 3rd dimension size of 1. That is what you need to pass down to pyradiomics.

Note that for the questions about pyradiomics specifically, it is better if you use the pyradiomics google group.

1 Like
(Joost Van Griethuysen) #5

@MachadoL,which version of PyRadiomics are you using? Since Feb 20th, most of PyRadiomics does support 2D input. However, some parts (e.g. the LoG filter) still require 3D images. Furthermore, when using PNG images, there is a second (and more difficult) problem: color channels.

PyRadiomics is designed for feature extraction from scalar images (i.e. 1 value for each pixel/voxel). PNG is often encoded as RGB, i.e. 3 values per pixel. Therefore, to extract features from PNG, some preprocessing is required, converting the 3 RGB values into one (e.g. by taking the mean, or a specific channel).

(Joost Van Griethuysen) #6

This topic on the PyRadiomics forum deals with this specific problem (although the solution is based on a version where PyRadiomics required 3D input always).

1 Like
(Leonardo Machado) #7

Great, @fedorov.

I got it!
I’ll work on my things and let you know if everything goes allright.

Thanks again.

1 Like
(Leonardo Machado) #8


I am using pyradiomics 2.1.2. I’ll try to update my package and let you guys know!