<div dir="ltr"><br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Kannan U V</b> <span dir="ltr">&lt;<a href="mailto:kannanuv@cshl.edu">kannanuv@cshl.edu</a>&gt;</span><br>
Date: Mon, Aug 20, 2012 at 12:20 PM<br>Subject: Average of multiple image files<br>To: <a href="mailto:insight-users@itk.org">insight-users@itk.org</a><br><br><br><div dir="ltr">Hi,<div>I want to create an average image of multiple files. I am reading all files and create a dividend image that is a sum of all images and then use the divide image filter and divide the dividend float image with a constant image having pixel values equal to the number of images summed up. I am having issues adding multiple images to the dividend image. Below is the function I have written. I see that SetRequestedRegion is a virtual function.</div>

<div><br></div><div><div>nt tvMosaicParam::createAverageTile() {</div><div>  typedef itk::Image&lt;TilePixelType, 2&gt; TileImageType;</div><div>  typedef itk::Image&lt;AverageTilePixelType, 2&gt; AverageTileType;</div><div>

  typedef itk::Image&lt;TilePixelType, 2&gt; AverageImageOutputType;</div><div>  typedef itk::ImageFileWriter&lt;AverageTileType&gt; AverageImageWriterType;</div><div>  typedef itk::CastImageFilter&lt;TileImageType, AverageTileType&gt; CastFilterType;</div>

<div>  typedef itk::CastImageFilter&lt;AverageTileType, AverageTileType&gt; NullFilterType;</div><div>  typedef itk::CastImageFilter&lt;AverageTileType, TileImageType&gt; AverageImageOutputFilterType;</div><div>  typedef itk::ImageFileReader&lt;TileImageType&gt; TileImageReaderType;</div>

<div>  typedef itk::AddImageFilter&lt;AverageTileType, AverageTileType, AverageTileType&gt; AddImageFilterType;</div><div>  typedef itk::DivideImageFilter &lt;AverageTileType, AverageTileType, TileImageType&gt; DivideImageFilterType;</div>

<div><br></div><div>  TileImageType::SizeType outputSize;</div><div>  outputSize[0] = croppedTileSizeX;</div><div>  outputSize[1] = croppedTileSizeY;</div><div><br></div><div>  AddImageFilterType::Pointer addImageFilter = AddImageFilterType::New();</div>

<div>  DivideImageFilterType::Pointer divideImageFilter = DivideImageFilterType::New();</div><div>  AverageImageWriterType::Pointer averageImageWriter = AverageImageWriterType::New();</div><div><br></div><div>  // Setting up blank image as average</div>

<div>  NullFilterType::Pointer nullFilter = NullFilterType::New();</div><div>  TileImageReaderType::Pointer reader = TileImageReaderType::New();</div><div>  CastFilterType::Pointer castFilter = CastFilterType::New();</div>

<div>  AddImageFilterType::Pointer addFilter = AddImageFilterType::New();</div><div>  AverageImageOutputFilterType::Pointer averageImageOutputFilterType = AverageImageOutputFilterType::New();</div><div>  AverageTileType::Pointer divisorImage = AverageTileType::New();</div>

<div>  AverageTileType::Pointer dividendImage = AverageTileType::New();</div><div><br></div><div>  CreateConstantImage (divisorImage, (double)imageFileName.size());</div><div>  CreateConstantImage (dividendImage, 0.0);</div>

<div><div>  string *imFileName = new string(&quot;&quot;);</div><div>  string outputImageDir(tvOutputDirectory);</div><div>  for (int iTile = 0; iTile &lt; 10; iTile++) {</div><div>  //for (int iTile = 0; iTile &lt; (int) imageFileName.size(); iTile++) {</div>

<div>    cout &lt;&lt; &quot;Processing iTile = &quot; &lt;&lt; iTile;</div><div>    imFileName-&gt;clear();</div><div>    imFileName-&gt;append(outputImageDir);</div><div>    imFileName-&gt;append(&quot;/&quot;);</div><div>

    imFileName-&gt;append(imageFileName.at(iTile).c_str());</div><div>    cout &lt;&lt; &quot;, Image name : &quot; &lt;&lt;  imFileName-&gt;c_str() &lt;&lt; endl;</div><div>    reader-&gt;SetFileName (imFileName-&gt;c_str());</div>

<div>    castFilter-&gt;SetInput (reader-&gt;GetOutput());</div><div>    addFilter-&gt;SetInput1 (castFilter-&gt;GetOutput());</div><div>    addFilter-&gt;SetInput2 (dividendImage);</div><div>    nullFilter-&gt;SetInput (addFilter-&gt;GetOutput());</div>

<div>    dividendImage-&gt;SetRequestedRegion (nullFilter-&gt;GetOutput());</div><div>    reader-&gt;Update();</div><div>    addFilter-&gt;Update();</div><div>    nullFilter-&gt;Update();</div><div>  }</div><div><br></div>

<div>  //divideImageFilter-&gt;SetInput1(dividendImage);</div><div>  //divideImageFilter-&gt;SetInput2(divisorImage);</div><div><br></div><div>  //averageImageWriter-&gt;SetInput(divideImageFilter-&gt;GetOutput());</div>
<div>
  averageImageOutputFilterType-&gt;SetInput (dividendImage);</div><div>  averageImageWriter-&gt;SetInput(averageImageOutputFilterType-&gt;GetOutput());</div><div>  //averageImageWriter-&gt;SetInput();</div><div>  string *averageImageFileName = new string(&quot;&quot;);</div>

<div>  averageImageFileName-&gt;clear();</div><div>  averageImageFileName-&gt;append(outputImageDir);</div><div>  averageImageFileName-&gt;append(&quot;/&quot;);</div><div>  averageImageFileName-&gt;append(&quot;AverageImage.img&quot;);</div>

<div>  averageImageWriter-&gt;SetFileName (averageImageFileName-&gt;c_str());</div><div>  cout &lt;&lt; &quot;Average Image name : &quot; &lt;&lt;  averageImageFileName-&gt;c_str() &lt;&lt; endl;</div><div>  averageImageWriter-&gt;Update();</div>

<div><br></div><div>  return 0;</div></div><div>}</div><div><br></div><div>How do I proceed? Thanks in advance for your help.</div><span class="HOEnZb"><font color="#888888"><div><br></div>-- <br>Thanks,<br>Kannan<br>
</font></span></div></div>
</div><br><br clear="all"><div><br></div>-- <br>Thanks,<br>Kannan<br>
</div>