Dan,<br><br>Thank you very much for the code you sent me. It is really very kind from your part.<br><br>But there is a thing that I don't understand...<br>Just to test, I modified the file and I added the line :<br><br>
<br><span style="font-family: courier new,monospace;">std::cout << "static_cast< TOutput >(input[i]) = " << static_cast< TOutput >(input[i]) << std::endl;</span><br><br>in the for :<br>
<br><br><span style="font-family: courier new,monospace;">AccumulatorType mean = NumericTraits< TOutput >::Zero;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> for( unsigned int i=0; i< input.size(); i++ )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> std::cout << "static_cast< TOutput >(input[i]) = " << static_cast< TOutput >(input[i]) << std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> mean += static_cast< TOutput >(input[i]);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> std::cout << std::endl;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return static_cast<TOutput>( mean / input.size() );</span><br>
<br><br>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.<br><br><br>Example :<br><br><br>static_cast< TOutput >(input[i]) = 4294966307<br>
static_cast< TOutput >(input[i]) = 4294966307<br>static_cast< TOutput >(input[i]) = 4294966307<br>static_cast< TOutput >(input[i]) = 4294966307<br>static_cast< TOutput >(input[i]) = 4294966307<br><br>
static_cast< TOutput >(input[i]) = 4294966311<br>static_cast< TOutput >(input[i]) = 4294966311<br>static_cast< TOutput >(input[i]) = 4294966311<br>static_cast< TOutput >(input[i]) = 4294966311<br>static_cast< TOutput >(input[i]) = 4294966311<br>
<br>etc...<br><br><br>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".<br>
<br><br>Do you think it's an error in the program I created?<br><br>Here's the source code :<br><br>(Thank you very much, Stéphane)<br><br><br><font size="2"><br><br></font><font size="1"><font size="2"><span style="font-family: courier new,monospace;">#include "itkImage.h"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> #include "itkImageFileReader.h"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> #include "itkImageFileWriter.h"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> #include "itkImageIOBase.h"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> #include "itkNaryMeanImageFilter.h"</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> int main( int argc, char * argv[] )</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if( argc < 4 )</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> std::cerr << "Usage: " << std::endl;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> std::cerr << argv[0] << " Image1.mhd Image2.mhd [ImageX.mhd]* NomImageOutput.mhd" << std::endl;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return EXIT_FAILURE;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> typedef unsigned int PixelType; // être sûr que c'est le bon type !! </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> typedef itk::Image< PixelType, 3 > ImageType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> typedef itk::ImageFileReader< ImageType > ReaderType;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> typedef itk::ImageFileWriter< ImageType > WriterType;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> typedef itk::NaryMeanImageFilter< ImageType,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ImageType > MeanFilterType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> int nbImages = argc - 2;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ReaderType::Pointer reader = ReaderType::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> MeanFilterType::Pointer addition = MeanFilterType::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> std::cout << std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> for (int i = 0 ; i < nbImages ; i++)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">{ </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> reader->SetFileName( argv[i+1] );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> reader->Update();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> addition->SetInput( i , reader->GetOutput() );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> std::cout << "Image n°" << i+1 << " [" << argv[i+1] << "] ajoutée" << std::endl << std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">}</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> addition-> Update();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> WriterType::Pointer writer = WriterType::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> writer->SetFileName( argv[nbImages+1] );</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> writer->SetInput(addition->GetOutput());</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> std::cout << "Ecriture du fichier..." << std::endl << std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> writer->Update();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> std::cout << "Fichier '" << argv[nbImages+1] << "' créé" << std::endl;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return EXIT_SUCCESS;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <br><br><br><br style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span></font><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><br style="font-family: courier new,monospace;">
</font><br>