ITK/Examples/IO/ImageFileWriter
From KitwarePublic
< ITK | Examples
Jump to navigationJump to search
Revision as of 16:12, 21 October 2010 by Daviddoria (talk | contribs)
ImageFileWriter.cxx
<source lang="cpp">
- include "itkImage.h"
- include "itkImageFileWriter.h"
- include <iostream>
- 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 0;
} </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>