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&#39;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 &lt;&lt; &quot;static_cast&lt; TOutput &gt;(input[i]) = &quot; &lt;&lt; static_cast&lt; TOutput &gt;(input[i]) &lt;&lt; std::endl;</span><br><br>in the for :<br>
<br><br><span style="font-family: courier new,monospace;">AccumulatorType mean = NumericTraits&lt; TOutput &gt;::Zero;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp; for( unsigned int i=0; i&lt; input.size(); i++ )</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp; {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;static_cast&lt; TOutput &gt;(input[i]) = &quot; &lt;&lt; static_cast&lt; TOutput &gt;(input[i]) &lt;&lt; std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; &nbsp;mean += static_cast&lt; TOutput &gt;(input[i]);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp;&nbsp; }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; &nbsp;std::cout &lt;&lt; std::endl;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp; return static_cast&lt;TOutput&gt;( mean / input.size() );</span><br>
<br><br>When I launch my program to calculate the average of multiple images, the line I&#39;ve just added show me always the same pixel value for the 5 different images.<br><br><br>Example :<br><br><br>static_cast&lt; TOutput &gt;(input[i]) = 4294966307<br>
static_cast&lt; TOutput &gt;(input[i]) = 4294966307<br>static_cast&lt; TOutput &gt;(input[i]) = 4294966307<br>static_cast&lt; TOutput &gt;(input[i]) = 4294966307<br>static_cast&lt; TOutput &gt;(input[i]) = 4294966307<br><br>
static_cast&lt; TOutput &gt;(input[i]) = 4294966311<br>static_cast&lt; TOutput &gt;(input[i]) = 4294966311<br>static_cast&lt; TOutput &gt;(input[i]) = 4294966311<br>static_cast&lt; TOutput &gt;(input[i]) = 4294966311<br>static_cast&lt; TOutput &gt;(input[i]) = 4294966311<br>
<br>etc...<br><br><br>Or, my 5 images are different... I think it&#39;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 &#39;normal&#39; images and then a BLACK-image, all the values are &quot;0&quot;.<br>
<br><br>Do you think it&#39;s an error in the program I created?<br><br>Here&#39;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 &quot;itkImage.h&quot;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;#include &quot;itkImageFileReader.h&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;#include &quot;itkImageFileWriter.h&quot;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;#include &quot;itkImageIOBase.h&quot;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;#include &quot;itkNaryMeanImageFilter.h&quot;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;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;">&nbsp;{</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;if( argc &lt; 4 )</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;{</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;std::cerr &lt;&lt; &quot;Usage: &quot; &lt;&lt; std::endl;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;std::cerr &lt;&lt; argv[0] &lt;&lt; &quot; Image1.mhd Image2.mhd [ImageX.mhd]* NomImageOutput.mhd&quot; &lt;&lt; std::endl;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;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;">&nbsp;}</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;typedef&nbsp;&nbsp; unsigned int PixelType; // être sûr que c&#39;est le bon type !!&nbsp; </span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;typedef itk::Image&lt; PixelType, 3 &gt; ImageType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;typedef itk::ImageFileReader&lt; ImageType &gt; ReaderType;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;typedef itk::ImageFileWriter&lt; ImageType &gt; WriterType;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;typedef itk::NaryMeanImageFilter&lt; ImageType,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; ImageType &gt; MeanFilterType;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;int nbImages = argc - 2;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;ReaderType::Pointer reader = ReaderType::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;MeanFilterType::Pointer addition = MeanFilterType::New();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;std::cout &lt;&lt; std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;for (int i = 0 ; i &lt; nbImages ; i++)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">{&nbsp;&nbsp;&nbsp; </span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; reader-&gt;SetFileName( argv[i+1] );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; reader-&gt;Update();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; addition-&gt;SetInput( i , reader-&gt;GetOutput() );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;Image n°&quot; &lt;&lt; i+1 &lt;&lt; &quot; [&quot; &lt;&lt; argv[i+1] &lt;&lt; &quot;] ajoutée&quot; &lt;&lt; std::endl &lt;&lt; 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;">&nbsp;addition-&gt; Update();</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;WriterType::Pointer writer = WriterType::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;writer-&gt;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;">&nbsp;writer-&gt;SetInput(addition-&gt;GetOutput());</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;std::cout &lt;&lt; &quot;Ecriture du fichier...&quot; &lt;&lt; std::endl &lt;&lt; std::endl;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;writer-&gt;Update();</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;std::cout &lt;&lt; &quot;Fichier &#39;&quot; &lt;&lt; argv[nbImages+1] &lt;&lt; &quot;&#39; créé&quot; &lt;&lt; std::endl;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;return EXIT_SUCCESS;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;<br><br><br><br style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">&nbsp;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">&nbsp;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;</span></font><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">&nbsp;</span><br style="font-family: courier new,monospace;">
</font><br>