1 / 34

ITK Statistical Classification

ITK Statistical Classification. Kitware Inc. Statistical Classification. Multiple Components Images K-Means Markov Random Fields. Creating Images with Multiple Components. Multiple-Component Images. 3 Images of 1 component per pixel. 1 Image of 3 component per pixel.

thor
Download Presentation

ITK Statistical Classification

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ITKStatistical Classification Kitware Inc.

  2. Statistical Classification • Multiple Components Images • K-Means • Markov Random Fields

  3. Creating Images with Multiple Components

  4. Multiple-Component Images 3 Images of 1 component per pixel 1 Image of 3 component per pixel

  5. Image to Vector Image Filter #include "itkImage.h" #include "itkVectorImage.h" #include "itkImageFileReader.h“ #include "itkImageFileWriter.h" #include "itkImageToVectorImageFilter.h" int main( intargc,char * argv[] ) typedef itk::Image< unsigned char, 2 > ImageType; typedef itk::ImageToVectorImageFilter< ImageType > FilterType; typedef FilterType::OutputImageType OutputImageType; typedef itk::ImageFileReader< ImageType > ReaderType; typedef itk::ImageFileWriter< OutputImageType > WriterType; FilterType::Pointer filter= FilterType::New();

  6. Image to Vector Image Filter for (unsigned int k = 1; k < argc-1; k++ ) { ReaderType ::Pointer reader = ReaderType ::New(); reader->SetFileName( argv[ k ] ); reader->Update(); filter->SetNthInput( k-1, reader->GetOutput() ); } WriterType::Pointer writer = WriterType::New(); writer->SetInput( filter->GetOutput() ); writer->SetFileName( argv[ argc-1 ] ); writer->Update();

  7. Image to Vector Image Filter Run Command: ConvertImagesToVectorImage brainweb165a10f17_Slice94.png brainweb1e1a10f20_Slice94.png brainweb1e5a10f17_Slice94.png brainwebSlice94.vtk In ParaView: Load the brainwebSlice94.vtk image Use the Calculator to verify the components

  8. Exercise 36a

  9. K-Means Classifier

  10. Image K-Means Estimation Image to List Adaptor List N Components Image K-d Tree Generator K-d Tree K-Means Estimator Array of Means K-d Tree

  11. Image K-Means Estimation #include "itkKdTree.h" #include "itkKdTreeBasedKmeansEstimator.h" #include "itkWeigthedCentroidKdTreeGenerator.h“ #include "itkImageToListAdaptor.h“ #include "itkImageFileReader.h“ #include "itkImage.h“ int main( intargc,char * argv[] ) { typedef itk::Vector< unsigned char, 3 > PixelType; typedef itk::Image< PixelType, 2 > ImageType;

  12. Image K-Means Estimation typedef itk::Statistics::ImageToListAdaptor< ImageType > AdaptorType; AdaptorType::Pointer adaptor = AdaptorType::New(); adaptor->SetImage( reader->GetOutput() ); typedef itk::Statistics::WeightedCentroidKdTreeGenerator< AdaptorType > TreeGeneratorType; TreeGeneratorType::Pointer treeGenerator = TreeGeneratorType::New(); treeGenerator->SetSample( adaptor ); treeGenerator->SetBucketSize( 16 ); treeGenerator->Update();

  13. Image K-Means Estimation typedef TreeGeneratorType::KdTreeType TreeType; typedef itk:: Statistics:: KdTreeBasedKmeansEstimator< TreeType > EstimatorType; EstimatorType::Pointer estimator = EstimatorType::New(); EstimatorType::ParametersType initialMeans( NumberOfClasses * NumberOfComponents ); estimator->SetParameters( initialMeans ); estimator->SetKdTree( treeGenerator->GetOutput() ); estimator->SetMaximumIteration( 200 ); estimator->SetCentroidPositionChangesThreshold(0.0); estimator->StartOptimization(); EstimatorType::ParametersType estimatedMeans = estimator->GetParameters();

  14. Image K-Means Estimation for ( unsigned int i = 0 ; i < numberOfClasses ; ++i ) { std::cout << "cluster[" << i << "] "; std::cout << " estimated mean : "; for ( unsigned int j = 0 ; j < NumberOfComponents ; ++j ) { std::cout << " " << estimatedMeans[ i * NumberOfComponents + j ]; } std::cout << std::endl; }

  15. Vector Image K-Means Estimation Run Command: ImageKmeansModeleEstimator brainwebSlice94.vtk 4 Output: Locations of the Means in the N-Components Space

  16. Exercise 36b

  17. Image K-Means Estimation Image to List Adaptor List N Components Image K-d Tree Generator K-d Tree K-Means Estimator Array of Means K-d Tree itk::ImageKmeansImageFilter

  18. Image K-Means Classification Array of Means …. Membership Functions N Components Image K-d Tree Sample Classifier Decision Rule Image of Labels Membership Sample Label List itk::ImageKmeansImageFilter

  19. Image K-Means Classification #include "itkImage.h“ #include "itkImageFileReader.h“ #include "itkImageFileWriter.h“ #include "itkImageKmeansImageFilter.h“ int main( intargc,char * argv[] ) { typedef itk::Vector< unsigned char, 3 > PixelType; typedef itk::Image< PixelType, 2 > ImageType;

  20. Image K-Means Classification typedef itk:: ImageKmeansImageFilter< ImageType > KMeansFilterType; KMeansFilterType::Pointer kmeansFilter = KMeansFilterType::New(); kmeansFilter->SetInput( reader->GetOutput() ); kmeansFilter->SetUseNonContiguousLabels( useNonContiguousLabels ); KMeansFilterType::RealPixelType initialMean; initialMean.Fill(0.0); // N-Components array for( unsigned int cc = 0; cc < numberOfClasses; ++cc ) { kmeansFilter->AddClassWithInitialMean( initialMean ); }

  21. Image K-Means Classification typedef KMeansFilterType::OutputImageType OutputImageType; typedef itk::ImageFileWriter< OutputImageType > WriterType; WriterType::Pointer writer = WriterType::New(); writer->SetInput( kmeansFilter->GetOutput() ); writer->Update(); KMeansFilterType::ParametersType estimatedMeans = kmeansFilter->GetFinalMeans(); // Array of NumberOfClasses X NumberOfComponents

  22. Image K-Means Classification Run Command: ImageKmeansModeleClassifier brainwebSlice94.vtk labelsImage.vtk 4 0 Output: Locations of the Means in the N-components space Image of labels associated to classes

  23. K-Means Classification Result

  24. Exercise 36c

  25. Markov Random Fields

  26. Markov Random Field Filter Number of Classes Number of Iterations Smoothing Factor Error Tolerance N Components Image Neighborhood Radius Markov Random Fields Filter Neighborhood Weights Image of Labels Classifier

  27. Markov Random Field Filter Membership Functions Array of Means N Components Image Image Classifier Image of Labels Markov Random Fields Filter Decision Rule

  28. Markov Random Field Output SmoothingFactor = 10 SmoothingFactor = 20 SmoothingFactor = 1

  29. Markov Random Field Classification #include "itkImage.h“ #include "itkImageFileReader.h“ #include "itkImageFileWriter.h“ #include "itkMRFImageFilter.h“ #include "itkDistanceToCentroidMembershipFunction.h“ #include "itkMinimumDecisionRule.h“ #include "itkImageClassifierBase.h“ int main( intargc,char * argv[] ) { typedef itk::Vector< unsigned char, 3 > PixelType; typedef itk::Image< PixelType, 2 > ImageType;

  30. Markov Random Field Classification typedef itk:: MRFImageFilter< ImageType > MarkovFilterType; MarkovFilterType::Pointer markovFilter = MarkovFilterType::New(); markovFilter->SetInput( reader->GetOutput() ); markovFilter->SetNumberOfClasses( numberOfClasses ); markovFilter->SetMaximumNumberOfIterations( maxNumberIterations ); markovFilter->SetSmoothingFactor( smoothingFactor ); markovFilter->SetErrorTolerance( 1e-7 ); markovFilter->SetNeighborhoodRadius( 1 ); markovFilter->SetMRFNeighborhoodWeight( weights ); markovFilter->Classifier( classifier ); writer->SetInput( markovFilter->GetOutput() );

  31. Markov Random Field Classification typedef itk:: ImageClassifierBase< ImageType,LabelImageType > ClassifierType; ClassifierType::Pointer classifier = ClassifierType::New(); classifier->SetDecisionRule( reader->GetOutput() ); typedef itk:: Statistics:: DistanceToCentroidMembershipFunction<PixelType > MembershipFunctionType; MembershipFunctionType::Pointer membershipFunction; MembershipFunctionType ::New(); for( unsigned int cc = 0; cc < numberOfClasses; ++cc ) { membershipFunction = MembershipFunctionType ::New(); membershipFunction ->SetCentroid( classMean[cc] ); classifier->AddMembershipFunction( membershipFunction ); }

  32. Markov Random Fields Run Command: ImageMarkovRandomField brainwebSlice94.vtk labelsImage.vtk outputLabelsImage.vtk 50 1 4 means…. Output: Image of labels smoothed Termination criteria: (max num iterations or convergence)

  33. Exercise 36d

  34. Enjoy ITK !

More Related