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

features extract with .png image #762

Closed 302850047 closed 2 years ago

302850047 commented 2 years ago

I want to extract features with HE image, it is .png format, the size is [1024, 1024, 3], and I want to extract features with whole image, so the label is a [1024, 1024] image with a value of 1. But I can't extract features. Here is my code:

image = sitk.ReadImage('test.png') mask_arr = np.ones(image.GetSize()[::-1]) mask = sitk.GetImageFromArray(mask_arr) firstOrderFeatures = firstorder.RadiomicsFirstOrder(image, mask)

Traceback (most recent call last): python-BaseException File "/data/chenzhi/.pycharm_helpers/pydev/pydevd.py", line 1483, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "/data/chenzhi/.pycharm_helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "/data/chenzhi/Chenjy/Pathomics/paper_repetition/features_extract.py", line 24, in firstOrderFeatures = firstorder.RadiomicsFirstOrder(image, mask) File "/data/chenzhi/.conda/envs/Chenjy/lib/python3.7/site-packages/radiomics/firstorder.py", line 37, in init self.discretizedImageArray = self._applyBinning(self.imageArray.copy()) File "/data/chenzhi/.conda/envs/Chenjy/lib/python3.7/site-packages/radiomics/base.py", line 115, in applyBinning matrix, = imageoperations.binImage(matrix, self.maskArray, self.settings) File "/data/chenzhi/.conda/envs/Chenjy/lib/python3.7/site-packages/radiomics/imageoperations.py", line 155, in binImage binEdges = getBinEdges(parameterMatrix[parameterMatrixCoordinates], kwargs) IndexError: boolean index did not match indexed array along dimension 1; dimension is 1024 but corresponding boolean dimension is 2024

JoostJM commented 2 years ago

1) Before you can extract from PNG, you first need to make the image a grayscale image. This is already often asked & answered in the issues of the repo 2) The error messages tells you what is going wrong: either the image or your mask is actually 2x the size (2024). I don't know where it is going wrong, as your stack trace shows you are using custom code to apply first order extraction. My advice would be to use PyRadiomics as it is intended; through use of the feature extractor module.