目录
1、itkThresholdImageFilter
该类的主要功能是通过设置低阈值、高阈值或介于高低阈值之间,则将图像值输出为用户指定的值。
如果图像值低于、高于或介于设置的阈值之间,该类就将图像值设置为用户指定的“外部”值(默认情况下为“黑色”)。
常用的成员函数:
Set/GetLower()
:设置/获取下限阈值Set/GetUpper()
:设置/获取上限阈值Set/GetOutsideValue()
:设置/获取“外部”像素值ThresholdAbove()
:将大于或等于该阈值的值设置为OutsideValueThresholdBelow()
:将小于或等于该阈值的值设置为OutsideValueThresholdOutside()
:将超出上下限阈值范围的值设置为 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()