资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

R语言怎么实现二值化分割

这篇“R语言怎么实现二值化分割”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“R语言怎么实现二值化分割”文章吧。

在广元等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供做网站、成都网站设计 网站设计制作按需求定制开发,公司网站建设,企业网站建设,品牌网站设计,营销型网站建设,成都外贸网站制作,广元网站建设费用合理。

原理讲解

ITK 中的二值化分割主要用到 itk::BinaryThresholdImageFilter 过滤器,其分割原理图如下:

R语言怎么实现二值化分割  

 

二值化分割是分割方法中最基础的,通过定义 Lower 和 Upper 两个像素临界点

R语言怎么实现二值化分割
只要图像像素值在这者之间,则该像素值将改变为 Insidevalue;否则将改为 Outsidevalue;最终图像的像素值只有两种:Insidevalue 或者是 Outsidevalue;

注:上面的 Insidevalue、Outsidevalue、Lowervalue、Uppervalue 四个参数是用户自己设定的。

代码实现

上文已经提到了,二值化分割主要用到的头文件为 itkBinaryThresholdImageFilter ,该过滤器主要通过设置四个参数来完成分割效果。

下面的代码部分就是关于二值分割的功能实现,代码中,依次进行图像读取、参数设定、二值化处理、图像写出等一系列步骤

#include
#include
#include
#include
#include
#include

using namespace std;

int Binary_Threshold()
{

    itk::PNGImageIOFactory::RegisterOneFactory();

    string input_name = "D:/ceshi1/ITK/Filter/Threshold_Seg/input.png";
    string output_name = "D:/ceshi1/ITK/Filter/Threshold_Seg/output.png";


    using InputPixelType = unsigned char;
    using OutputPixelType = unsigned char;

    using InputImageType = itk::Image;
    using OutputImageType = itk::Image;

    using FilterType = itk::BinaryThresholdImageFilter;

    using ReaderType = itk::ImageFileReader;
    using WriterType = itk::ImageFileWriter;

    ReaderType::Pointer reader = ReaderType::New();
    WriterType::Pointer writer = WriterType::New();

    FilterType::Pointer filter = FilterType::New();

    reader->SetFileName(input_name);

    filter->SetInput(reader->GetOutput());
    writer->SetInput(filter->GetOutput());
    writer->SetFileName(output_name);

    const OutputPixelType  outsidevalue = 0;
    const InputPixelType  insidevalue = 255;

    filter->SetOutsideValue(outsidevalue);
    filter->SetInsideValue(insidevalue);

    const InputPixelType lowerThreshold = 150;
    const OutputPixelType upperThreshold = 180;


    filter->SetUpperThreshold(upperThreshold);
    filter->SetLowerThreshold(lowerThreshold);

    try
    {
        filter->Update();// Running Filter;
        writer->Update();//Runing Writer;

    }
    catch(exception &e)
    {
        cout << "Caught Error!" << endl;
        cout << e.what() << endl;

        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;

}

这里 Insidevalue 设置为 0 (黑色),Outsidevalue 设置为 255(白色);阈值分割区间设为 (150,180 );选取的分割图像为 ITK 官方提供的脑部切片 PNG 图片,最终的分割结果如下

R语言怎么实现二值化分割

以上就是关于“R语言怎么实现二值化分割”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注创新互联行业资讯频道。


本文名称:R语言怎么实现二值化分割
分享路径:http://cdkjz.cn/article/gejcpo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220