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"><<a href="mailto:dan.muel@gmail.com">dan.muel@gmail.com</a>></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 << std::endl;<br>
<br>
for (int i = 0 ; i < nbImages ; i++)<br>
{<br>
reader->SetFileName( argv[i+1] );<br>
reader->Update();<br>
</div> ImageType::Pointer input = reader->GetOutput();<br>
input->DisconnectPipeline();<br>
addition->SetInput( i , input );<br>
<div class="Ih2E3d"> std::cout << "Image n°" << i+1 << " [" << argv[i+1] << "] ajoutée" <<<br>
std::endl << std::endl;<br>
}<br>
<br>
</div>mean->Update();<br>
<br>
I hope this works...<br>
<br>
Cheers, Dan<br>
<div class="Ih2E3d"><br>
2008/10/22 Stéphane CALANDE <<a href="mailto:scalande@gmail.com">scalande@gmail.com</a>>:<br>
</div><div><div></div><div class="Wj3C7c">> Dan,<br>
><br>
> Thank you very much for the code you sent me. It is really very kind from<br>
> 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>
> std::cout << "static_cast< TOutput >(input[i]) = " << static_cast< TOutput<br>
>>(input[i]) << std::endl;<br>
><br>
> in the for :<br>
><br>
><br>
> AccumulatorType mean = NumericTraits< TOutput >::Zero;<br>
> for( unsigned int i=0; i< input.size(); i++ )<br>
> {<br>
> std::cout << "static_cast< TOutput >(input[i]) = " << static_cast<<br>
> TOutput >(input[i]) << std::endl;<br>
> mean += static_cast< TOutput >(input[i]);<br>
> }<br>
> std::cout << std::endl;<br>
> return static_cast<TOutput>( mean / input.size() );<br>
><br>
><br>
> When I launch my program to calculate the average of multiple images, the<br>
> line I've just added show me always the same pixel value for the 5 different<br>
> 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<br>
> think that the values are the value of the last images that I gave as input.<br>
> For example, if I give as input multiple 'normal' images and then a<br>
> 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>
><br>
><br>
> #include "itkImage.h"<br>
> #include "itkImageFileReader.h"<br>
> #include "itkImageFileWriter.h"<br>
> #include "itkImageIOBase.h"<br>
> #include "itkNaryMeanImageFilter.h"<br>
><br>
> int main( int argc, char * argv[] )<br>
><br>
> {<br>
><br>
> if( argc < 4 )<br>
><br>
> {<br>
><br>
> std::cerr << "Usage: " << std::endl;<br>
><br>
> std::cerr << argv[0] << " Image1.mhd Image2.mhd [ImageX.mhd]*<br>
> NomImageOutput.mhd" << std::endl;<br>
><br>
> return EXIT_FAILURE;<br>
><br>
> }<br>
><br>
> typedef unsigned int PixelType; // être sûr que c'est le bon type !!<br>
><br>
> typedef itk::Image< PixelType, 3 > ImageType;<br>
><br>
> typedef itk::ImageFileReader< ImageType > ReaderType;<br>
><br>
> typedef itk::ImageFileWriter< ImageType > WriterType;<br>
><br>
> typedef itk::NaryMeanImageFilter< ImageType,<br>
> ImageType > MeanFilterType;<br>
><br>
> int nbImages = argc - 2;<br>
><br>
> ReaderType::Pointer reader = ReaderType::New();<br>
><br>
> MeanFilterType::Pointer addition = MeanFilterType::New();<br>
><br>
> std::cout << std::endl;<br>
><br>
> for (int i = 0 ; i < nbImages ; i++)<br>
> {<br>
> reader->SetFileName( argv[i+1] );<br>
> reader->Update();<br>
> addition->SetInput( i , reader->GetOutput() );<br>
> std::cout << "Image n°" << i+1 << " [" << argv[i+1] << "] ajoutée" <<<br>
> std::endl << std::endl;<br>
> }<br>
><br>
> addition-> Update();<br>
><br>
> WriterType::Pointer writer = WriterType::New();<br>
><br>
> writer->SetFileName( argv[nbImages+1] );<br>
><br>
> writer->SetInput(addition->GetOutput());<br>
><br>
> std::cout << "Ecriture du fichier..." << std::endl << std::endl;<br>
><br>
> writer->Update();<br>
><br>
> std::cout << "Fichier '" << argv[nbImages+1] << "' créé" << std::endl;<br>
><br>
> return EXIT_SUCCESS;<br>
><br>
> }<br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
><br>
</div></div></blockquote></div><br>