目录
1、itkNeighborhoodConnectedImageFilter 领域链接
该类的功能是标记连接到种子并位于邻域内的像素。
NeighborhoodConnectedImageFilter使用ReplaceValue标记连接到初始种子且其邻域位于上下阈值范围内的像素。
该滤波器是ConnectedThresholdImageFilter的一个相关变量,该类仅仅接受哪些所有相邻像素亮度在区间范围的数据,每个像素数据邻域大小是用户提供的整数范围来定义的。
常用的成员函数:
AddSeed()
:增加种子点ClearSeeds()
:清除种子列表SetSeed()
:设置种子点Set/GetRadius()
:设置/获取用于遮罩的邻域的半径Set/GetLower()
:设置/获取下限阈值Set/GetUpper()
:设置/获取上限阈值Set/GetReplaceValue()
:设置/获取值以替换阈值像素, 介于Lower和Upper(含)内的像素将被替换为该值, 默认值为 1
示例代码:
#include "itkImage.h"
#include "itkNeighborhoodConnectedImageFilter.h"
using namespace itk;
const unsigned int Dimension = 2; //数据的Dimension
typedef signed short shortPixelType;
typedef itk::Image<shortPixelType, Dimension> ShortImageType;
bool neighborhoodConnectedImage(ShortImageType* image, ShortImageType* outImage)
{
const short lowerThr = 0; //设置二值化的上下阈值
const short upperThr = 1000;
const short replaceValue = 255;
ShortImageType::SizeType radius;
radius[0] = 5;
radius[1] = 5;
ShortImageType::IndexType seed;
seed[0] = 100; //该值必须在图像的三维大小范围内
seed[1] = 100;
typedef NeighborhoodConnectedImageFilter<ShortImageType, ShortImageType> NeiConnectedFilterType;
typename NeiConnectedFilterType::Pointer thresholder = NeiConnectedFilterType::New();
thresholder->SetInput(image);
thresholder->SetLower(lowerThr);
thresholder->SetUpper(upperThr);
thresholder->SetRadius(radius);
thresholder->SetSeed(seed);
thresholder->SetReplaceValue(replaceValue);
try
{
thresholder->Update();
}
catch (itk::ExceptionObject& ex)
{
//读取过程发生错误
std::cerr