目录
- 1、itkRecursiveGaussianImageFliter 递归高斯滤波器
- 2、itkLapacianRecursiveGaussianImageFiter 拉普拉斯高斯滤波器
1、itkRecursiveGaussianImageFliter 递归高斯滤波器
该类用于计算具有高斯核近似值的 IIR 卷积的基类。
该类是递归滤波器的基类,它与高斯核近似卷积。
与 itkDiscreteGaussianImageFilter相比,此滤波器对于大内核往往更快,并且它可以一步获取模糊图像的导数。 另外,请注意,itkRecursiveGaussianImageFilter 有 SetSigma(),itkDiscreteGaussianImageFilter 有 SetVariance()。
常用的成员函数:
Set/GetSigma()
:设置/获取高斯核的Sigma(以世界坐标测量),默认值为 1.0。 如果 Sigma 值小于或等于 0,则会生成异常Set/GetOrder()
:设置/获取要进行卷积的高斯阶数,ZeroOrder 相当于与高斯卷积,是默认设置;FirstOrder 相当于与高斯的一阶导数进行卷积;SecondOrder 相当于与高斯的二阶导数进行卷积SetZeroOrder()
:明确设置零阶导数SetFirstOrder()
:明确设置一阶导数SetSecondOrder()
:明确设置二阶导数SetNormalizeAcrossScale()
:设置/获取用于在尺度空间上标准化高斯的标志SetUp()
:设置滤波器的系数以近似特定的内核,这里它用于近似高斯或其导数之一,参数是沿要过滤的维度的间距VerifyPreconditions()
:验证过程对象是否已正确配置、所有必需的输入是否已设置以及所需的参数是否已正确设置, 如果无效,将抛出异常
示例代码:
(1) 二阶高斯递归
#include "itkImage.h"
#include "itkRecursiveGaussianImageFilter.h"typedef itk::Image<float, 3> FloatImageType;bool recursiveGaussianImage(FloatImageType* image, FloatImageType* outputImage, double sigma)
{typedef itk::RecursiveGaussianImageFilter<FloatImageType, FloatImageType> RecursiveGaussianFilterType;typename RecursiveGaussianFilterType::Pointer filterA = RecursiveGaussianFilterType::New();typename RecursiveGaussianFilterType::Pointer filterB = RecursiveGaussianFilterType::New();typename RecursiveGaussianFilterType::Pointer filterC = RecursiveGaussianFilterType::New();filterA->SetInput(image);filterB->SetInput(filterA->GetOutput());filterC->SetInput(filterB->GetOutput());filterA->SetSigma(sigma);filterB->SetSigma(sigma);filterC->SetSigma(sigma);filterA->SetDirection(0); // 0 --> X directionfilterB->SetDirection(1); // 1 --> Y directionfilterC->SetDirection(2); // 1 --> Z directionfilterA->SetZeroOrder(); //ZeroOrder FirstOrder SecondOrderfilterB->SetZeroOrder();filterC->SetSecondOrder();try{filterC->Update();}catch (itk::ExceptionObject& ex){//读取过程发生错误std::cerr << "Error: " << ex << std::endl;return false;}outputImage = filterC->GetOutput();return true;
}
(2) 拉普拉斯滤波器
#include "itkImage.h"
#include "itkRecursiveGaussianImageFilter.h"
#include "itkAddImageFilter.h"typedef itk::Image<float, 3> FloatImageType;//拉普拉斯滤波器
bool laplacianRecursiveGaussian(FloatImageType* image, FloatImageType* outputImage, double sigma)
{const bool normalizeAcrossScale = false;typedef itk::RecursiveGaussianImageFilter<FloatImageType, FloatImageType> RecursiveGaussianFilterType;typename RecursiveGaussianFilterType::Pointer filterX1 = RecursiveGaussianFilterType::New();typename RecursiveGaussianFilterType::Pointer filterY1 = RecursiveGaussianFilterType::New();typename RecursiveGaussianFilterType::Pointer filterX2 = RecursiveGaussianFilterType::New();typename RecursiveGaussianFilterType::Pointer filterY2 = RecursiveGaussianFilterType::New();filterX1->SetInput(image);filterY1->SetInput(filterX1->GetOutput());filterY2->SetInput(image);filterX2->SetInput(filterY2->GetOutput());filterX1->SetDirection(0); // 0 --> X directionfilterY1->SetDirection(1); // 1 --> Y directionfilterX2->SetDirection(0); // 0 --> X directionfilterY2->SetDirection(1); // 1 --> Y directionfilterX1->SetZeroOrder();filterY1->SetSecondOrder();filterX2->SetSecondOrder();filterY2->SetZeroOrder();filterX1->SetNormalizeAcrossScale(normalizeAcrossScale);filterY1->SetNormalizeAcrossScale(normalizeAcrossScale);filterX2->SetNormalizeAcrossScale(normalizeAcrossScale);filterY2->SetNormalizeAcrossScale(normalizeAcrossScale);filterX1->SetSigma(sigma);filterY1->SetSigma(sigma);filterX2->SetSigma(sigma);filterY2->SetSigma(sigma);typedef itk::AddImageFilter<FloatImageType, FloatImageType> AddFiterType;typename AddFiterType::Pointer addFilter = AddFiterType::New();addFilter->SetInput1(filterY1->GetOutput());addFilter->SetInput2(filterX2->GetOutput());try{addFilter->Update();}catch (itk::ExceptionObject& ex){//读取过程发生错误std::cerr << "Error: " << ex << std::endl;return false;}outputImage = addFilter->GetOutput();return true;
}
2、itkLapacianRecursiveGaussianImageFiter 拉普拉斯高斯滤波器
该类主要用于计算图像的拉普拉斯高斯 (LoG)。
通过与高斯的二阶导数卷积来计算图像的拉普拉斯高斯 (LoG),该滤波器是使用递归高斯滤波器实现的。
它是包含itkRecursiveGaussianImageFiter的一个便捷的滤波器,可以简化它的使用。
常用的成员函数:
Set/GetSigma()
:设置/获取Sigma值, Sigma以图像间距为单位进行测量SetNormalizeAcrossScale()
:设置/获取用于在尺度空间上归一化的高斯因子
示例代码:
#include "itkImage.h"
#include "itkLaplacianRecursiveGaussianImageFilter.h"typedef itk::Image<float, 3> FloatImageType;bool laplacianRecursiveGaussianImage(FloatImageType* image,FloatImageType* outputImage, double sigma)
{typedef itk::LaplacianRecursiveGaussianImageFilter<FloatImageType, FloatImageType> LaplacianRecursiceGaussianFilterType;typename LaplacianRecursiceGaussianFilterType::Pointer laplacianRecGauFilter = LaplacianRecursiceGaussianFilterType::New();laplacianRecGauFilter->SetInput(image);laplacianRecGauFilter->SetNormalizeAcrossScale(false);laplacianRecGauFilter->SetSigma(sigma);try{laplacianRecGauFilter->Update();}catch (itk::ExceptionObject& ex){//读取过程发生错误std::cerr << "Error: " << ex << std::endl;return false;}outputImage = laplacianRecGauFilter->GetOutput();return true;
}