ITK users,<br><br>I'm still somewhat new to ITK. I'm trying to figure out how Image regions control where iterators may 'roam'. My problem may lie in that I don't fully understand how the BufferedRegion, LargestPossibleRegion, and regular Region differ. An example that I am trying to extend is Example/Iterators/ImageRegionIterator.cxx. I want to output an image that is the same overall size/spacing as the input image. I am trying to process a region in the input image (say squaring the pixel values) and output the pixel values in the output image in the same pixel index.
<br><br>So far I've only processed a region of the input image and can only get two outcomes to work.<br>1.) The output image is the same LargestPossibleRegion but the copied pixel values lie outside of the region that was processed in the input image.
<br>2.) Essentially the output of what /Examples/Iterators/ImageRegionIterator.cxx would give... an output image with LargestPossibleRegion = Input image processsed region with accuratly placed pixel values.<br><br>Is there something that I am overlooking to force the output Iterator to only operate on the corresponding processed subregion within the output image? I tried setting the output image SetBufferedRegion(input process image region size) and SetLargestPossibleRegion(sourceImage->GetLargestPossibleRegion()) but it didn't work. I will include the portion of code that I am trying to describe in case anything is unclear above.
<br><br> ImageType::ConstPointer sourceImage = reader->GetOutput();<br> ImageType::RegionType maxSourceRegion = sourceImage->GetLargestPossibleRegion();<br> ImageType::SizeType maxSourceRegionSize = maxSourceRegion.GetSize
();<br> ImageType::IndexType maxSourceRegionIndex = maxSourceRegion.GetIndex();<br><br> WriterType::Pointer writer = WriterType::New();<br> writer->SetFileName(argv[2]);<br><br> ImageType::RegionType sourceInputRegion;
<br> ImageType::RegionType::IndexType sourceRegionStartIndex;<br> ImageType::RegionType::SizeType sourceRegionStartSize;<br><br> sourceRegionStartIndex[0] = ::atoi(argv[3]);<br> sourceRegionStartIndex[1] = ::atoi(argv[4]);
<br><br> sourceRegionStartSize[0] = ::atoi(argv[5]);<br> sourceRegionStartSize[1] = ::atoi(argv[6]);<br><br> sourceInputRegion.SetSize(sourceRegionStartSize);<br> sourceInputRegion.SetIndex(sourceRegionStartIndex);
<br><br> ImageType::RegionType outputRegion;<br> ImageType::RegionType::IndexType outputRegionStartIndex;<br> ImageType::RegionType::SizeType outputRegionStartSize;<br><br> outputRegionStartIndex[0] = ::atoi(argv[3]);
<br> outputRegionStartIndex[1] = ::atoi(argv[4]);<br><br> outputRegionStartSize[0] = ::atoi(argv[5]);<br> outputRegionStartSize[1] = ::atoi(argv[6]);<br><br> outputRegion.SetSize(outputRegionStartSize);<br>
outputRegion.SetIndex(outputRegionStartIndex);<br> <br> ImageType::Pointer outputImage = ImageType::New();<br> outputImage->SetRegions(outputRegion);<br> const ImageType::SpacingType & spacing =<br> reader->GetOutput()->GetSpacing();
<br> const ImageType::PointType & inputOrigin =<br> reader->GetOutput()->GetOrigin();<br> double outputOrigin[Dimension];<br><br> for(unsigned int i=0; i<Dimension; i++) {<br>
outputOrigin[i] = inputOrigin[i]+spacing[i]*sourceRegionStartIndex[i];<br> }<br><br> outputImage->SetSpacing(spacing);<br> outputImage->SetOrigin(outputOrigin);<br> //outputImage->SetLargestPossibleRegion(sourceImage->GetLargestPossibleRegion());
<br> outputImage->Allocate();<br><br> ConstIteratorType inputIt(reader->GetOutput(),sourceInputRegion);<br> IteratorType outputIt(outputImage,outputRegion);<br><br><br>(process pixel values in regions and send to same index in output image)
<br>(update writer)<br><br><br>Many thanks in advance ~<br><br>Jared<br>