ITK/Examples/Curves/ContourMeanDistanceImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
No edit summary
(Deprecated content that is moved to sphinx)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<div class="floatcenter">[[File:ITK_Examples_Baseline_Curves_TestContourMeanDistanceImageFilter.png]]</div>
{{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 releasesIn many cases, the examples on this page no longer conform to the best practices for modern ITK versions.}}
==ContourMeanDistanceImageFilter.cxx==
<source lang="cpp">
#include "itkImage.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkVnlFFTRealToComplexConjugateImageFilter.h"
#include "itkComplexToRealImageFilter.h"
#include "itkComplexToImaginaryImageFilter.h"
#include "itkComplexToModulusImageFilter.h"
#include "itkImageFileReader.h"
#include "itkCastImageFilter.h"
#include "itkPasteImageFilter.h"
#include "itkContourMeanDistanceImageFilter.h"
 
#include <itksys/SystemTools.hxx>
#include "vnl/vnl_sample.h"
#include <math.h>
 
#include <itkImageToVTKImageFilter.h>
 
#include "QuickView.h"
 
typedef itk::Image<unsigned char, 2> ImageType;
 
static void CreateImage1(ImageType::Pointer);
static 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>
 
{{ITKVTKCMakeLists|ContourMeanDistanceImageFilter|}}

Latest revision as of 19:13, 6 June 2019

Warning: 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.