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?
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.
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.
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.
@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).
Hi, I guess I have the same problem. I have a Dicom image and a mask I made (just a numpy array). I transformed both of them to stk image file and then I used the joinSeries function to have the 3 dimensions.
Right now, I was able to make only the first-order features. I guess I can not make shape features, but I would like the GLCM, GLSZM, and so on…
What kind of DICOM file(s) do you have? As it stands, I most often saw that DICOM is loaded as a 3D volume, even when it’s just a single file (e.g. single slice, but also X-Ray). JoinSeries may have the effect of concatenating in the 4th dimension, which is not really supported in PyRadiomics.
If you have volumetric DICOM with scalar pixel values (i.e. a grayscale image), I’d advise using a tool to convert them to a volumetric and SimpleITK-readable image format, such as NRRD (e.g. dicom2niix).
Additionally, the error you report is quite strange, as P_gldm is returned from the C-extension and should always be a numpy array. If the function fails, no array is returned, but the function will have thrown a RuntimeException instead, meaning that that line of code should not be reached.
Can you share the full log so I might look into this error?
The problem was the numpy version. I was using the 1.14 instead of the 1.17. I checked somewhere the requirements and I guess it should work with the 1.14 version.
About the DICOM file, the shape of the pixel data is 2 dimensional (Did I answer the question?). Using the joinSeries I got the (512,512,1) or (1,512,512), I can’t remember right now.
I would like to ask, is there some information in the metadata that is necessary in order to calculate the features? I am asking because I would like to work just with a nump_array transformed to stk image object.
Should I calculate the shape2D features with the “force2D = True” parameter? I was wondering if make any sense at all these features in my case.
Sorry if these questions are too much specific. If you need some information I would be glad to provide.
Thank you for the fast answer and once more for the amazing package
First of all, if your data is 2D, you don’t have to use the JoinSeries anymore. PyRadiomics now supports 2D input as well. Setting force2D=True has 2 use cases:
In case of 3D image input, whole volume segmentation (multi-slice) - Deals with out-of-plane voxel anisotropy (i.e. same spacing in-plane, but different slice thickness). By removing angle offsets that move between slices in texture calculation, the assumption in the feature formulas that the distance between neighboring voxels is equal is met. Sometimes this is described as the 2.5D approach. Otherwise you’d need to deal with this by resampling, or taking the distance between neigbors into account (e.g. matrix weighting)
In case of 3D image input, single slice segmentation - Allows for calculating 2D features, including shape2D, even though the input is 3D (i.e. image has 3 dimensions, even though a dimension may have size 1).
In your case, I’d say you fall under 2, so yes, I’d advise setting force2D=True and calculating shape2D.
P.s. this numpy version may need some investigating. Can you create an issue on the PyRadiomics github?