ITK/Examples/VectorImages/VectorNeighborhoodIterator

From KitwarePublic

Jump to: navigation, search

Contents

VectorNeighborhoodIterator.cxx

#include "itkVectorImage.h"
#include "itkNeighborhoodIterator.h"
 
typedef itk::VectorImage<unsigned char, 2>  VectorImageType;
 
int main(int, char*[])
{
  // Create an image
  VectorImageType::Pointer image = VectorImageType::New();
 
  itk::Index<2> start;
  start.Fill(0);
 
  itk::Size<2> size;
  size.Fill(10);
 
  itk::ImageRegion<2> region(start,size);
 
  image->SetRegions(region);
  image->SetNumberOfComponentsPerPixel(3);
  image->Allocate();
 
  // Create the neighborhood iterator
  VectorImageType::SizeType radius;
  radius[0] = 1;
  radius[1] = 1;
 
  itk::NeighborhoodIterator<VectorImageType> iterator(radius, image, image->GetLargestPossibleRegion());
 
  while(!iterator.IsAtEnd())
    {
    iterator.GetCenterPixel();
 
    ++iterator;
    }
 
 
  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
 
project(VectorNeighborhoodIterator)
 
find_package(ItkVtkGlue REQUIRED)
include(${ItkVtkGlue_USE_FILE})
 
add_executable(VectorNeighborhoodIterator VectorNeighborhoodIterator.cxx)
target_link_libraries(VectorNeighborhoodIterator
  ItkVtkGlue  ${VTK_LIBRARIES} ${ITK_LIBRARIES})

Building All of the Examples

Many of the examples in the ITK Wiki Examples Collection require VTK. You can build all of the the examples by following these instructions. If you are a new VTK user, you may want to try the Superbuild which will build a proper ITK and VTK.

ItkVtkGlue

If you download the entire ITK Wiki Examples Collection, the ItkVtkGlue directory will be included and configured. If you wish to just build a few examples, then you will need to download ItkVtkGlue and build it. When you run cmake it will ask you to specify the location of the ItkVtkGlue binary directory.

Personal tools