|
|
(4 intermediate revisions by one other user not shown) |
Line 1: |
Line 1: |
| ==ConfidenceConnectedImageFilter.cxx==
| | {{warning|1=The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.}} |
| <source lang="cpp">
| |
| #include "itkImage.h"
| |
| #include "itkImageFileReader.h"
| |
| #include "itkImageFileWriter.h"
| |
| #include "itkConfidenceConnectedImageFilter.h"
| |
| | |
| typedef itk::Image< unsigned char, 2 > ImageType;
| |
| | |
| int main( int argc, char *argv[])
| |
| { | |
| if(argc < 3)
| |
| {
| |
| std::cerr << "Required: filename.png output.png" << std::endl;
| |
| | |
| return EXIT_FAILURE;
| |
| }
| |
| std::string inputFileName = argv[1];
| |
| std::string outputFileName = argv[2];
| |
|
| |
| typedef itk::ImageFileReader<ImageType> ReaderType;
| |
| ReaderType::Pointer reader = ReaderType::New();
| |
| reader->SetFileName(inputFileName.c_str());
| |
| reader->Update();
| |
| | |
| typedef itk::ConfidenceConnectedImageFilter<ImageType, ImageType> ConfidenceConnectedFilterType;
| |
| ConfidenceConnectedFilterType::Pointer confidenceConnectedFilter = ConfidenceConnectedFilterType::New();
| |
| confidenceConnectedFilter->SetInitialNeighborhoodRadius(3);
| |
| confidenceConnectedFilter->SetMultiplier(2);
| |
| confidenceConnectedFilter->SetNumberOfIterations(25);
| |
| confidenceConnectedFilter->SetReplaceValue(255);
| |
| | |
| // Set seed
| |
| ImageType::IndexType seed;
| |
| seed[0] = 60;
| |
| seed[1] = 70;
| |
| confidenceConnectedFilter->SetSeed(seed);
| |
| confidenceConnectedFilter->SetInput(reader->GetOutput());
| |
| confidenceConnectedFilter->Update();
| |
| | |
| typedef itk::ImageFileWriter< ImageType > WriterType;
| |
| WriterType::Pointer writer = WriterType::New(); | |
| writer->SetFileName(outputFileName);
| |
| writer->SetInput(confidenceConnectedFilter->GetOutput());
| |
| writer->Update();
| |
|
| |
| return EXIT_SUCCESS;
| |
| }
| |
| | |
| </source>
| |
| | |
| {{ITKCMakeLists|ConfidenceConnectedImageFilter|}}
| |