pyradiomics特征提取报错‘Image/Mask geometry mismatch. ‘

在使用PyRadiomics进行特征提取时遇到ValueError,提示Image/Mask geometry mismatch。解决方案是在Params.yaml设置文件中增加geometryTolerance参数,将其值适当增大,如设置为1e-5,以允许图像和掩模之间的小范围几何差异。这有助于解决因图像和掩模边界不完全匹配导致的问题。

报错详情

ValueError: Image/Mask geometry mismatch. Potential fix: increase tolerance using geometryTolerance, see Documentation:Usage:Customizing the Extraction:Settings:geometryTolerance for more information

Traceback (most recent call last):
  File "D:\project\mri_svm\4_feature_extraction.py", line 29, in <module>
    result = extractor.execute(mri_path, label_path)  # 提取特征
  File "D:\Anaconda\envs\jspt\lib\site-packages\pyradiomics-3.0.1.post15+g2791e23-py3.9-win-amd64.egg\radiomics\featureextractor.py", line 276, in execute
    boundingBox, correctedMask = imageoperations.checkMask(image, mask, **_settings)
  File "D:\Anaconda\envs\jspt\lib\site-packages\pyradiomics-3.0.1.post15+g2791e23-py3.9-win-amd64.egg\radiomics\imageoperations.py", line 243, in checkMask
    raise ValueError('Image/Mask geometry mismatch. Potential fix: increase tolerance using geometryTolerance, '
ValueError: Image/Mask geometry mismatch. Potential fix: increase tolerance using geometryTolerance, see Documentation:Usage:Customizing the Extraction:Settings:geometryTolerance for more information

解决方法

参考官方文档中关于setting的介绍:Customizing the Extraction

 在参数文件 Params.yaml 中的 setting: 部分添加 geometryTolerance 参数,见代码段最后一行。

setting:
  binWidth: 25
  label: 1
  interpolator: 'sitkBSpline'
  resampledPixelSpacing: 
  weightingNorm: 
  geometryTolerance: 1e-5

geometryTolerance参数默认为1e-16, 根据需要改大一些。

Image/Mask geometry mismatch, attempting to correct Mask 图像大小: (1024, 768) 图像原点: (0.0, 0.0) 图像间距: (1.0, 1.0) 图像方向: (1.0, 0.0, 0.0, 1.0) 掩码大小: (1024, 768, 1) 掩码原点: (0.0, 0.0, 0.0) 掩码间距: (1.0, 1.0, 1.0) 掩码方向: (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0) --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) D:\ruanjian\Anaconda3\lib\site-packages\radiomics\imageoperations.py in checkMask(imageNode, maskNode, **kwargs) 234 try: --> 235 lsif.Execute(imageNode, maskNode) 236 D:\ruanjian\Anaconda3\lib\site-packages\SimpleITK\SimpleITK.py in Execute(self, *args) 43957 """ > 43958 return _SimpleITK.LabelStatisticsImageFilter_Execute(self, *args) 43959 RuntimeError: Exception thrown in SimpleITK LabelStatisticsImageFilter_Execute: Code\BasicFilters\src\sitkLabelStatisticsImageFilter.cxx:134: sitk::ERROR: Both images for LabelStatisticsImageFilter don't match type or dimension! During handling of the above exception, another exception occurred: RuntimeError Traceback (most recent call last) <ipython-input-15-863fbd70eb0f> in <module> 30 31 # 执行特征提取 ---> 32 feature_1 = extractor.execute(image_path, mask_path) 33 34 # 打印提取的特征 D:\ruanjian\Anaconda3\lib\site-packages\radiomics\featureextractor.py in execute(self, imageFilepath, maskFilepath, label, label_channel, voxelBased) 274 # 2. Check whether loaded mask contains a valid ROI for feature extraction and get bounding box 275 # Raises a ValueError if the ROI is invalid --> 276 boundingBox, correctedMask = imageoperations.checkMask(image, mask, **_settings) 277 278 # Update the mask if it had to be resampled D:\ruanjian\Anaconda3\lib\site-packages\radiomics\imageoperations.py in checkMask(imageNode, maskNode, **kwargs) 256 logger.warning('Image/Mask geometry mismatch, attempting to correct Mask') 257 --> 258 correctedMask = _correctMask(imageNode, maskNode, **kwargs) # Raises Value error if ROI outside image physical space 259 260 # Resampling successful, try to calculate boundingbox D:\ruanjian\Anaconda3\lib\site-packages\radiomics\imageoperations.py in _correctMask(imageNode, maskNode, **kwargs) 300 logger.debug('Resampling mask to image geometry') 301 --> 302 _checkROI(imageNode, maskNode, **kwargs) # Raises a value error if ROI is invalid 303 304 rif = sitk.ResampleImageFilter() D:\ruanjian\Anaconda3\lib\site-packages\radiomics\imageoperations.py in _checkROI(imageNode, maskNode, **kwargs) 349 maskNode.TransformContinuousIndexToPhysicalPoint(bb[:Nd] + bb[Nd:] - 0.5)) # UBound 350 # Step 2: Translate the ROI physical bounds to the image coordinate space --> 351 ROIBounds = (imageNode.TransformPhysicalPointToContinuousIndex(ROIBounds[0]), # Origin 352 imageNode.TransformPhysicalPointToContinuousIndex(ROIBounds[1])) 353 D:\ruanjian\Anaconda3\lib\site-packages\SimpleITK\SimpleITK.py in TransformPhysicalPointToContinuousIndex(self, point) 3898 3899 """ -> 3900 return _SimpleITK.Image_TransformPhysicalPointToContinuousIndex(self, point) 3901 3902 RuntimeError: Exception thrown in SimpleITK Image_TransformPhysicalPointToContinuousIndex: d:\a\1\sitk\code\common\src\sitkPimpleImageBase.hxx:227: sitk::ERROR: vector dimension mismatch
06-28
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值