ITK/Examples/IO/ImageFileWriter: Difference between revisions
From KitwarePublic
Jump to navigationJump to search
Daviddoria (talk | contribs) |
Daviddoria (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
== | ==ImageFileWriter.cxx== | ||
<source lang="cpp"> | <source lang="cpp"> | ||
#include "itkImage.h" | #include "itkImage.h" | ||
Line 57: | Line 57: | ||
cmake_minimum_required(VERSION 2.6) | cmake_minimum_required(VERSION 2.6) | ||
PROJECT( | PROJECT(ImageFileWriter) | ||
FIND_PACKAGE(ITK REQUIRED) | FIND_PACKAGE(ITK REQUIRED) | ||
INCLUDE(${ITK_USE_FILE}) | INCLUDE(${ITK_USE_FILE}) | ||
ADD_EXECUTABLE( | ADD_EXECUTABLE(ImageFileWriter ImageFileWriter.cxx) | ||
TARGET_LINK_LIBRARIES( | TARGET_LINK_LIBRARIES(ImageFileWriter ITKIO) | ||
</source> | </source> |
Revision as of 16:12, 21 October 2010
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>