[Insight-users] Re: Re: format conversion

Dalal, Dhaval dalal at bnl.gov
Mon Apr 25 12:14:23 EDT 2005


 
Hi Amadeus
I installed mplayer on windows using cygwin.
I read in an avi file and output all the frames in jpeg...
I ran your code and it works fine on windows..
Thanks for your solution.
Dhaval

-----Original Message-----
From: insight-users-bounces at itk.org
To: insight-users at itk.org
Sent: 4/24/2005 1:59 PM
Subject: [Insight-users] Re: Re: format conversion

On Sun, 24 Apr 2005 12:13:04 -0400, Stephen R. Aylward wrote:

> Hi Amadeus,
> 
> Thanks for the tip.
> 
> I've added this to the ITK file format wiki:
> http://www.itk.org/Wiki/ITK_File_Formats
> 
> Are you willing to contribute your modifications to 
> ImageSeriesReadWrite, if they are cross-platform?
> 

Absolutely. Don't know if the shell in Windows understands
wildcards, maybe cygwin. Here's the code:


// Read a sequence of 2D images, stack them and output a volume. 
// Cosmetic changes were applied to the original
ImageSeriesReadWrite.cxx
// in order to allow the convenience of using wildcards on the command
line,
// on systems that support that. 
// 
// Author: Silviu Minut
// Date: Apr 23 2005
// minutsil at cse.msu.edu


#include "itkImage.h"
#include "itkImageSeriesReader.h"
#include "itkImageFileWriter.h"
#include "itkNumericSeriesFileNames.h"
#include "itkPNGImageIO.h"

#include <vector>

using std::vector;
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::string;



void usage(char * prog)
{
    cerr << endl << "\e[1;31mUsage: \e[0m" 
	 << prog << " 2Dframe*.xxx output.yyy" << endl 
	 << endl;
    
    cerr << "\e[1;34mPurpose: \e[0m" << endl
	 << "\tRead a sequence of at least two images, stack them into
a\n"
	 << "\tvolume and output a 3D itk image, which can be then
used\n"
	 << "\te.g. in the GeodesicActiveContour application." << endl
<< endl
	 << "\tThe format of the input and output images is inferred" <<
endl
	 << "\tfrom the extension." << endl
	 << endl
	 << "\tIf you input images in an unsupported format, itk will"
<< endl
	 << "\tcomplain and will output a list of supported formats." <<
endl
	 << "\tSee also: http://www.itk.org/Wiki/ITK_File_Formats ."
	 << endl
	 << endl;
    exit(-1);
}


int main( int argc, char ** argv )
{   
    size_t i=0;
    vector<string> ifile;

    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;
    WriterType::Pointer writer;


    // itkImageSeriesReader requires at least two input files.
    // We also need an output file name. 
    if(argc<4)  
	usage(argv[0]);
    
    // Store the input file names into a vector of strings,
    // which will be passed on to the reader. 
    for(i=1; i<argc-1; i++)
	ifile.push_back(string(argv[i]));

    // Read the input images.
    reader = ReaderType::New();

    // This is how one would enforce reading a certain format (e.g.
png):
    // reader->SetImageIO( itk::PNGImageIO::New() );
    reader->SetFileNames( ifile );
    try { 
	reader->Update();
    }
    catch( itk::ExceptionObject & excp ) {
	cerr << "Error reading the series." << endl;
	cerr << excp << endl;
    }


    // Write out.
    writer = WriterType::New();
    writer->SetFileName( argv[argc-1] );
    writer->SetInput( reader->GetOutput() );
    writer->Update();

    cerr << "Output: " << argv[argc-1] << endl;

    return 0;
}










_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users


More information about the Insight-users mailing list