I'm new to ITK and I'm currently having problems assemble my series of Tiff files into a vtkImage. I've simply edited the PNGSeriesWriter example. A vtk image does get generated, and I've managed to load it in VolView and MicroView by using ITK
2.4.1. However, when I look at the volume, the whole volume is composed of only the first Tiff file , and is repeated along the z axis. <br><br>Anyone know how to fix this? Help is greatly appreciated. I've pasted my code below.
<br><br>Jon<br><br>/*=========================================================================<br><br> Program: Insight Segmentation & Registration Toolkit<br> Module: $RCSfile: ImageSeriesReadWrite.cxx,v $<br>
Language: C++<br> Date: $Date: 2005/11/20 13:27:53 $<br> Version: $Revision: 1.10 $<br><br> Copyright (c) Insight Software Consortium. All rights reserved.<br> See ITKCopyright.txt or <a href="http://www.itk.org/HTML/Copyright.htm">
http://www.itk.org/HTML/Copyright.htm</a> for details.<br><br> This software is distributed WITHOUT ANY WARRANTY; without even <br> the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR <br> PURPOSE. See the above copyright notices for more information.
<br><br>=========================================================================*/<br>#if defined(_MSC_VER)<br>#pragma warning ( disable : 4786 )<br>#endif<br><br>#ifdef __BORLANDC__<br>#define ITK_LEAN_AND_MEAN<br>#endif
<br><br>// Software Guide : BeginLatex<br>//<br>// This example illustrates how to read a series of 2D slices from independent<br>// files in order to compose a volume. The class \doxygen{ImageSeriesReader}<br>// is used for this purpose. This class works in combination with a generator
<br>// of filenames that will provide a list of files to be read. In this<br>// particular example we use the \doxygen{NumericSeriesFileNames} class as<br>// filename generator. This generator uses a \code{printf} style of string format
<br>// with a ``\code{\%d}'' field that will be successively replaced by a number specified<br>// by the user. Here we will use a format like ``\code{file\%03d.png}'' for reading <br>// PNG files named file001.png, file002.png
, file003.png... and so on.<br>//<br>// This requires the following headers as shown.<br>//<br>// \index{itk::ImageSeriesReader!header}<br>// \index{itk::NumericSeriesFileNames!header}<br>//<br>// Software Guide : EndLatex
<br><br>// Software Guide : BeginCodeSnippet<br>#include "itkImage.h"<br>#include "itkImageSeriesReader.h"<br>#include "itkImageFileWriter.h"<br>#include "itkNumericSeriesFileNames.h"
<br>#include "itkTIFFImageIO.h"<br>// Software Guide : EndCodeSnippet<br><br><br>int main( int argc, char ** argv )<br>{<br> // Verify the number of parameters in the command line<br> if( argc < 4 )<br> {
<br> std::cerr << "Usage: " << std::endl;<br> std::cerr << argv[0] << " firstSliceValue lastSliceValue outputImageFile " << std::endl;<br> return EXIT_FAILURE;<br>
}<br><br><br>// Software Guide : BeginLatex<br>//<br>// We start by defining the \code{PixelType} and \code{ImageType}.<br>//<br>//<br>// Software Guide : EndLatex <br><br>// Software Guide : BeginCodeSnippet<br> typedef unsigned char PixelType;
<br> const unsigned int Dimension = 3;<br><br> typedef itk::Image< PixelType, Dimension > ImageType;<br><br> typedef itk::ImageSeriesReader< ImageType > ReaderType;<br> typedef itk::ImageFileWriter< ImageType > WriterType;
<br><br> ReaderType::Pointer reader = ReaderType::New();<br> WriterType::Pointer writer = WriterType::New();<br><br> const unsigned int first = atoi( argv[1] );<br> const unsigned int last = atoi( argv[2] );<br><br> const char * outputFilename = argv[3];
<br><br><br> typedef itk::NumericSeriesFileNames NameGeneratorType;<br><br> NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();<br><br> nameGenerator->SetSeriesFormat( "vol%03d.tiff" ); //set file name imageformat here
<br><br> nameGenerator->SetStartIndex( first );<br> nameGenerator->SetEndIndex( last );<br> nameGenerator->SetIncrementIndex( 1 );<br><br> reader->SetImageIO( itk::TIFFImageIO::New() );<br><br> reader->SetFileNames( nameGenerator->GetFileNames() );
<br> <br> writer->SetFileName( outputFilename );<br><br> try<br> {<br> reader->Update();<br> }<br> catch( itk::ExceptionObject & err ) <br> {<br> std::cerr << "ExceptionObject caught !" << std::endl;
<br> std::cerr << err << std::endl; <br> return EXIT_FAILURE;<br> }<br>/*<br> // JW: Get Image set spacing<br> ImageType::Pointer image = reader->GetOutput();<br><br> ImageType::SpacingType spacing;
<br><br> // Note: measurement units (in this application it's in mm)<br> spacing[0] = 0.021; // spacing along X<br> spacing[1] = 0.021; // spacing along Y<br> spacing[2] = 0.022; // spacing along Z<br><br><br> image->SetSpacing( spacing );
<br><br> ImageType::PointType origin;<br><br> origin[0] = 0.0; // coordinates of the <br> origin[1] = 0.0; // first pixel in N-D<br> origin[2] = 0.0;<br><br> image->SetOrigin( origin );<br><br> const ImageType::SpacingType& sp = image->GetSpacing();
<br><br> std::cout << "Spacing = ";<br> std::cout << sp[0] << ", " << sp[1] << ", " << sp[2] << std::endl;<br><br> writer->SetInput( image );<br>
// Software Guide : EndCodeSnippet<br> */ <br> writer->SetInput(reader->GetOutput());<br><br> try <br> { <br> writer->Update();<br> <br> } <br> catch( itk::ExceptionObject & err ) <br> {
<br> std::cerr << "ExceptionObject caught !" << std::endl; <br> std::cerr << err << std::endl; <br> return EXIT_FAILURE;<br> } <br>// Software Guide : EndCodeSnippet<br><br><br>
return EXIT_SUCCESS;<br>}<br><br><br><br><br>