ITK/Examples/SimpleOperations/ImageDuplicator

From KitwarePublic

Jump to: navigation, search

This example demonstrates how to copy/clone/duplicate an image so it can continue down two separate paths of the pipeline.

ImageDuplicator.cxx

#include "itkImage.h"
#include "itkImageDuplicator.h"
#include "itkRandomImageSource.h"
 
int main(int, char *[])
{
  typedef itk::Image< unsigned char, 2 >  ImageType;
 
  itk::RandomImageSource<ImageType>::Pointer randomImageSource =
    itk::RandomImageSource<ImageType>::New();
  randomImageSource->SetNumberOfThreads(1); // to produce non-random results
 
  randomImageSource->Update();
  ImageType::Pointer image = randomImageSource->GetOutput();
 
  typedef itk::ImageDuplicator< ImageType > DuplicatorType;
  DuplicatorType::Pointer duplicator = DuplicatorType::New();
  duplicator->SetInputImage(image);
  duplicator->Update();
  ImageType::Pointer clonedImage = duplicator->GetOutput();
 
  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
 
project(ImageDuplicator)
 
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
 
add_executable(ImageDuplicator ImageDuplicator.cxx)
 
if( "${ITK_VERSION_MAJOR}" LESS 4 )
  target_link_libraries(ImageDuplicator ITKReview ${ITK_LIBRARIES})
else( "${ITK_VERSION_MAJOR}" LESS 4 )
  target_link_libraries(ImageDuplicator ${ITK_LIBRARIES})
endif( "${ITK_VERSION_MAJOR}" LESS 4 )
Personal tools