ITK/Examples/Curves/ContourMeanDistanceImageFilter

From KitwarePublic
< ITK‎ | Examples
Revision as of 00:32, 25 January 2011 by Daviddoria (talk | contribs) (Created page with "==ContourMeanDistanceImageFilter.cxx== <source lang="cpp"> #include "itkImage.h" #include "itkRescaleIntensityImageFilter.h" #include "itkVnlFFTRealToComplexConjugateImageFilter....")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

ContourMeanDistanceImageFilter.cxx

<source lang="cpp">

  1. include "itkImage.h"
  2. include "itkRescaleIntensityImageFilter.h"
  3. include "itkVnlFFTRealToComplexConjugateImageFilter.h"
  4. include "itkComplexToRealImageFilter.h"
  5. include "itkComplexToImaginaryImageFilter.h"
  6. include "itkComplexToModulusImageFilter.h"
  7. include "itkImageFileReader.h"
  8. include "itkCastImageFilter.h"
  9. include "itkPasteImageFilter.h"
  10. include "itkContourMeanDistanceImageFilter.h"
  1. include <itksys/SystemTools.hxx>
  2. include "vnl/vnl_sample.h"
  3. include <math.h>
  1. include <itkImageToVTKImageFilter.h>
  1. include "QuickView.h"

typedef itk::Image<unsigned char, 2> ImageType;

void CreateImage1(ImageType::Pointer); void CreateImage2(ImageType::Pointer);

int main(int argc, char*argv[]) {

 ImageType::Pointer image1 = ImageType::New();
 CreateImage1(image1);
 ImageType::Pointer image2 = ImageType::New();
 CreateImage2(image2);
 
 typedef itk::ContourMeanDistanceImageFilter <ImageType, ImageType >
   ContourMeanDistanceImageFilterType;
 
 ContourMeanDistanceImageFilterType::Pointer contourMeanDistanceImageFilter =
   ContourMeanDistanceImageFilterType::New();
 contourMeanDistanceImageFilter->SetInput1(image1);
 contourMeanDistanceImageFilter->SetInput2(image2);
 contourMeanDistanceImageFilter->Update();
 std::cout << "Mean distance: " << contourMeanDistanceImageFilter->GetMeanDistance() << std::endl;
 
 QuickView viewer;
 viewer.AddImage(image1.GetPointer());
 viewer.AddImage(image2.GetPointer());
 viewer.Visualize();
 return EXIT_SUCCESS;

}

void CreateImage1(ImageType::Pointer image) {

 // Create an image bigger than the input image and that has dimensions which are powers of two
 itk::Index<2> start;
 start.Fill(0);
 itk::Size<2> size;
 size.Fill(20);
 itk::ImageRegion<2> region(start, size);
 image->SetRegions(region);
 image->Allocate();
 for(unsigned int i = 0; i < 20; i++)
   {
   for(unsigned int j = 0; j < 20; j++)
     {
     if(i == j) // y = x
       {
       itk::Index<2> pixel;
       pixel[0] = i;
       pixel[1] = j;
       image->SetPixel(pixel, 255);
       }
     }
   }

}

void CreateImage2(ImageType::Pointer image) {

 // Create an image bigger than the input image and that has dimensions which are powers of two
 itk::Index<2> start;
 start.Fill(0);
 itk::Size<2> size;
 size.Fill(20);
 itk::ImageRegion<2> region(start, size);
 image->SetRegions(region);
 image->Allocate();
 for(unsigned int i = 0; i < 20; i++)
   {
   for(unsigned int j = 0; j < 20; j++)
     {
     if(i == 10)
       {
       itk::Index<2> pixel;
       pixel[0] = i;
       pixel[1] = j;
       image->SetPixel(pixel, 255);
       }
     }
   }

}

</source>

CMakeLists.txt

<source lang="cmake"> cmake_minimum_required(VERSION 2.6)

PROJECT(ContourMeanDistanceImageFilter)

include_directories(/home/doriad/src/ITK/Wrapping/WrapITK/ExternalProjects/ItkVtkGlue/src/) include_directories(/home/doriad/ITKWikiExamples/ItkVtkGlue)

FIND_PACKAGE(VTK REQUIRED) INCLUDE(${VTK_USE_FILE})

FIND_PACKAGE(ITK REQUIRED) INCLUDE(${ITK_USE_FILE})

ADD_EXECUTABLE(ContourMeanDistanceImageFilter ContourMeanDistanceImageFilter.cxx /home/doriad/ITKWikiExamples/ItkVtkGlue/QuickView.cxx) TARGET_LINK_LIBRARIES(ContourMeanDistanceImageFilter vtkHybrid ITKNumerics ITKBasicFilters ITKCommon ITKIO)


</source>