I&#39;m not seeing where you set dividendImage to anything but 0. Looks like you need dividendImage = addFilter-&gt;GetOutput().<br><br>Alternatively, you could add N images together with NaryAddImageFilter (<a href="http://www.itk.org/Doxygen/html/classitk_1_1NaryAddImageFilter.html">http://www.itk.org/Doxygen/html/classitk_1_1NaryAddImageFilter.html</a>), then divide by N with ShiftScaleImageFilter (<a href="http://www.itk.org/Doxygen/html/itkShiftScaleImageFilter_8h_source.html">http://www.itk.org/Doxygen/html/itkShiftScaleImageFilter_8h_source.html</a> -- shift = 0, scale = 1/N).<br>
<br><div class="gmail_quote">On Fri, Aug 24, 2012 at 4:44 PM, Kannan U V <span dir="ltr">&lt;<a href="mailto:kannanuv@cshl.edu" target="_blank">kannanuv@cshl.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Hi David,<div>Here is  the code I wrote to average randomly generated tiles. I get a blank image (filled with zeros) as the averageImage. But the random images are different. I think I am doing something wrong in </div>

<div><br></div><div><div>    dividendImage-&gt;SetRequestedRegion (nullFilter-&gt;GetOutput());</div></div><div><br></div><div>but I not able to figure out how.</div><div><br></div><div><br></div><div><div>void createAverageImage () {</div>

<div><br></div><div>  cout &lt;&lt; &quot;In createAverageImage()&quot; &lt;&lt; endl;</div><div><br></div><div>  ImageType::SizeType outputSize;</div><div>  outputSize[0] = 10;</div><div>  outputSize[1] = 10;</div><div>
<br>
</div><div>  itk::RandomImageSource&lt;ImageType&gt;::Pointer randomImageSource =</div><div>    itk::RandomImageSource&lt;ImageType&gt;::New();</div><div>  randomImageSource-&gt;SetSize(outputSize);</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>  NullFilterType::Pointer nullFilter = NullFilterType::New();</div>

<div>  ImageReaderType::Pointer reader = ImageReaderType::New();</div><div>  CastFilterType::Pointer castFilter = CastFilterType::New();</div><div>  AddImageFilterType::Pointer addFilter = AddImageFilterType::New();</div>

<div>  AverageImageOutputFilterType::Pointer averageImageOutputFilterType = AverageImageOutputFilterType::New();</div><div>  SumImageType::Pointer divisorImage = SumImageType::New();</div><div>  SumImageType::Pointer dividendImage = SumImageType::New();</div>

<div><br></div><div>  // Set region size of dividend and divisor images</div><div>  SumImageType::SizeType sumOutputSize;</div><div>  sumOutputSize[0] = 10;</div><div>  sumOutputSize[1] = 10;</div><div>  SumImageType::IndexType start;</div>

<div>  start[0] = 0;</div><div>  start[1] = 0;</div><div><br></div><div>  SumImageType::RegionType region;</div><div>  region.SetIndex(start);</div><div>  region.SetSize(sumOutputSize);</div><div><br></div><div>  // Set divisor image to total number of images</div>

<div>  cout &lt;&lt; &quot;Allocating divisorImage&quot; &lt;&lt; endl;</div><div>  divisorImage-&gt;SetRegions(region);</div><div>  divisorImage-&gt;Allocate();</div><div>  divisorImage-&gt;FillBuffer(10.0);</div><div><br>

</div><div><div> // Set dividend image to zero</div><div>  cout &lt;&lt; &quot;Allocating dividendImage&quot; &lt;&lt; endl;</div><div>  dividendImage-&gt;SetRegions(region);</div><div>  dividendImage-&gt;Allocate();</div>

<div>  dividendImage-&gt;FillBuffer(0.0);</div><div><br></div><div>  string *imFileName = new string(&quot;&quot;);</div><div>  string outputImageDir(&quot;./imageFiles/&quot;);</div><div>  for (int iTile = 0; iTile &lt; 10; iTile++) {</div>

<div>    randomImageSource-&gt;SetNumberOfThreads(iTile); // to produce non-random results</div><div>  //for (int iTile = 0; iTile &lt; (int) imageFileName.size(); iTile++) {</div><div>    cout &lt;&lt; &quot;Processing Image = &quot; &lt;&lt; iTile;</div>

<div>    stringstream ss;</div><div>    ss &lt;&lt; iTile &lt;&lt; &quot;.tif&quot;;</div><div>    string *imFileName = new string(&quot;&quot;);</div><div>    imFileName-&gt;clear();</div><div>    imFileName-&gt;append(outputImageDir);</div>

<div>    //imFileName-&gt;append(&quot;/&quot;);</div><div>    imFileName-&gt;append(&quot;FileName&quot;);</div><div>    imFileName-&gt;append(ss.str().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 (randomImageSource-&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> }</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(dividendImage);</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>    nullFilter-&gt;Update();</div><div>}</div></div><div><br></div><br><div class="gmail_quote">On Mon, Aug 20, 2012 at 12:45 PM, David Doria <span dir="ltr">&lt;<a href="mailto:daviddoria@gmail.com" target="_blank">daviddoria@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>&gt; Hi,<br>
&gt; I want to create an average image of multiple files. I am reading all files<br>
&gt; and create a dividend image that is a sum of all images and then use the<br>
&gt; divide image filter and divide the dividend float image with a constant<br>
&gt; image having pixel values equal to the number of images summed up. I am<br>
&gt; having issues adding multiple images to the dividend image. Below is the<br>
&gt; function I have written. I see that SetRequestedRegion is a virtual<br>
&gt; function.<br>
<br>
</div>Most functions in ITK are virtual functions :) Can you explain the<br>
problem you having? Or better, provide the smallest compilable,<br>
self-contained example of the problem. That is, rather than reading<br>
images from files, generate some random images programmatically and<br>
then call your function with them.<br>
<span><font color="#888888"><br>
David<span class="HOEnZb"><font color="#888888"><br>
</font></span></font></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br>Thanks,<br>Kannan<br>
</font></span></div></div>
<br>_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" target="_blank">http://www.kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>robert<br><br>