sitk.LabelIntensityStatisticsImageFilter 不工作
sitk.LabelIntensityStatisticsImageFilter not working
我正在尝试使用 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 非常棒,但在我看来,它们的错误消息不是很有帮助。老实说,当您将过滤器传递给 labelstatFilter 时,您只缺少一个 () 。我只将这个特定的过滤器与连接的组件过滤器结合使用(例如):
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)
我正在尝试使用 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 非常棒,但在我看来,它们的错误消息不是很有帮助。老实说,当您将过滤器传递给 labelstatFilter 时,您只缺少一个 () 。我只将这个特定的过滤器与连接的组件过滤器结合使用(例如):
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)