【ITK库学习】使用itk库进行图像分割(二):区域生长--连接ConnectedImageFilter

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 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值