膨胀、腐蚀、开、闭运算、顶帽、低帽:
#include "itkBinaryBallStructuringElement.h"//基本球形
#include "itkBinaryMorphologicalOpeningImageFilter.h"//开运算
#include "itkBinaryMorphologicalClosingImageFilter.h"//闭运算
#include "itkGrayscaleErodeImageFilter.h"//灰度腐蚀
#include "itkGrayscaleDilateImageFilter.h"//灰度膨胀
#include "itkBinaryDilateImageFilter.h"//二值膨胀
#include "itkBinaryErodeImageFilter.h"//二值腐蚀
typedef itk::BinaryBallStructuringElement<ImageType::PixelType, ImageType::ImageDimension>
StructuringElementType;
StructuringElementType structuringElement;
structuringElement.SetRadius(rad);
structuringElement.CreateStructuringElement();
typedef itk::BinaryMorphologicalOpeningImageFilter <ImageType, ImageType, StructuringElementType> BinaryMorphologicalOpeningImageFilterType;
BinaryMorphologicalOpeningImageFilterType::Pointer mathOperationFilter
= BinaryMorphologicalOpeningImageFilterType::New();
mathOperationFilter->SetInput(*input);
mathOperationFilter->SetKernel(structuringElement);
mathOperationFilter->Update();
typedef itk::BinaryMorphologicalClosingImageFilter <ImageType, ImageType, StructuringElementType> BinaryMorphologicalClosingImageFilterType;
BinaryMorphologicalClosingImageFilterType::Pointer mathOperationFilter
= BinaryMorphologicalClosingImageFilterType::New();
mathOperationFilter->SetInput(*input);
mathOperationFilter->SetKernel(structuringElement);
mathOperationFilter->Update();
typedef itk::GrayscaleErodeImageFilter <ImageType, ImageType, StructuringElementType>
GrayscaleErodeImageFilterType;
GrayscaleErodeImageFilterType::Pointer mathOperationFilter = GrayscaleErodeImageFilterType::New();
mathOperationFilter->SetInput(*input);
mathOperationFilter->SetKernel(structuringElement);
mathOperationFilter->Update();
typedef itk::GrayscaleDilateImageFilter <ImageType, ImageType, StructuringElementType>
GrayscaleDilateImageFilterType;
GrayscaleDilateImageFilterType::Pointer mathOperationFilter = GrayscaleDilateImageFilterType::New();
mathOperationFilter->SetInput(*input);
mathOperationFilter->SetKernel(structuringElement);
mathOperationFilter->Update();
typedef itk::BinaryErodeImageFilter <ImageType, ImageType, StructuringElementType>
BinaryErodeImageFilter ;
BinaryErodeImageFilter ::Pointer mathOperationFilter = BinaryErodeImageFilter ::New();
mathOperationFilter->SetInput(*input);
mathOperationFilter->SetKernel(structuringElement);
mathOperationFilter->Update();
typedef itk::BinaryDilateImageFilter <ImageType, ImageType, StructuringElementType>
BinaryDilateImageFilter ;
BinaryDilateImageFilter ::Pointer mathOperationFilter = BinaryDilateImageFilter ::New();
mathOperationFilter->SetInput(*input);
mathOperationFilter->SetKernel(structuringElement);
mathOperationFilter->Update();
typedef itk::BinaryErodeImageFilter <ImageType, ImageType, StructuringElementType>
BinaryErodeImageFilter ;
BinaryErodeImageFilter ::Pointer mathOperationFilter = BinaryErodeImageFilter ::New();
mathOperationFilter->SetInput(*input);
mathOperationFilter->SetKernel(structuringElement);
mathOperationFilter->SetBackgroundValue(0);
mathOperationFilter->SetForegroundValue(1);
mathOperationFilter->Update();
TopHat是应用在灰度图像的。TopHat算法本质是形态学变换中开闭运算的组合。
WhiteTopHat:原图像-开运算结果
BlackTopHat:闭运算结果-原图像
原文:https://blog.csdn.net/rabbitbride/article/details/73179465
#include "itkBlackTopHatImageFilter.h"
#include "itkWhiteTopHatImageFilter.h"
typedef itk::BinaryBallStructuringElement<PixelType, ImageDimension > SRType;
SRType kernel;
kernel.SetRadius( 22 );
kernel.CreateStructuringElement();
//typedef itk::WhiteTopHatImageFilter<ImageType,ImageType,SRType > TopHatFilterType;
typedef itk::BlackTopHatImageFilter<ImageType,ImageType,SRType > TopHatFilterType;
TopHatFilterType::Pointer topHatFilter = TopHatFilterType::New();
topHatFilter->SetInput( intput_data );
topHatFilter->SetSafeBorder( false);
topHatFilter->SetKernel( kernel );
topHatFilter->Update();
原文:https://blog.csdn.net/rabbitbride/article/details/72356474