【ITK库学习】使用itk库进行图像分割(一):区域生长--阈值ThresholdImageFilter

1、itkThresholdImageFilter

该类的主要功能是通过设置低阈值、高阈值或介于高低阈值之间,则将图像值输出为用户指定的值。

如果图像值低于、高于或介于设置的阈值之间,该类就将图像值设置为用户指定的“外部”值(默认情况下为“黑色”)。

常用的成员函数

  • Set/GetLower():设置/获取下限阈值
  • Set/GetUpper():设置/获取上限阈值
  • Set/GetOutsideValue():设置/获取“外部”像素值
  • ThresholdAbove():将大于或等于该阈值的值设置为OutsideValue
  • ThresholdBelow():将小于或等于该阈值的值设置为OutsideValue
  • ThresholdOutside():将超出上下限阈值范围的值设置为 OutsideValue

该类并不对像素进行二值化处理,输出图像中的像素值可以是浮点型或整型。

示例代码:

#include "itkImage.h"
#include "itkThresholdImageFilter.h";

using namespace itk;

const unsigned int  Dimension = 3;       //数据的Dimension
typedef signed short shortPixelType;
typedef itk::Image<shortPixelType, Dimension> ShortImageType;

//图像进行阈值分割处理
bool thresholdImage(ShortImageType* image, ShortImageType* outImage)
{
   
	const short lowerThr = 0;      //设置下阈值
	const short upperThr = 1000;   //设置上阈值
	short outsideValue = 0; 
    typedef ThresholdImageFilter<ShortImageType> thresholdFilterType;
	typename thresholdFilterType::Pointer thresholder = thresholdFilterType::New();
	thresholder->SetInput(image);
	thresholder->SetOutsideValue(outsideValue);
	设置上下阈值
	//thresholder->SetLower(lowerThr);
	//thresholder->SetUpper(upperThr);
	
	//<下阈值的值均设为outsideValue
	thresholder->ThresholdBelow(lowerThr);
	try
	{
   
		thresholder->Update();
	}
	catch (itk::ExceptionObject& ex)
	{
   
		//读取过程发生错误
		std::cerr << "Error: " << ex << std::endl;
		return false;
	}
	//>上阈值的值均设为outsideValue
	thresholder->ThresholdAbove(upperThr);
	try
	{
   
		thresholder->Update()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值