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

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Deprecated content that is moved to sphinx)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This example reads in a series of 2D images and stacks them to create a 3D image.
{{warning|1=The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/pages likely require ITK version 4.13 or earlier releasesIn many cases, the examples on this page no longer conform to the best practices for modern ITK versions.
 
}}
==TileImageFilter_CreateVolume.cxx==
<source lang="cpp">
#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] = 2;
  layout[1] = 2;
  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;
}
</source>
 
{{ITKCMakeLists|{{SUBPAGENAME}}}}

Latest revision as of 20:19, 5 June 2019

Warning: The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.