It works !!<br><br>Thank you very very much Dan ;-)<br>You help me a lot!<br><br>Have a nice day !<br><br><br><br>Stéphane<br><br><br><br><br><div class="gmail_quote">2008/10/22 Dan Mueller <span dir="ltr">&lt;<a href="mailto:dan.muel@gmail.com">dan.muel@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Stéphane,<br>
<br>
I think you need to disconnect the reader output from the pipeline. I<br>
would do something as follows:<br>
<br>
MeanFilterType::Pointer mean = MeanFilterType::New();<br>
<div class="Ih2E3d"><br>
std::cout &lt;&lt; std::endl;<br>
<br>
for (int i = 0 ; i &lt; nbImages ; i++)<br>
{<br>
 &nbsp; &nbsp;reader-&gt;SetFileName( argv[i+1] );<br>
 &nbsp; &nbsp;reader-&gt;Update();<br>
</div> &nbsp; &nbsp;ImageType::Pointer input = reader-&gt;GetOutput();<br>
 &nbsp; &nbsp;input-&gt;DisconnectPipeline();<br>
 &nbsp; &nbsp;addition-&gt;SetInput( i , input );<br>
<div class="Ih2E3d"> &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;<br>
 &nbsp; &nbsp;std::endl &lt;&lt; std::endl;<br>
}<br>
<br>
</div>mean-&gt;Update();<br>
<br>
I hope this works...<br>
<br>
Cheers, Dan<br>
<div class="Ih2E3d"><br>
2008/10/22 Stéphane CALANDE &lt;<a href="mailto:scalande@gmail.com">scalande@gmail.com</a>&gt;:<br>
</div><div><div></div><div class="Wj3C7c">&gt; Dan,<br>
&gt;<br>
&gt; Thank you very much for the code you sent me. It is really very kind from<br>
&gt; your part.<br>
&gt;<br>
&gt; But there is a thing that I don&#39;t understand...<br>
&gt; Just to test, I modified the file and I added the line :<br>
&gt;<br>
&gt;<br>
&gt; std::cout &lt;&lt; &quot;static_cast&lt; TOutput &gt;(input[i]) = &quot; &lt;&lt; static_cast&lt; TOutput<br>
&gt;&gt;(input[i]) &lt;&lt; std::endl;<br>
&gt;<br>
&gt; in the for :<br>
&gt;<br>
&gt;<br>
&gt; AccumulatorType mean = NumericTraits&lt; TOutput &gt;::Zero;<br>
&gt; &nbsp; &nbsp;for( unsigned int i=0; i&lt; input.size(); i++ )<br>
&gt; &nbsp; &nbsp; &nbsp;{<br>
&gt; &nbsp; &nbsp; &nbsp;std::cout &lt;&lt; &quot;static_cast&lt; TOutput &gt;(input[i]) = &quot; &lt;&lt; static_cast&lt;<br>
&gt; TOutput &gt;(input[i]) &lt;&lt; std::endl;<br>
&gt; &nbsp; &nbsp; &nbsp;mean += static_cast&lt; TOutput &gt;(input[i]);<br>
&gt; &nbsp; &nbsp; &nbsp;}<br>
&gt; &nbsp; &nbsp; &nbsp;std::cout &lt;&lt; std::endl;<br>
&gt; &nbsp; &nbsp;return static_cast&lt;TOutput&gt;( mean / input.size() );<br>
&gt;<br>
&gt;<br>
&gt; When I launch my program to calculate the average of multiple images, the<br>
&gt; line I&#39;ve just added show me always the same pixel value for the 5 different<br>
&gt; images.<br>
&gt;<br>
&gt;<br>
&gt; Example :<br>
&gt;<br>
&gt;<br>
&gt; static_cast&lt; TOutput &gt;(input[i]) = 4294966307<br>
&gt; static_cast&lt; TOutput &gt;(input[i]) = 4294966307<br>
&gt; static_cast&lt; TOutput &gt;(input[i]) = 4294966307<br>
&gt; static_cast&lt; TOutput &gt;(input[i]) = 4294966307<br>
&gt; static_cast&lt; TOutput &gt;(input[i]) = 4294966307<br>
&gt;<br>
&gt; static_cast&lt; TOutput &gt;(input[i]) = 4294966311<br>
&gt; static_cast&lt; TOutput &gt;(input[i]) = 4294966311<br>
&gt; static_cast&lt; TOutput &gt;(input[i]) = 4294966311<br>
&gt; static_cast&lt; TOutput &gt;(input[i]) = 4294966311<br>
&gt; static_cast&lt; TOutput &gt;(input[i]) = 4294966311<br>
&gt;<br>
&gt; etc...<br>
&gt;<br>
&gt;<br>
&gt; Or, my 5 images are different... I think it&#39;s not normal. After testing, I<br>
&gt; think that the values are the value of the last images that I gave as input.<br>
&gt; For example, if I give as input multiple &#39;normal&#39; images and then a<br>
&gt; BLACK-image, all the values are &quot;0&quot;.<br>
&gt;<br>
&gt;<br>
&gt; Do you think it&#39;s an error in the program I created?<br>
&gt;<br>
&gt; Here&#39;s the source code :<br>
&gt;<br>
&gt; (Thank you very much, Stéphane)<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; #include &quot;itkImage.h&quot;<br>
&gt; &nbsp;#include &quot;itkImageFileReader.h&quot;<br>
&gt; &nbsp;#include &quot;itkImageFileWriter.h&quot;<br>
&gt; &nbsp;#include &quot;itkImageIOBase.h&quot;<br>
&gt; &nbsp;#include &quot;itkNaryMeanImageFilter.h&quot;<br>
&gt;<br>
&gt; &nbsp;int main( int argc, char * argv[] )<br>
&gt;<br>
&gt; &nbsp;{<br>
&gt;<br>
&gt; &nbsp;if( argc &lt; 4 )<br>
&gt;<br>
&gt; &nbsp;{<br>
&gt;<br>
&gt; &nbsp;std::cerr &lt;&lt; &quot;Usage: &quot; &lt;&lt; std::endl;<br>
&gt;<br>
&gt; &nbsp;std::cerr &lt;&lt; argv[0] &lt;&lt; &quot; Image1.mhd Image2.mhd [ImageX.mhd]*<br>
&gt; NomImageOutput.mhd&quot; &lt;&lt; std::endl;<br>
&gt;<br>
&gt; &nbsp;return EXIT_FAILURE;<br>
&gt;<br>
&gt; &nbsp;}<br>
&gt;<br>
&gt; &nbsp;typedef &nbsp; unsigned int PixelType; // être sûr que c&#39;est le bon type !!<br>
&gt;<br>
&gt; &nbsp;typedef itk::Image&lt; PixelType, 3 &gt; ImageType;<br>
&gt;<br>
&gt; &nbsp;typedef itk::ImageFileReader&lt; ImageType &gt; ReaderType;<br>
&gt;<br>
&gt; &nbsp;typedef itk::ImageFileWriter&lt; ImageType &gt; WriterType;<br>
&gt;<br>
&gt; &nbsp;typedef itk::NaryMeanImageFilter&lt; ImageType,<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ImageType &gt; MeanFilterType;<br>
&gt;<br>
&gt; &nbsp;int nbImages = argc - 2;<br>
&gt;<br>
&gt; &nbsp;ReaderType::Pointer reader = ReaderType::New();<br>
&gt;<br>
&gt; &nbsp;MeanFilterType::Pointer addition = MeanFilterType::New();<br>
&gt;<br>
&gt; &nbsp;std::cout &lt;&lt; std::endl;<br>
&gt;<br>
&gt; &nbsp;for (int i = 0 ; i &lt; nbImages ; i++)<br>
&gt; {<br>
&gt; &nbsp; &nbsp; reader-&gt;SetFileName( argv[i+1] );<br>
&gt; &nbsp; &nbsp; reader-&gt;Update();<br>
&gt; &nbsp; &nbsp; addition-&gt;SetInput( i , reader-&gt;GetOutput() );<br>
&gt; &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;<br>
&gt; std::endl &lt;&lt; std::endl;<br>
&gt; }<br>
&gt;<br>
&gt; &nbsp;addition-&gt; Update();<br>
&gt;<br>
&gt; &nbsp;WriterType::Pointer writer = WriterType::New();<br>
&gt;<br>
&gt; &nbsp;writer-&gt;SetFileName( argv[nbImages+1] );<br>
&gt;<br>
&gt; &nbsp;writer-&gt;SetInput(addition-&gt;GetOutput());<br>
&gt;<br>
&gt; &nbsp;std::cout &lt;&lt; &quot;Ecriture du fichier...&quot; &lt;&lt; std::endl &lt;&lt; std::endl;<br>
&gt;<br>
&gt; &nbsp;writer-&gt;Update();<br>
&gt;<br>
&gt; &nbsp;std::cout &lt;&lt; &quot;Fichier &#39;&quot; &lt;&lt; argv[nbImages+1] &lt;&lt; &quot;&#39; créé&quot; &lt;&lt; std::endl;<br>
&gt;<br>
&gt; &nbsp;return EXIT_SUCCESS;<br>
&gt;<br>
&gt; &nbsp;}<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div><br>