void ITKTestClass::itkCannyEdgeDetectionImageFilter(std::string inputImageFile, std::string outputImageFile, double variance, double upperThreshold, double lowerThreshold)
{
itk::PNGImageIOFactory::RegisterOneFactory();
itk::TIFFImageIOFactory::RegisterOneFactory();
itk::BMPImageIOFactory::RegisterOneFactory();
itk::GDCMImageIOFactory::RegisterOneFactory();
itk::JPEGImageIOFactory::RegisterOneFactory();
const unsigned int Dimension = 2;
typedef unsigned char CharPixelType; // IO
typedef double RealPixelType; // Operations
typedef itk::Image< CharPixelType, Dimension > CharImageType;
typedef itk::Image< RealPixelType, Dimension > RealImageType;
// Software Guide : EndCodeSnippet
typedef itk::ImageFileReader< CharImageType > ReaderType;
typedef itk::ImageFileWriter< CharImageType > WriterType;
// Software Guide : BeginLatex
//
// The \code{CharImageType} image is cast to and from \code{RealImageType}
// using \doxygen{CastImageFilter} and \code{RescaleIntensityImageFilter},
// respectively; both the input and output of \code{CannyEdgeDetectionImageFilter}
// are \code{RealImageType}.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
typedef itk::CastImageFilter< CharImageType, RealImageType >
CastToRealFilterType;
typedef itk::CannyEdgeDetectionImageFilter< RealImageType, RealImageType >
CannyFilterType;
typedef itk::RescaleIntensityImageFilter< RealImageType, CharImageType >
RescaleFilterType;
// Software Guide : EndCodeSnippet
//Setting the IO
ReaderType::Pointer reader = ReaderType::New();
CastToRealFilterType::Pointer toReal = CastToRealFilterType::New();
CannyFilterType::Pointer cannyFilter = CannyFilterType::New();
RescaleFilterType::Pointer rescale = RescaleFilterType::New();
WriterType::Pointer writer = WriterType::New();
reader->SetFileName(inputImageFile);
writer->SetFileName(outputImageFile);
toReal->SetInput(reader->GetOutput());
cannyFilter->SetInput(toReal->GetOutput());
rescale->SetInput(cannyFilter->GetOutput());
writer->SetInput(rescale->GetOutput());
// Software Guide : BeginLatex
//
// In this example, three parameters of the Canny edge detection
// filter may be set via the \code{SetVariance()}, \code{SetUpperThreshold()},
// and \code{SetLowerThreshold()} methods. Based on the previous discussion
// of the steps in the internal pipeline, we understand that
// \code{variance} adjusts the amount of Gaussian smoothing and
// \code{upperThreshold} and \code{lowerThreshold} control which edges are
// selected in the final step.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
cannyFilter->SetVariance(variance);
cannyFilter->SetUpperThreshold(upperThreshold);
cannyFilter->SetLowerThreshold(lowerThreshold);
// Software Guide : EndCodeSnippet
// Software Guide : BeginLatex
//
// Finally, \code{Update()} is called on \code{writer} to trigger excecution
// of the pipeline. As usual, the call is wrapped in a \code{try/catch}
// block.
//
// Software Guide : EndLatex
// Software Guide : BeginCodeSnippet
try
{
writer->Update();
}
catch (itk::ExceptionObject & err)
{
std::cout << "ExceptionObject caught !" << std::endl;
std::cout << err << std::endl;
}
}
ITK進行進行像素過濾 itkCannyEdgeDetectionImageFilter
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.