[Insight-users] read and write image series

shirani kannangara mangalika673 at gmail.com
Tue Sep 18 06:23:50 EDT 2012


Hi vtk/itk users
I am constructing a program to read and write medical image(3D) data set ,
 image data(raw data -VHPAbdomen.mhd)in ITk version 4.2 ,CMake2.8.9. IT
built with 2 warnings.
 itk codes are as follows.But it does not display output properly. It is as
follows.My raw data file is attached herewith.I used
ImageSeriesReadWrite.cxx
*
*
*
*
*codes*
#include "itkImage.h"
#include "itkImageSeriesReader.h"
#include "itkImageFileWriter.h"
#include "itkNumericSeriesFileNames.h"
#include "itkPNGImageIO.h"
    #include <iostream>
        #include <string>
    using namespace std;

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

{
    if( argc <4 );

  {std::cout << "Usage: " << std::endl;
    std::cout<<argv[0] <<  " firstSliceValue lastSliceValue
 outputImageFile " << std::endl;
   return EXIT_FAILURE;
    }

  //std::cout<<"sliceValue:"<<std::endl;
  typedef unsigned char                       PixelType;
  const unsigned int   Dimension = 3;

  typedef itk::Image< PixelType, Dimension>  ImageType;

  typedef itk::ImageSeriesReader< ImageType >  ReaderType;
  typedef itk::ImageFileWriter<   ImageType >  WriterType;


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

  const unsigned int first = 1;
  const unsigned int last  = 450;
  //char * outputFilename = argv[3];
   char**outputFilename=  argv[3];

  typedef itk::NumericSeriesFileNames NameGeneratorType;

  NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();

  nameGenerator->SetSeriesFormat( "D:\\To_SMK\\VHPAbdomen%03d.mhd" );
  nameGenerator->SetStartIndex( first );
  nameGenerator->SetEndIndex( last);
  nameGenerator->SetIncrementIndex(1);

  reader->SetImageIO( itk::PNGImageIO::New() );

  reader->SetFileNames( nameGenerator->GetFileNames()  );
  writer->SetInput( reader->GetOutput() );
  writer->SetFileName("test.mhd");
try
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & err )
    {
    std::cerr << "ExceptionObject caught !" << std::endl;
    std::cerr << err << std::endl;
    return EXIT_FAILURE;
    };

  return 0;

  }

*OUTPUT*

D:\image\Debug>ImageReadWrite.exe
Usage:
0022D9E0 firstSliceValue lastSliceValue  outputImageFile

D:\image\Debug>ImageReadWrite.exe(1 450 test.mhd)
Usage:
00E71324 firstSliceValue lastSliceValue  outputImageFile

D:\image\Debug>ImageReadWrite.exe(1,450,test.mhd)
Usage:
0115131C firstSliceValue lastSliceValue  outputImageFile

D:\image\Debug>

PL help me to get it corrected
Thankas

Shirani
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120918/74ee084d/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: VHPAbdomen.mhd
Type: application/octet-stream
Size: 6522 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120918/74ee084d/attachment.obj>


More information about the Insight-users mailing list