ITK/Examples/IO/ImageFileWriter: Difference between revisions
From KitwarePublic
Jump to navigationJump to search
Daviddoria (talk | contribs) (Created page with "==WriteImage.cxx== <source lang="cpp"> #include "itkImage.h" #include "itkImageFileWriter.h" #include <iostream> #include <string> int main(int argc, char *argv[]) { std::str...") |
Daviddoria (talk | contribs) |
||
Line 62: | Line 62: | ||
INCLUDE(${ITK_USE_FILE}) | INCLUDE(${ITK_USE_FILE}) | ||
ADD_EXECUTABLE(WriteImage WriteImage. | ADD_EXECUTABLE(WriteImage WriteImage.cxx) | ||
TARGET_LINK_LIBRARIES(WriteImage ITKIO) | TARGET_LINK_LIBRARIES(WriteImage ITKIO) | ||
</source> | </source> |
Revision as of 01:11, 14 October 2010
WriteImage.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(WriteImage)
FIND_PACKAGE(ITK REQUIRED) INCLUDE(${ITK_USE_FILE})
ADD_EXECUTABLE(WriteImage WriteImage.cxx) TARGET_LINK_LIBRARIES(WriteImage ITKIO)
</source>