]> Creatis software - FrontAlgorithms.git/blob - appli/examples/example_Thinning.cxx
abd614461e3dd146fd297daad4d14c4306db6066
[FrontAlgorithms.git] / appli / examples / example_Thinning.cxx
1 #include "itkBinaryThinningImageFilter.h"
2 #include "itkImage.h"
3 #include "itkImageFileReader.h"
4 #include "itkImageFileWriter.h"
5 #include "itkRescaleIntensityImageFilter.h"
6  
7 typedef itk::Image<short, 3>  ImageType;
8  
9 int main(int argc, char *argv[])
10 {
11   
12   typedef itk::ImageFileReader<ImageType> ImageReader;
13   ImageReader::Pointer reader = ImageReader::New();
14   std::string fileName = argv[1];
15   reader->SetFileName(fileName);
16   reader->Update();
17   ImageType::Pointer image = reader->GetOutput();
18  
19   typedef itk::BinaryThinningImageFilter <ImageType, ImageType> BinaryThinningImageFilterType;
20   BinaryThinningImageFilterType::Pointer binaryThinningImageFilter = BinaryThinningImageFilterType::New();
21   binaryThinningImageFilter->SetInput(image);
22   binaryThinningImageFilter->Update();
23  
24   // Rescale the image so that it can be seen (the output is 0 and 1, we want 0 and 255)
25   typedef itk::RescaleIntensityImageFilter< ImageType, ImageType > RescaleType;
26   RescaleType::Pointer rescaler = RescaleType::New();
27   rescaler->SetInput( binaryThinningImageFilter->GetOutput() );
28   rescaler->SetOutputMinimum(0);
29   rescaler->SetOutputMaximum(255);
30   rescaler->Update();
31  
32   typedef  itk::ImageFileWriter< ImageType  > WriterType;
33   WriterType::Pointer writer = WriterType::New();
34   writer->SetFileName(argv[2]);
35   writer->SetInput(rescaler->GetOutput());
36   writer->Update();
37
38   return EXIT_SUCCESS;
39 }
40