Simpleitk:我可以在一个步骤中对多个图像使用单个标签吗?
Simpleitk: Can I use single label for multiple images in one step?
我有一个标签,我想申请4张联合注册的图像,以获得每张标签上的平均值。目前,我要写4次代码。
我当前的代码是
import SimpleITK as sitk
import numpy as np
label = sitk.ReadImage('segmentation.nii.gz')
image1 = sitk.ReadImage('image1.nii')
image2 = sitk.ReadImage('image2.nii')
image3 = sitk.ReadImage('image3.nii')
image4 = sitk.ReadImage('image4.nii')
labelstatsFilter = sitk.LabelStatisticsImageFilter()
labelstatsFilter.SetUseHistograms(True)
labelstatsFilter.Execute(image1, label)
labelstatsFilter.GetMean(1)
labelstatsFilter.Execute(image2, label)
labelstatsFilter.GetMean(1)
labelstatsFilter.Execute(image3, label)
labelstatsFilter.GetMean(1)
labelstatsFilter.Execute(image4, label)
labelstatsFilter.GetMean(1)
您可以使用循环,但您仍然需要使用 LabelStatisticsImageFilter 4 次。没有办法让 1 个执行调用计算 4 个不同图像的统计数据。
代码的循环版本如下所示:
import SimpleITK as sitk
label = sitk.ReadImage('segmentation.nii.gz')
images = []
means = []
labelstatsFilter = sitk.LabelStatisticsImageFilter()
labelstatsFilter.SetUseHistograms(True)
for i in range(4):
images.append( sitk.ReadImage('image'+str(i)+'.nii') )
labelstatsFilter.Execute( images[i], label )
means.append( labelstatsFilter.GetMean(1) )
我有一个标签,我想申请4张联合注册的图像,以获得每张标签上的平均值。目前,我要写4次代码。
我当前的代码是
import SimpleITK as sitk
import numpy as np
label = sitk.ReadImage('segmentation.nii.gz')
image1 = sitk.ReadImage('image1.nii')
image2 = sitk.ReadImage('image2.nii')
image3 = sitk.ReadImage('image3.nii')
image4 = sitk.ReadImage('image4.nii')
labelstatsFilter = sitk.LabelStatisticsImageFilter()
labelstatsFilter.SetUseHistograms(True)
labelstatsFilter.Execute(image1, label)
labelstatsFilter.GetMean(1)
labelstatsFilter.Execute(image2, label)
labelstatsFilter.GetMean(1)
labelstatsFilter.Execute(image3, label)
labelstatsFilter.GetMean(1)
labelstatsFilter.Execute(image4, label)
labelstatsFilter.GetMean(1)
您可以使用循环,但您仍然需要使用 LabelStatisticsImageFilter 4 次。没有办法让 1 个执行调用计算 4 个不同图像的统计数据。
代码的循环版本如下所示:
import SimpleITK as sitk
label = sitk.ReadImage('segmentation.nii.gz')
images = []
means = []
labelstatsFilter = sitk.LabelStatisticsImageFilter()
labelstatsFilter.SetUseHistograms(True)
for i in range(4):
images.append( sitk.ReadImage('image'+str(i)+'.nii') )
labelstatsFilter.Execute( images[i], label )
means.append( labelstatsFilter.GetMean(1) )