ITK 分水岭算法

https://vtk.org/Wiki/ITK/Examples/Segmentation/WatershedImageFilter

https://itk.org/Doxygen/html/Examples_2Segmentation_2WatershedSegmentation1_8cxx-example.html

这两个都可以参考,结果最后是转化为RGB彩图的,大致效果是这样的,里面参数threshold、level可以调试。

主要的代码是这些:

    typedef   float PixelType;
    const     unsigned int    Dim = 2;
    typedef itk::Image< PixelType, Dim >  floatImageType;
    typedef itk::RGBPixel<unsigned char>       RGBPixelType;
    typedef itk::Image<RGBPixelType, Dim>        RGBImageType;
    typedef itk::Image<itk::IdentifierType, Dim> LabeledImageType; 

    typedef itk::MedianImageFilter<floatImageType,floatImageType> MedianFilterType;
    MedianFilterType::Pointer medianFilter = MedianFilterType::New();
    medianFilter->SetRadius(3);
    medianFilter->SetInput(intensityFilter->GetOutput());
    medianFilter->Update();
    
    typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<floatImageType,floatImageType >  GradientFilterType;
    GradientFilterType::Pointer  gradientMagnitude = GradientFilterType::New();
    gradientMagnitude->SetInput( medianFilter->GetOutput() );
    gradientMagnitude->SetSigma( 1 );
    gradientMagnitude->Update();
    
    // Custom parameters
    typedef itk::WatershedImageFilter<floatImageType> WatershedFilterType;
    WatershedFilterType::Pointer watershed = WatershedFilterType::New();
    watershed->SetThreshold(0.003);
    watershed->SetLevel(0.25);
    watershed->SetInput(gradientMagnitude->GetOutput());
    watershed->Update();
    
    typedef itk::ScalarToRGBColormapImageFilter<LabeledImageType, RGBImageType> RGBFilterType;
    RGBFilterType::Pointer colormapImageFilter = RGBFilterType::New();
    colormapImageFilter->SetInput(watershed->GetOutput());
    colormapImageFilter->SetColormap( RGBFilterType::Jet );
    colormapImageFilter->Update();

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值