美文网首页
pyradiomics特征提取过程中报错

pyradiomics特征提取过程中报错

作者: CrimsonUMO | 来源:发表于2022-11-15 21:39 被阅读0次

    安装好pyradiomics可以正常import之后,尝试用示例数据运行一下流程,在提取特征这一步出了问题。

    result = extractor.execute(imagePath, maskPath)
    

    运行之后显示报错

    result = extractor.execute(imagePath, maskPath)
    Traceback (most recent call last):
    
      File "C:\Users\LeiLei\AppData\Local\Temp\ipykernel_15372\454753011.py", line 1, in <module>
        result = extractor.execute(imagePath, maskPath)
    
      File "C:\Users\LeiLei\anaconda3\envs\radio\lib\site-packages\radiomics\featureextractor.py", line 325, in execute
        featureVector.update(self.computeFeatures(inputImage, inputMask, imageTypeName, **inputKwargs))
    
      File "C:\Users\LeiLei\anaconda3\envs\radio\lib\site-packages\radiomics\featureextractor.py", line 501, in computeFeatures
        for (featureName, featureValue) in six.iteritems(featureClass.execute()):
    
      File "C:\Users\LeiLei\anaconda3\envs\radio\lib\site-packages\radiomics\base.py", line 185, in execute
        self._calculateSegment()
    
      File "C:\Users\LeiLei\anaconda3\envs\radio\lib\site-packages\radiomics\base.py", line 227, in _calculateSegment
        for success, featureName, featureValue in self._calculateFeatures():
    
      File "C:\Users\LeiLei\anaconda3\envs\radio\lib\site-packages\radiomics\base.py", line 234, in _calculateFeatures
        self._initCalculation(voxelCoordinates)
    
      File "C:\Users\LeiLei\anaconda3\envs\radio\lib\site-packages\radiomics\glcm.py", line 111, in _initCalculation
        self.P_glcm = self._calculateMatrix(voxelCoordinates)
    
      File "C:\Users\LeiLei\anaconda3\envs\radio\lib\site-packages\radiomics\glcm.py", line 148, in _calculateMatrix
        P_glcm = numpy.delete(P_glcm, emptyGrayLevels - 1, 1)
    
      File "<__array_function__ internals>", line 6, in delete
    
      File "C:\Users\LeiLei\anaconda3\envs\radio\lib\site-packages\numpy\lib\function_base.py", line 4552, in delete
        keep[obj,] = False
    
    IndexError: arrays used as indices must be of integer (or boolean) type
    

    参照github的问答(https://github.com/AIM-Harvard/pyradiomics/issues/592),把imageoperations.py里的代码改了一下,在第157行增加了一小段。

    原来:
      return parameterMatrix, binEdges
    现在:
      return parameterMatrix.astype('int'), binEdges
    

    问题没有解决,继续找,看到有人说修改glcm.py文件。在该文件的148行增加一条语句:

        if list(emptyGrayLevels):
    

    变成:

        if list(emptyGrayLevels):
          P_glcm = numpy.delete(P_glcm, emptyGrayLevels - 1, 1)
          P_glcm = numpy.delete(P_glcm, emptyGrayLevels - 1, 2)
    

    还是报错
    然后我就把pyradiomics移除重新安装了一下,还是不行。现在开始怀疑是不是包的问题。
    但是我换了示例数据run一下,就没问题了。
    所以问题还是出在示例数据上。Brain1这个示例数据不对劲。
    这个故事告诉我们,不要迷信示例数据。弹报错的时候先检查数据本身可能是更便捷的思路。

    相关文章

      网友评论

          本文标题:pyradiomics特征提取过程中报错

          本文链接:https://www.haomeiwen.com/subject/uwasxdtx.html