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

Stéphane CALANDE scalande at gmail.com
Wed Oct 22 10:47:40 EDT 2008


Dan,

Thank you very much for the code you sent me. It is really very kind from
your part.

But there is a thing that I don't understand...
Just to test, I modified the file and I added the line :


std::cout << "static_cast< TOutput >(input[i]) = " << static_cast< TOutput
>(input[i]) << std::endl;

in the for :


AccumulatorType mean = NumericTraits< TOutput >::Zero;
   for( unsigned int i=0; i< input.size(); i++ )
     {
     std::cout << "static_cast< TOutput >(input[i]) = " << static_cast<
TOutput >(input[i]) << std::endl;
     mean += static_cast< TOutput >(input[i]);
     }
     std::cout << std::endl;
   return static_cast<TOutput>( mean / input.size() );


When I launch my program to calculate the average of multiple images, the
line I've just added show me always the same pixel value for the 5 different
images.


Example :


static_cast< TOutput >(input[i]) = 4294966307
static_cast< TOutput >(input[i]) = 4294966307
static_cast< TOutput >(input[i]) = 4294966307
static_cast< TOutput >(input[i]) = 4294966307
static_cast< TOutput >(input[i]) = 4294966307

static_cast< TOutput >(input[i]) = 4294966311
static_cast< TOutput >(input[i]) = 4294966311
static_cast< TOutput >(input[i]) = 4294966311
static_cast< TOutput >(input[i]) = 4294966311
static_cast< TOutput >(input[i]) = 4294966311

etc...


Or, my 5 images are different... I think it's not normal. After testing, I
think that the values are the value of the last images that I gave as input.
For example, if I give as input multiple 'normal' images and then a
BLACK-image, all the values are "0".


Do you think it's an error in the program I created?

Here's the source code :

(Thank you very much, Stéphane)




#include "itkImage.h"
 #include "itkImageFileReader.h"
 #include "itkImageFileWriter.h"
 #include "itkImageIOBase.h"
 #include "itkNaryMeanImageFilter.h"

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

 {

 if( argc < 4 )

 {

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

 std::cerr << argv[0] << " Image1.mhd Image2.mhd [ImageX.mhd]*
NomImageOutput.mhd" << std::endl;

 return EXIT_FAILURE;

 }

 typedef   unsigned int PixelType; // être sûr que c'est le bon type !!

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

 typedef itk::ImageFileReader< ImageType > ReaderType;

 typedef itk::ImageFileWriter< ImageType > WriterType;

 typedef itk::NaryMeanImageFilter< ImageType,
                                  ImageType > MeanFilterType;

 int nbImages = argc - 2;

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

 MeanFilterType::Pointer addition = MeanFilterType::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] << "] ajoutée" <<
std::endl << std::endl;
}

 addition-> Update();

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

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

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

 std::cout << "Ecriture du fichier..." << std::endl << std::endl;

 writer->Update();

 std::cout << "Fichier '" << argv[nbImages+1] << "' créé" << std::endl;

 return EXIT_SUCCESS;

 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20081022/307039ed/attachment-0001.htm>


More information about the Insight-users mailing list