Difference between revisions of "ITK/Examples/ImageProcessing/TileImageFilter CreateVolume"

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Created page with "==MultiplyImageFilter.cxx== <source lang="cpp"> #include "itkTileImageFilter.h" #include "itkImageFileReader.h" #include "itkImageFileWriter.h" #include "itkImage.h" int main(in...")
 
Line 1: Line 1:
==MultiplyImageFilter.cxx==
==TileImageFilter.cxx==
<source lang="cpp">
<source lang="cpp">
#include "itkTileImageFilter.h"
#include "itkTileImageFilter.h"
Line 22: Line 22:
   typedef itk::ImageFileWriter< OutputImageType > WriterType;
   typedef itk::ImageFileWriter< OutputImageType > WriterType;


   if (argc < 6)
   if (argc < 4)
     {
     {
     std::cerr << "Usage: " << std::endl;
     std::cerr << "Usage: " << std::endl;
     std::cerr << argv[0] << " iSize jSize kSize input1 input2 ... inputn output" << std::endl;
     std::cerr << argv[0] << "input1 input2 ... inputn output" << std::endl;
     return EXIT_FAILURE;
     return EXIT_FAILURE;
     }
     }
Line 45: Line 45:
   InputImageType::Pointer inputImageTile;
   InputImageType::Pointer inputImageTile;


   for (int i = 3; i < argc - 1; i++)
   for (int i = 1; i < argc - 1; i++)
     {
     {
     reader->SetFileName( argv[i] );
     reader->SetFileName( argv[i] );
Line 78: Line 78:
   return EXIT_SUCCESS;
   return EXIT_SUCCESS;
}
}
</source>
</source>



Revision as of 04:15, 20 February 2011

TileImageFilter.cxx

#include "itkTileImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkImage.h"

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

  typedef unsigned char  PixelType;
  const unsigned int InputImageDimension = 2;
  const unsigned int OutputImageDimension = 3;

  typedef itk::Image< PixelType, InputImageDimension  >   InputImageType;
  typedef itk::Image< PixelType, OutputImageDimension >   OutputImageType;

  typedef itk::ImageFileReader< InputImageType > ImageReaderType ;

  typedef itk::TileImageFilter< InputImageType, OutputImageType > TilerType;

  typedef itk::ImageFileWriter< OutputImageType > WriterType;

  if (argc < 4)
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << "input1 input2 ... inputn output" << std::endl;
    return EXIT_FAILURE;
    }

  TilerType::Pointer tiler = TilerType::New();

  itk::FixedArray< unsigned int, OutputImageDimension > layout;

  layout[0] = 1;
  layout[1] = 1;
  layout[2] = 0;

  tiler->SetLayout( layout );

  unsigned int inputImageNumber = 0;

  ImageReaderType::Pointer reader = ImageReaderType::New();

  InputImageType::Pointer inputImageTile;

  for (int i = 1; i < argc - 1; i++)
    {
    reader->SetFileName( argv[i] );
    reader->UpdateLargestPossibleRegion();
    inputImageTile = reader->GetOutput();
    inputImageTile->DisconnectPipeline();
    tiler->SetInput( inputImageNumber++, inputImageTile );
    }

  PixelType filler = 128;

  tiler->SetDefaultPixelValue( filler );

  tiler->Update();

  WriterType::Pointer writer = WriterType::New();

  writer->SetInput( tiler->GetOutput() );

  writer->SetFileName( argv[argc-1] );

  try
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & excp )
    {
    std::cerr << excp << std::endl;
    return EXIT_FAILURE;
    }

  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
if(COMMAND CMAKE_POLICY)
  cmake_policy(SET CMP0003 NEW)
endif(COMMAND CMAKE_POLICY)

project(TileImageFilter)

find_package(ITK REQUIRED)
include(${ITK_USE_FILE})

add_executable(TileImageFilter TileImageFilter.cxx )

target_link_libraries(TileImageFilter ${ITK_LIBRARIES})