[Insight-users] 2D png to 3D gipl : ImageSeriesReader
Luis Ibanez
luis . ibanez at kitware . com
Mon, 29 Sep 2003 11:44:06 -0400
Hi Jianguo,
Please find below an example of code that will read
a set of .PNG files and save them in a single GIPL
image file.
Regards
Luis
---------------------------
#include "itkNumericSeriesFileNames.h"
#include "itkImageSeriesReader.h"
#include "itkImageFileWriter.h"
#include "itkImage.h"
int main(int argc, char * argv[])
{
typedef itk::Image<unsigned char,3> Image3DType;
//
// Here we generate filenames like
// myImage000.png, myImage001.png .... to myImage200.png
//
itk::NumericSeriesFileNames::Pointer fileIter =
itk::NumericSeriesFileNames::New();
fileIter->SetStartIndex( 0 );
fileIter->SetEndIndex( 200 );
fileIter->SetIncrementIndex( 1 );
fileIter->SetSeriesFormat("myImages%03d.png");
itk::ImageSeriesReader<Image3DType>::Pointer reader =
itk::ImageSeriesReader<Image3DType>::New();
reader->SetFileNames( fileIter->GetFileNames() );
reader->Update();
//
// Here we save the image in GIPL format
//
itk::ImageFileWriter< Image3DType >::Pointer writer =
itk::ImageFileWriter< Image3DType >::New();
writer->SetInput( reader->GetOutput() );
writer->SetFileName("myImage.gipl");
writer->Update();
return 0;
}
-------------------
Rao Jianguo wrote:
> Dear All,
>
> I am going to make an application.
>
> My intention is to make a code to read in series of 2D image files
> in png format, then stack them up to form a 3D image and
> output it in gipl format.
>
> If someone there have already done this could you please let me know
> to avoid reinventing the wheel.
>
> Thanks for your attention.
>
>
>
> Jianguo
>
>