ITK/Examples/IO/ImageFileWriter

From KitwarePublic
< ITK‎ | Examples
Revision as of 16:23, 26 October 2010 by Daviddoria (talk | contribs)
Jump to navigationJump to search

ImageFileWriter.cxx

<source lang="cpp">

  1. include "itkImage.h"
  2. include "itkImageFileWriter.h"
  1. include <iostream>
  2. include <string>

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

 std::string outputFilename;
 if(argc > 1)
   {
   outputFilename = argv[1];
   }
 else
   {
   outputFilename = "test.png";
   }
 typedef unsigned char     PixelType;
 const     unsigned int    Dimension = 2;
 typedef itk::Image< PixelType, Dimension >  ImageType;
 ImageType::RegionType region;
 ImageType::IndexType start;
 start[0] = 0;
 start[1] = 0;
 ImageType::SizeType size;
 size[0] = 200;
 size[1] = 300;
 region.SetSize(size);
 region.SetIndex(start);
 ImageType::Pointer image = ImageType::New();
 image->SetRegions(region);
 image->Allocate();
 ImageType::IndexType ind;
 ind[0] = 10;
 ind[1] = 10;
 typedef  itk::ImageFileWriter< ImageType  > WriterType;
 WriterType::Pointer writer = WriterType::New();
 writer->SetFileName(outputFilename);
 writer->SetInput(image);
 writer->Update();
 return EXIT_SUCCESS;

} </source>

CMakeLists.txt

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

PROJECT(ImageFileWriter)

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

ADD_EXECUTABLE(ImageFileWriter ImageFileWriter.cxx) TARGET_LINK_LIBRARIES(ImageFileWriter ITKIO)

</source>