R語言怎么實現(xiàn)二值化分割

這篇“R語言怎么實現(xiàn)二值化分割”文章的知識點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“R語言怎么實現(xiàn)二值化分割”文章吧。

在廣元等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供做網(wǎng)站、成都網(wǎng)站設(shè)計 網(wǎng)站設(shè)計制作按需求定制開發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站設(shè)計,營銷型網(wǎng)站建設(shè),成都外貿(mào)網(wǎng)站制作,廣元網(wǎng)站建設(shè)費(fèi)用合理。

原理講解

ITK 中的二值化分割主要用到 itk::BinaryThresholdImageFilter 過濾器,其分割原理圖如下:

R語言怎么實現(xiàn)二值化分割  

 

二值化分割是分割方法中最基礎(chǔ)的,通過定義 Lower 和 Upper 兩個像素臨界點(diǎn)

R語言怎么實現(xiàn)二值化分割
只要圖像像素值在這者之間,則該像素值將改變?yōu)?Insidevalue;否則將改為 Outsidevalue;最終圖像的像素值只有兩種:Insidevalue 或者是 Outsidevalue;

注:上面的 Insidevalue、Outsidevalue、Lowervalue、Uppervalue 四個參數(shù)是用戶自己設(shè)定的。

代碼實現(xiàn)

上文已經(jīng)提到了,二值化分割主要用到的頭文件為 itkBinaryThresholdImageFilter ,該過濾器主要通過設(shè)置四個參數(shù)來完成分割效果。

下面的代碼部分就是關(guān)于二值分割的功能實現(xiàn),代碼中,依次進(jìn)行圖像讀取、參數(shù)設(shè)定、二值化處理、圖像寫出等一系列步驟

#include<itkBinaryThresholdImageFilter.h>
#include<itkImage.h>
#include<itkImageFileReader.h>
#include<itkImageFileWriter.h>
#include<itkPNGImageIOFactory.h>
#include<string.h>

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<InputPixelType, 2>;
    using OutputImageType = itk::Image<OutputPixelType, 2>;

    using FilterType = itk::BinaryThresholdImageFilter<InputImageType, OutputImageType>;

    using ReaderType = itk::ImageFileReader<InputImageType>;
    using WriterType = itk::ImageFileWriter<OutputImageType>;

    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 設(shè)置為 0 (黑色),Outsidevalue 設(shè)置為 255(白色);閾值分割區(qū)間設(shè)為 (150,180 );選取的分割圖像為 ITK 官方提供的腦部切片 PNG 圖片,最終的分割結(jié)果如下

R語言怎么實現(xiàn)二值化分割

以上就是關(guān)于“R語言怎么實現(xiàn)二值化分割”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對大家有幫助,若想了解更多相關(guān)的知識內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

名稱欄目:R語言怎么實現(xiàn)二值化分割
標(biāo)題來源:http://bm7419.com/article30/gejcpo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供響應(yīng)式網(wǎng)站電子商務(wù)、建站公司、網(wǎng)頁設(shè)計公司、搜索引擎優(yōu)化品牌網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計