I'm not seeing where you set dividendImage to anything but 0. Looks like you need dividendImage = addFilter->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"><<a href="mailto:kannanuv@cshl.edu" target="_blank">kannanuv@cshl.edu</a>></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->SetRequestedRegion (nullFilter->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 << "In createAverageImage()" << 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<ImageType>::Pointer randomImageSource =</div><div> itk::RandomImageSource<ImageType>::New();</div><div> randomImageSource->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 << "Allocating divisorImage" << endl;</div><div> divisorImage->SetRegions(region);</div><div> divisorImage->Allocate();</div><div> divisorImage->FillBuffer(10.0);</div><div><br>
</div><div><div> // Set dividend image to zero</div><div> cout << "Allocating dividendImage" << endl;</div><div> dividendImage->SetRegions(region);</div><div> dividendImage->Allocate();</div>
<div> dividendImage->FillBuffer(0.0);</div><div><br></div><div> string *imFileName = new string("");</div><div> string outputImageDir("./imageFiles/");</div><div> for (int iTile = 0; iTile < 10; iTile++) {</div>
<div> randomImageSource->SetNumberOfThreads(iTile); // to produce non-random results</div><div> //for (int iTile = 0; iTile < (int) imageFileName.size(); iTile++) {</div><div> cout << "Processing Image = " << iTile;</div>
<div> stringstream ss;</div><div> ss << iTile << ".tif";</div><div> string *imFileName = new string("");</div><div> imFileName->clear();</div><div> imFileName->append(outputImageDir);</div>
<div> //imFileName->append("/");</div><div> imFileName->append("FileName");</div><div> imFileName->append(ss.str().c_str());</div><div> cout << ", Image name : " << imFileName->c_str() << endl;</div>
<div> reader->SetFileName (imFileName->c_str());</div><div> castFilter->SetInput (randomImageSource->GetOutput());</div><div> addFilter->SetInput1 (castFilter->GetOutput());</div><div> addFilter->SetInput2 (dividendImage);</div>
<div> nullFilter->SetInput (addFilter->GetOutput());</div><div> dividendImage->SetRequestedRegion (nullFilter->GetOutput());</div><div> reader->Update();</div><div> addFilter->Update();</div>
<div> }</div><div><br></div><div> divideImageFilter->SetInput1(dividendImage);</div><div> divideImageFilter->SetInput2(divisorImage);</div><div><br></div><div> //averageImageWriter->SetInput(divideImageFilter->GetOutput());</div>
<div> averageImageOutputFilterType->SetInput (dividendImage);</div><div> //averageImageWriter->SetInput(averageImageOutputFilterType->GetOutput());</div><div> averageImageWriter->SetInput(dividendImage);</div>
<div> string *averageImageFileName = new string("");</div><div> averageImageFileName->clear();</div><div> //averageImageFileName->append(outputImageDir);</div><div> averageImageFileName->append("./");</div>
<div> averageImageFileName->append("AverageImage.img");</div><div> averageImageWriter->SetFileName (averageImageFileName->c_str());</div><div> cout << "Average Image name : " << averageImageFileName->c_str() << endl;</div>
<div> averageImageWriter->Update();</div><div><br></div><div> nullFilter->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"><<a href="mailto:daviddoria@gmail.com" target="_blank">daviddoria@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>> Hi,<br>
> I want to create an average image of multiple files. I am reading all files<br>
> and create a dividend image that is a sum of all images and then use the<br>
> divide image filter and divide the dividend float image with a constant<br>
> image having pixel values equal to the number of images summed up. I am<br>
> having issues adding multiple images to the dividend image. Below is the<br>
> function I have written. I see that SetRequestedRegion is a virtual<br>
> 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>