Python 如何在itk中将图像二值化为标签图像

Python 如何在itk中将图像二值化为标签图像,python,image,label,itk,Python,Image,Label,Itk,我试着分析一幅用阈值滤波器进行二值化的图像,实际上把图像分成两部分,它们都包含在边界之外。然后我想把这个图像转换成一个标签图像二值图像-标签映射-标签图像,然后按标签进行分析 LabelFilter0 = itk.BinaryImageToLabelMapFilter.IUC3LM3.New() LabelFilter0.SetInput(BinaryFilter.GetOutput()) LabelFilter0.SetInputForegroundValue(100) LabelFilter

我试着分析一幅用阈值滤波器进行二值化的图像,实际上把图像分成两部分,它们都包含在边界之外。然后我想把这个图像转换成一个标签图像二值图像-标签映射-标签图像,然后按标签进行分析

LabelFilter0 = itk.BinaryImageToLabelMapFilter.IUC3LM3.New()
LabelFilter0.SetInput(BinaryFilter.GetOutput())
LabelFilter0.SetInputForegroundValue(100)
LabelFilter0.SetFullyConnected(False)
print LabelFilter0.GetNumberOfObjects()
LabelImage0 = itk.LabelMapToLabelImageFilter.LM3IUC3.New()
LabelImage0.SetInput(LabelFilter0.GetOutput())
Sta0Filter = itk.LabelStatisticsImageFilter.ISS3IUC3.New()
Sta0Filter.SetLabelInput(reader1.GetOutput())
Sta0Filter.SetInput(reader0.GetOutput())
但是,在itk.BinaryImageToLabelMapFilter之后找不到任何对象。我完全迷路了该怎么设置这个过滤器

以下是阈值后的3D数据:


有关如何使用LabelStatisticsImageFilter的示例,请参见ITK示例页面。它是C++的,但是这个想法是一样的,看起来像:

typedef itk::BinaryImageToLabelMapFilter<ImageType> BinaryImageToLabelMapFilterType;
BinaryImageToLabelMapFilterType::Pointer binaryImageToLabelMapFilter = BinaryImageToLabelMapFilterType::New();
binaryImageToLabelMapFilter->SetInput(image);
binaryImageToLabelMapFilter->Update();

typedef itk::LabelMapToLabelImageFilter<BinaryImageToLabelMapFilterType::OutputImageType, ImageType> LabelMapToLabelImageFilterType;
LabelMapToLabelImageFilterType::Pointer labelMapToLabelImageFilter = LabelMapToLabelImageFilterType::New();
labelMapToLabelImageFilter->SetInput(binaryImageToLabelMapFilter->GetOutput());
labelMapToLabelImageFilter->Update();

typedef itk::LabelStatisticsImageFilter< ImageType, ImageType > LabelStatisticsImageFilterType;
LabelStatisticsImageFilterType::Pointer labelStatisticsImageFilter = LabelStatisticsImageFilterType::New();
labelStatisticsImageFilter->SetLabelInput( labelMapToLabelImageFilter->GetOutput() );
labelStatisticsImageFilter->SetInput(image);
labelStatisticsImageFilter->Update();
在您的代码中,我没有看到触发管道启动所需的“更新”调用。你可能想先检查一下

我使用此过滤器的经验是,您可以将此过滤器直接连接到BinarySthresholdImageFilter的末尾以使用它