西特克.标签强度统计图像过滤器不起作用



我正在尝试使用sitk。LabelIntensityStatisticsImageFilter 用于计算图像中标签的一阶统计信息。

我的代码是

import SimpleITK as sitk
ADC600 = '/Users/omarkamal/PycharmProjects/DWI/Pt1/ADC600.nii'
ADC600_r = sitk.ReadImage(ADC600)
label = '/Users/omarkamal/PycharmProjects/DWI/Pt1/seg.nii.gz'
label = sitk.ReadImage(label)
labelstatsFilter = sitk.LabelIntensityStatisticsImageFilter
labelstatsFilter.Execute(ADC600_r, label)
Mean = labelstatsFilter.GetMean(1)
Kurtosis = labelstatsFilter.GetKurtosis(1)
print(Mean, Kurtosis)

我收到此错误:

Traceback (most recent call last):
File "/Users/omarkamal/PycharmProjects/DWI/Stats Extractor.py", line 21, in <module>
labelstatsFilter.Execute(ADC600_r, label)
File "/Users/omarkamal/anaconda3/envs/dicom/lib/python3.7/site-packages/SimpleITK/SimpleITK.py", line 41307, in Execute
return _SimpleITK.LabelIntensityStatisticsImageFilter_Execute(self, *args)
NotImplementedError: Wrong number or type of arguments for overloaded function 'LabelIntensityStatisticsImageFilter_Execute'.
Possible C/C++ prototypes are:
itk::simple::LabelIntensityStatisticsImageFilter::Execute(itk::simple::Image const &,itk::simple::Image const &)
itk::simple::LabelIntensityStatisticsImageFilter::Execute(itk::simple::Image const &,itk::simple::Image const &,double,bool,bool,uint32_t)

显然这个模块是在 C/C++ 中从 itk 借来的? 我该如何解决这个问题?

我还想计算我在 simpleITK 中找不到的熵。有什么想法吗?

SimpleITK非常棒,但在我看来,他们的错误消息不是很有帮助。老实说,当你将过滤器传递给标签统计过滤器时,你缺少的只是一个((。我只将此特定过滤器与连接的组件过滤器结合使用(例如(:

cc = sitk.ConnectedComponent(img, True)
stats = sitk.LabelIntensityStatisticsImageFilter()
stats.Execute(cc, img)

因此,我不确定修复后您是否会收到另一个错误。尽管如此,我还是写了一个函数,应该可以让您轻松测试它并检查一些常见错误(主要问题是图像必须重叠(:

def sitk_get_stats(inputImage, label):
"""
Function to get mean and Kurtosis from a labeled image
:param inputImage: Grey value volume readable by SimpleITK.
:param label: Grey value volume readable by SimpleITK that overlaps with the inputImage.
:return: Returns the mean and kurtosis of a labeled image.
"""
inputImage = str(inputImage)
label = str(label)
img = sitk.ReadImage(inputImage)
label = sitk.ReadImage(label)

# Get the size of the image in x, y, z. They have to overlap or you'll get an error.
size = img.GetSize()
print("Original image size: {}, {}, {}".format(size[0], size[1], size[2]))
size = label.GetSize()
print("Label image size: {}, {}, {}".format(size[0], size[1], size[2]))
#You were missing the () in your original implementation.
labelstatsFilter = sitk.LabelIntensityStatisticsImageFilter()
# SimpleITK collapses a lot of complexity by filling in defaults for you. 
# You can often adjust the default parameters, which you can expose by printing out the filter .
print(labelstatsFilter)
#Execute the filter. 
labelstatsFilter.Execute(label, img)
#Get the mean intensity value for the first label.
Mean = labelstatsFilter.GetMean(1)
#Get the kurtosis for the first label.
Kurtosis = labelstatsFilter.GetKurtosis(1)
print(Mean, Kurtosis)
#Return the values that you are curious about. 
return  Mean, Kurtosis

#Define you input image.
ADC600 = '/Users/omarkamal/PycharmProjects/DWI/Pt1/ADC600.nii'
#Define the overlapping label. 
label = '/Users/omarkamal/PycharmProjects/DWI/Pt1/seg.nii.gz'
#Put the results into objects so you can do something with them later. 
mean, kurtosis = sitk_get_stats(inputImage=ADC600, label=label)

最新更新