之前一直很奇怪,ITK的图像类型可以自定义,从uchar到double都可以,那这么做到底有什么意义,难道直接用uchar不好么。
今天用canny edge detection和binary morphological closing的时候发现,canny filter的输出像素必须是float类型的,而binary morphological filter输入输出必须是uchar类型的,所以itk里面的图像自定义类型估计是为了兼容这么多来自不同种族的算法函数吧…
// binary morphological filter
using StructuringElementType = itk::BinaryBallStructuringElement<ImageTypeUchar::PixelType, ImageTypeUchar::ImageDimension>;
StructuringElementType structuringElement;
structuringElement.SetRadius(5);
structuringElement.CreateStructuringElement();
using BinaryMorphologicalClosingImageFilterType = itk::BinaryMorphologicalClosingImageFilter <ImageTypeBin, ImageTypeBin, StructuringElementType>;
BinaryMorphologicalClosingImageFilterType::Pointer closingFilter = BinaryMorphologicalClosingImageFilterType::New();
closingFilter->SetInput(reader->GetOutput());
closingFilter->SetKernel(structuringElement);
closingFilter->Update();
// canny edge detection
using CannyFilterType = itk::CannyEdgeDetectionImageFilter< ImageTypeFloat, ImageTypeFloat >;
CannyFilterType::Pointer cannyFilter = CannyFilterType::New();
cannyFilter->SetInput(reader->GetOutput());
cannyFilter->SetVariance(variance);
cannyFilter->SetLowerThreshold(low_thr);
cannyFilter->SetUpperThreshold(high_thr);
来源:https://blog.csdn.net/sharemon/article/details/98846224