网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

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://bjjierui.cn/article/gejcpo.html

其他资讯