做社交網(wǎng)站多少錢網(wǎng)絡(luò)推廣是干什么的
效果:
Video:
區(qū)域增加分割
1、itkThresholdImageFilter
該類的主要功能是通過設(shè)置低閾值、高閾值或介于高低閾值之間,則將圖像值輸出為用戶指定的值。
如果圖像值低于、高于或介于設(shè)置的閾值之間,該類就將圖像值設(shè)置為用戶指定的“外部”值(默認(rèn)情況下為“黑色”)。
該類并不對像素進(jìn)行二值化處理,輸出圖像中的像素值可以是浮點型或整型。
常用的成員函數(shù):
Set/GetLower():設(shè)置/獲取下限閾值Set/GetUpper():設(shè)置/獲取上限閾值Set/GetOutsideValue():設(shè)置/獲取“外部”像素值ThresholdAbove():將大于或等于該閾值的值設(shè)置為OutsideValueThresholdBelow():將小于或等于該閾值的值設(shè)置為OutsideValueThresholdOutside():將超出上下限閾值范圍的值設(shè)置為 OutsideValue
?Example:
#include "itkImage.h"
#include "itkThresholdImageFilter.h";using namespace itk;const unsigned int Dimension = 3; //數(shù)據(jù)的Dimension
typedef signed short shortPixelType;
typedef itk::Image<shortPixelType, Dimension> ShortImageType;//圖像進(jìn)行閾值分割處理
bool thresholdImage(ShortImageType* image, ShortImageType* outImage)
{const short lowerThr = 200; //設(shè)置下閾值const short upperThr = 1000; //設(shè)置上閾值short outsideValue = 0; typedef ThresholdImageFilter<ShortImageType> thresholdFilterType;typename thresholdFilterType::Pointer thresholder = thresholdFilterType::New();thresholder->SetInput(image);thresholder->SetOutsideValue(outsideValue);設(shè)置上下閾值//thresholder->SetLower(lowerThr);//thresholder->SetUpper(upperThr);//<下閾值的值均設(shè)為outsideValuethresholder->ThresholdBelow(lowerThr);try{thresholder->Update();}catch (itk::ExceptionObject& ex){//讀取過程發(fā)生錯誤std::cerr << "Error: " << ex << std::endl;return false;}//>上閾值的值均設(shè)為outsideValuethresholder->ThresholdAbove(upperThr);try{thresholder->Update();}catch (itk::ExceptionObject& ex){//讀取過程發(fā)生錯誤std::cerr << "Error: " << ex << std::endl;return false;}//介于閾值之外的值均設(shè)為outsideValuethresholder->ThresholdOutside(lowerThr, upperThr);try{thresholder->Update();}catch (itk::ExceptionObject& ex){//讀取過程發(fā)生錯誤std::cerr << "Error: " << ex << std::endl;return false;}outImage = thresholder->GetOutput();return true;
}
2、itkBinaryThresholdImageFilter
2、itkBinaryThresholdImageFilter
該類的主要功能是通過閾值處理,將輸入圖像進(jìn)行二值化。
輸出的圖像像素只有兩個值:OutsideValue或者InsideValue,具體取決于相應(yīng)的輸入圖像像素是否位于高低閾值LowerThreshold和UpperThreshold之間,其中當(dāng)像素值等于任一閾值時,被認(rèn)為是在閾值之間。
?
?
注意:LowerThreshold不得大于UpperThreshold ,否則會引發(fā)異常。
因此,通常僅需要設(shè)置其中之一,具體取決于用戶是否希望閾值高于或低于期望閾值。
常用的成員函數(shù):
Set/GetInsideValue():設(shè)置/獲取“內(nèi)部”像素值Set/GetOutsideValue():設(shè)置/獲取“外部”像素值Set/GetLowerThreshold():設(shè)置/獲取低閾值Set/GetUpperThreshold():設(shè)置/獲取高閾值
與itkThresholdImageFilter相比較,itkBinaryThresholdImageFilter更適用于將圖像根據(jù)兩個閾值進(jìn)行二值化處理,而itkThresholdImageFilter適用于將圖像中符合條件的像素值映射為特定的數(shù)值。
Example:
#include "itkImage.h"
#include "itkBinaryThresholdImageFilter.h";using namespace itk;const unsigned int Dimension = 3; //數(shù)據(jù)的Dimension
typedef signed short shortPixelType;
typedef itk::Image<shortPixelType, Dimension> ShortImageType;//圖像進(jìn)行二值化閾值分割處理
bool binaryThresholdImage(ShortImageType* image, ShortImageType* outImage)
{const short lowerThr = 0; //設(shè)置二值化的下閾值const short upperThr = 1000; //設(shè)置二值化的上閾值short backGround = 0; //設(shè)置背景值short foreGround = 255; //設(shè)置前景值typedef BinaryThresholdImageFilter<ShortImageType, ShortImageType> BThresholdFilterType;typename BThresholdFilterType::Pointer thresholder = BThresholdFilterType::New();thresholder->SetInput(image);thresholder->SetOutsideValue(backGround);thresholder->SetInsideValue(foreGround);thresholder->SetLowerThreshold(lowerThr);thresholder->SetUpperThreshold(upperThr);try{thresholder->Update();}catch (itk::ExceptionObject& ex){//讀取過程發(fā)生錯誤std::cerr << "Error: " << ex << std::endl;return false;}outImage = thresholder->GetOutput();return true;
}
3、itkOtsuThresholdImageFilter
該類的功能是使用最大類間方差法Otsu閾值設(shè)置圖像閾值。
最大類間方差法:是由日本學(xué)者大津(Nobuyuki Otsu)于1979年提出的,是一種自適合于雙峰情況的自動求取閾值的方法,又叫大津法,簡稱Otsu。是一種基于全局的二值化算法。
它是按圖像的灰度特性,將圖像分成背景和目標(biāo)兩部分。背景和目標(biāo)之間的類間方差越大,說明構(gòu)成圖像的2部分的差別越大,當(dāng)部分目標(biāo)錯分為背景或部分背景錯分為目標(biāo)都會導(dǎo)致2部分差別變小。因此,使類間方差最大的分割意味著錯分概率最小。
常用的成員函數(shù):
Set/GetInsideValue():設(shè)置/獲取“內(nèi)部”像素值
Set/GetOutsideValue():設(shè)置/獲取“外部”像素值
Set/GetReturnBinMidpoint():設(shè)置/獲取閾值是bin的中點還是最大值? 默認(rèn)值是 bin 最大值
ReturnBinMidpointOn():設(shè)置/獲取閾值是bin的中點還是最大值? 默認(rèn)值是 bin 最大值
VerifyPreconditions():驗證先決條件,驗證過程對象是否已正確配置、所有必需的輸入是否已設(shè)置以及所需的參數(shù)是否已正確設(shè)置, 如果無效,將拋出異常,在將 UpdateOutputInformation() 傳播到輸入之前調(diào)用此方法,ProcessObject 的實現(xiàn)驗證 m_NumberOfRequiredInputs 是否已設(shè)置且不為空
Code
#include "itkImage.h"
#include "itkOtsuThresholdImageFilter.h"using namespace itk;const unsigned int Dimension = 3; //數(shù)據(jù)的Dimension
typedef signed short shortPixelType;
typedef itk::Image<shortPixelType, Dimension> ShortImageType;bool OtsuThresholdImage(ShortImageType* image, ShortImageType* outImage)
{short outsideValue = 0; //設(shè)置前景背景值short insideValue = 255;typedef OtsuThresholdImageFilter<ShortImageType, ShortImageType> OtsuThresholdFilterType;typename OtsuThresholdFilterType::Pointer thresholder = OtsuThresholdFilterType::New();thresholder->SetInput(image);thresholder->SetOutsideValue(outsideValue);thresholder->SetInsideValue(insideValue);try{thresholder->Update();}catch (itk::ExceptionObject& ex){//讀取過程發(fā)生錯誤std::cerr << "Error: " << ex << std::endl;return false;}outImage = thresholder->GetOutput();return true;
}
4、itkConnectedThresholdImageFilter
該類的功能是標(biāo)記連接到種子并位于值范圍內(nèi)的像素。
該類使用ReplaceValue標(biāo)記連接到初始種子且位于閾值下限和上限范圍內(nèi)的像素。
與itkThresholdImageFilter等前幾個類相比,它們雖然都是根據(jù)不同像素的灰度值或像素特征將圖像分割成不同的區(qū)域,但是此類不同的是基于連接像素的原理,通過選擇與種子像素相連的像素來進(jìn)行分割,分割的結(jié)果是連通區(qū)域,可以靈活地選擇不同的種子點和連接條件,得到不同的連通區(qū)域。
itkConnectedThresholdImageFilter適用于分割具有明顯邊界的目標(biāo),可以得到分割結(jié)果中目標(biāo)區(qū)域的邊界比較平滑。而itkThresholdImageFilter/itkBinaryThresholdImageFilter適用于分割目標(biāo)灰度值較高或較低的區(qū)域,可以得到目標(biāo)區(qū)域與背景的清晰分割
常用的成員函數(shù):
AddSeed():增加種子點
ClearSeeds():清除種子列表
SetSeed():設(shè)置種子點
GetSeeds():獲取種子容器
Set/GetLower():設(shè)置/獲取下限閾值
Set/GetUpper():設(shè)置/獲取上限閾值
Set/GetUpperInput():設(shè)置/獲取連接到管道的上閾值輸入
Set/GetLowerInput():設(shè)置/獲取連接到管道的下閾值輸入
SetConnectivity():要使用的連接類型(完全連接或 4(2D)、6(3D)、2*N(ND) 連接)
Set/GetReplaceValue():設(shè)置/獲取值以替換閾值像素, 介于Lower和Upper(含)內(nèi)的像素將被替換為該值, 默認(rèn)值為 1
Code:
#include "itkImage.h"
#include "itkConnectedThresholdImageFilter.h"using namespace itk;const unsigned int Dimension = 3; //數(shù)據(jù)的Dimension
typedef signed short shortPixelType;
typedef itk::Image<shortPixelType, Dimension> ShortImageType;bool connectedThresholdImage(ShortImageType* image, ShortImageType* outImage)
{const short lowerThr = 0; //設(shè)置二值化的上下閾值const short upperThr = 1000;const short replaceValue = 255;ShortImageType::IndexType seed;seed[0] = 100; //該值必須在圖像的三維大小范圍內(nèi)seed[1] = 100;seed[2] = 25;typedef ConnectedThresholdImageFilter<ShortImageType, ShortImageType> ConnectedThresholdFilterType;typename ConnectedThresholdFilterType::Pointer thresholder = ConnectedThresholdFilterType::New();thresholder->SetInput(image);thresholder->SetLower(lowerThr);thresholder->SetUpper(upperThr);thresholder->SetReplaceValue(replaceValue);thresholder->SetSeed(seed);try{thresholder->Update();}catch (itk::ExceptionObject& ex){//讀取過程發(fā)生錯誤std::cerr << "Error: " << ex << std::endl;return false;}outImage = thresholder->GetOutput();return true;
}