ValueError: Image/Mask geometry mismatch. Potential fix: increase tolerance using geometryTolerance, see Documentation:Usage:Customizing the Extraction:Settings:geometryTolerance for more information
具体代码如下
```python
> RuntimeError Traceback (most recent call last)
Cell In[47], line 4
2 imgname = 'A'+str(i)+' T1.nrrd'
3 maskname = 'A'+str(i)+' label.nrrd'
----> 4 featureVector = extractor.execute(imgname,maskname)
5 df_add = pd.DataFrame([featureVector])
6 data_A = pd.concat([data_A, df_add])
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\radiomics\featureextractor.py:276, in RadiomicsFeatureExtractor.execute(self, imageFilepath, maskFilepath, label, label_channel, voxelBased)
272 image, mask = self.loadImage(imageFilepath, maskFilepath, generalInfo, **_settings)
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)
278 # Update the mask if it had to be resampled
279 if correctedMask is not None:
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\radiomics\imageoperations.py:247, in checkMask(imageNode, maskNode, **kwargs)
243 raise ValueError('Image/Mask geometry mismatch. Potential fix: increase tolerance using geometryTolerance, '
244 'see Documentation:Usage:Customizing the Extraction:Settings:geometryTolerance for more '
245 'information')
246 else:
--> 247 raise e # unhandled error
249 logger.warning('Image/Mask geometry mismatch, attempting to correct Mask')
251 correctedMask = _correctMask(imageNode, maskNode, **kwargs) # Raises Value error if ROI outside image physical space
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\radiomics\imageoperations.py:228, in checkMask(imageNode, maskNode, **kwargs)
226 lsif = sitk.LabelStatisticsImageFilter()
227 try:
--> 228 lsif.Execute(imageNode, maskNode)
230 # If lsif fails, and mask is corrected, it includes a check whether the label is present. Therefore, perform
231 # this test here only if lsif does not fail on the first attempt.
232 if label not in lsif.GetLabels():
File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\SimpleITK\SimpleITK.py:37612, in LabelStatisticsImageFilter.Execute(self, image, labelImage)
37603 def Execute(self, image, labelImage):
37604 r"""
37605 Execute(LabelStatisticsImageFilter self, Image image, Image labelImage)
37606
(...)
37610
37611 """
> 37612 return _SimpleITK.LabelStatisticsImageFilter_Execute(self, image, labelImage)
RuntimeError: Exception thrown in SimpleITK LabelStatisticsImageFilter_Execute: D:\a\1\sitk\Code\BasicFilters\src\sitkImageFilter.cxx:63:
sitk::ERROR: Input "labelImage" for "LabelStatisticsImageFilter" has size of [ 512, 512, 20 ] which does not match the primary input's size of [ 512, 512, 22 ]!
```
引用chatGPT作答,这个错误提示意味着您正在尝试使用具有不同几何形状的图像和掩模进行特征提取,因此您需要调整几何容差设置。为了解决这个问题,您可以在调用execute()方法时使用geometryTolerance参数,并将其设置为足够高的值以容忍掩模和图像之间的轻微几何差异。这样,在您的代码中,将execute()方法改为:
featureVector = extractor.execute(imgname,maskname,geometryTolerance=1e-3)
然后,可以逐渐增加容差值,直到您得到可以接受的特征提取结果。