<div dir="ltr"><br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Kannan U V</b> <span dir="ltr"><<a href="mailto:kannanuv@cshl.edu">kannanuv@cshl.edu</a>></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<TilePixelType, 2> TileImageType;</div><div> typedef itk::Image<AverageTilePixelType, 2> AverageTileType;</div><div>
typedef itk::Image<TilePixelType, 2> AverageImageOutputType;</div><div> typedef itk::ImageFileWriter<AverageTileType> AverageImageWriterType;</div><div> typedef itk::CastImageFilter<TileImageType, AverageTileType> CastFilterType;</div>
<div> typedef itk::CastImageFilter<AverageTileType, AverageTileType> NullFilterType;</div><div> typedef itk::CastImageFilter<AverageTileType, TileImageType> AverageImageOutputFilterType;</div><div> typedef itk::ImageFileReader<TileImageType> TileImageReaderType;</div>
<div> typedef itk::AddImageFilter<AverageTileType, AverageTileType, AverageTileType> AddImageFilterType;</div><div> typedef itk::DivideImageFilter <AverageTileType, AverageTileType, TileImageType> 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("");</div><div> string outputImageDir(tvOutputDirectory);</div><div> for (int iTile = 0; iTile < 10; iTile++) {</div><div> //for (int iTile = 0; iTile < (int) imageFileName.size(); iTile++) {</div>
<div> cout << "Processing iTile = " << iTile;</div><div> imFileName->clear();</div><div> imFileName->append(outputImageDir);</div><div> imFileName->append("/");</div><div>
imFileName->append(imageFileName.at(iTile).c_str());</div><div> cout << ", Image name : " << imFileName->c_str() << endl;</div><div> reader->SetFileName (imFileName->c_str());</div>
<div> castFilter->SetInput (reader->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> nullFilter->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();</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> 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>