Append Two 3D Volumes#


Append two 3D volumes in the Z-direction.


Input image

Input image#

Output image

Output image#



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

main(int argc, char * argv[])
  if (argc != 4)
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0];
    std::cerr << " <InputFileName1> <InputFileName2> <OutputFileName>";
    std::cerr << std::endl;
    return EXIT_FAILURE;
  const char * inputFileName1 = argv[1];
  const char * inputFileName2 = argv[2];
  const char * outputFileName = argv[3];

  constexpr unsigned int Dimension = 3;

  using PixelType = unsigned char;
  using ImageType = itk::Image<PixelType, Dimension>;

  const auto input1 = itk::ReadImage<ImageType>(inputFileName1);
  const auto input2 = itk::ReadImage<ImageType>(inputFileName2);

  using TileFilterType = itk::TileImageFilter<ImageType, ImageType>;
  auto tileFilter = TileFilterType::New();
  tileFilter->SetInput(0, input1);
  tileFilter->SetInput(1, input2);
  TileFilterType::LayoutArrayType layout;
  layout[0] = 1;
  layout[1] = 1;
  layout[2] = 2;

    itk::WriteImage(tileFilter->GetOutput(), outputFileName);
  catch (const itk::ExceptionObject & error)
    std::cerr << "Error: " << error << std::endl;
    return EXIT_FAILURE;

  return EXIT_SUCCESS;

Classes demonstrated#

template<typename TInputImage, typename TOutputImage>
class TileImageFilter : public itk::ImageToImageFilter<TInputImage, TOutputImage>

Tile multiple input images into a single output image.

This filter will tile multiple images using a user-specified layout. The tile sizes will be large enough to accommodate the largest image for each tile. The layout is specified with the SetLayout method. The layout has the same dimension as the output image. If all entries of the layout are positive, the tiled output will contain the exact number of tiles. If the layout contains a 0 in the last dimension, the filter will compute a size that will accommodate all of the images. Empty tiles are filled with the value specified with the SetDefault value method. The input images must have a dimension less than or equal to the output image. The output image have a larger dimension than the input images. This filter can be used to create a volume from a series of inputs by specifying a layout of 1,1,0.

ITK Sphinx Examples:

See itk::TileImageFilter for additional documentation.