[Insight-users] ITK example that sums multiple metaheader images

Stéphane CALANDE scalande at gmail.com
Thu Oct 16 08:54:08 EDT 2008


Hi,

Thank you very much for your response Luis.
Meanwhile, I've used the NaryAddImageFilter to resolve my problem.
Here is the code for those that could be interrested in the subject :





 #include "itkImage.h"
 #include "itkImageFileReader.h"
 #include "itkImageFileWriter.h"
 #include "itkAddImageFilter.h"
 #include "itkImageIOBase.h"
 #include "itkNaryAddImageFilter.h"

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

 {

 if( argc < 4 )

 {

 std::cerr << "Usage: " << std::endl;

 std::cerr << argv[0] << " Image1 Image2 [ImageX]* ImageOutput" <<
std::endl;

 return EXIT_FAILURE;

 }

 typedef   unsigned int PixelType; // be sure it's the good type !!

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

 typedef itk::ImageFileReader< ImageType > ReaderType;

 typedef itk::ImageFileWriter< ImageType > WriterType;

 typedef itk::NaryAddImageFilter< ImageType,
                                  ImageType > AddFilterType;

 int nbImages = argc - 2;

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

 AddFilterType::Pointer addition = AddFilterType::New();

 std::cout << std::endl;

 for (int i = 0 ; i < nbImages ; i++)
{
    reader->SetFileName( argv[i+1] );
    reader->Update();
    addition->SetInput( i , reader->GetOutput() );
    std::cout << "Image n°" << i+1 << " [" << argv[i+1] << "] added" <<
std::endl << std::endl;
}

 addition-> Update();

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

 writer->SetFileName( argv[nbImages+1] );

 writer->SetInput(addition->GetOutput());

 std::cout << "Writing file..." << std::endl << std::endl;

 writer->Update();

 std::cout << "File '" << argv[nbImages+1] << "' created" << std::endl;

 return EXIT_SUCCESS;

 }







Bye,



Stéphane
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20081016/b0d5956b/attachment-0001.htm>


More information about the Insight-users mailing list