IndexError при расчете GLCM с использованием PyRadiomics в Python 3.10Python

Программы на Python
Ответить
Anonymous
 IndexError при расчете GLCM с использованием PyRadiomics в Python 3.10

Сообщение Anonymous »

Я использую библиотеку PyRadiomics для извлечения признаков из медицинских изображений. При запуске кода я сталкиваюсь с ошибкой IndexError при попытке вычислить матрицу совпадения уровней серого (GLCM).

Код: Выделить всё

import radiomics
from radiomics import featureextractor
import SimpleITK as sitk

extractor = featureextractor.RadiomicsFeatureExtractor()

d = {}
for imagen, mask in lista_imagenes:
if imagen not in skip_data:
print(imagen.replace('\\','/'), mask.replace('\\','/'))
result = extractor.execute(imagen.replace('\\','/'), mask.replace('\\','/'))
d[imagen] = result

Сообщение об ошибке:

Код: Выделить всё

IndexError: Calculation of GLCM Failed.
Полная обратная трассировка:

Код: Выделить всё

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[55], line 7
5 if imagen not in skip_data:
6     print(imagen.replace('\\','/'), mask.replace('\\','/'))
----> 7     result = extractor.execute(imagen.replace('\\','/'), mask.replace('\\','/'))
8     d[imagen] = result
9     img = sitk.GetArrayFromImage(sitk.ReadImage(imagen.replace('\\','/')))

File c:\Python310\lib\site-packages\radiomics\featureextractor.py:330, in RadiomicsFeatureExtractor.execute(self, imageFilepath, maskFilepath, label, label_channel, voxelBased)
328   logger.info('Calculating features for %s image', imageTypeName)
329   inputImage, inputMask = imageoperations.cropToTumorMask(inputImage, mask, boundingBox, padDistance=kernelRadius)
--> 330   featureVector.update(self.computeFeatures(inputImage, inputMask, imageTypeName, **inputKwargs))

File c:\Python310\lib\site-packages\radiomics\featureextractor.py:517, in RadiomicsFeatureExtractor.computeFeatures(self, image, mask, imageTypeName, **kwargs)
514   for feature in featureNames:
515     featureClass.enableFeatureByName(feature)
--> 517 for (featureName, featureValue) in six.iteritems(featureClass.execute()):
518   newFeatureName = '%s_%s_%s' % (imageTypeName, featureClassName, featureName)
519   featureVector[newFeatureName] = featureValue

File c:\Python310\lib\site-packages\radiomics\base.py:185, in RadiomicsFeaturesBase.execute(self)
183   self._calculateVoxels()
184 else:
--> 185   self._calculateSegment()

File c:\Python310\lib\site-packages\radiomics\base.py:224, in RadiomicsFeaturesBase._calculateSegment(self)
222 def _calculateSegment(self):
223   # Get the feature values using the current segment.
--> 224   for success, featureName, featureValue in self._calculateFeatures():
225     # Always store the result. In case of an error, featureValue will be NaN
226     self.featureValues[featureName] = numpy.squeeze(featureValue)

File c:\Python310\lib\site-packages\radiomics\base.py:231, in RadiomicsFeaturesBase._calculateFeatures(self, voxelCoordinates)
228 def _calculateFeatures(self, voxelCoordinates=None):
229   # Initialize the calculation
230   # This function serves to calculate the texture matrices where applicable
--> 231   self._initCalculation(voxelCoordinates)

File c:\Python310\lib\site-packages\radiomics\glcm.py:111, in RadiomicsGLCM._initCalculation(self, voxelCoordinates)
110 def _initCalculation(self, voxelCoordinates=None):
--> 111   self.P_glcm = self._calculateMatrix(voxelCoordinates)
113   self._calculateCoefficients()
115   self.logger.debug('GLCM feature class initialized, calculated GLCM with shape %s', self.P_glcm.shape)

File c:\Python310\lib\site-packages\radiomics\glcm.py:139, in RadiomicsGLCM._calculateMatrix(self, voxelCoordinates)
136 if self.voxelBased:
137   matrix_args += [self.settings.get('kernelRadius', 1), voxelCoordinates]
--> 139 P_glcm, angles = cMatrices.calculate_glcm(*matrix_args)
141 self.logger.debug('Process calculated matrix')
143 # Delete rows and columns that specify gray levels not present in the ROI

IndexError: Calculation of GLCM Failed.

Что я пробовал:

[*]Проверил правильность путей к изображению и маске
[*]Убедился, что файлы существуют и доступны
[*]Пробовал различные конфигурации параметров в RadiomicsFeatureExtractor


Подробнее здесь: https://stackoverflow.com/questions/792 ... ython-3-10
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»