[Insight-users] Using regions to control iterators...

Jared Hoover jsh238 at gmail.com
Thu May 11 20:32:35 EDT 2006


ITK users,

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.

So far I've only processed a region of the input image and can only get two
outcomes to work.
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.
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.

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.

    ImageType::ConstPointer sourceImage = reader->GetOutput();
    ImageType::RegionType maxSourceRegion =
sourceImage->GetLargestPossibleRegion();
    ImageType::SizeType maxSourceRegionSize = maxSourceRegion.GetSize();
    ImageType::IndexType maxSourceRegionIndex = maxSourceRegion.GetIndex();

    WriterType::Pointer writer = WriterType::New();
    writer->SetFileName(argv[2]);

    ImageType::RegionType sourceInputRegion;
    ImageType::RegionType::IndexType sourceRegionStartIndex;
    ImageType::RegionType::SizeType sourceRegionStartSize;

    sourceRegionStartIndex[0] = ::atoi(argv[3]);
    sourceRegionStartIndex[1] = ::atoi(argv[4]);

    sourceRegionStartSize[0] = ::atoi(argv[5]);
    sourceRegionStartSize[1] = ::atoi(argv[6]);

    sourceInputRegion.SetSize(sourceRegionStartSize);
    sourceInputRegion.SetIndex(sourceRegionStartIndex);

    ImageType::RegionType outputRegion;
    ImageType::RegionType::IndexType outputRegionStartIndex;
    ImageType::RegionType::SizeType outputRegionStartSize;

    outputRegionStartIndex[0] = ::atoi(argv[3]);
    outputRegionStartIndex[1] = ::atoi(argv[4]);

    outputRegionStartSize[0] = ::atoi(argv[5]);
    outputRegionStartSize[1] = ::atoi(argv[6]);

    outputRegion.SetSize(outputRegionStartSize);
    outputRegion.SetIndex(outputRegionStartIndex);

    ImageType::Pointer outputImage = ImageType::New();
    outputImage->SetRegions(outputRegion);
    const ImageType::SpacingType & spacing =
                            reader->GetOutput()->GetSpacing();
    const ImageType::PointType & inputOrigin =
                            reader->GetOutput()->GetOrigin();
    double outputOrigin[Dimension];

    for(unsigned int i=0; i<Dimension; i++) {
        outputOrigin[i] =
inputOrigin[i]+spacing[i]*sourceRegionStartIndex[i];
    }

    outputImage->SetSpacing(spacing);
    outputImage->SetOrigin(outputOrigin);

//outputImage->SetLargestPossibleRegion(sourceImage->GetLargestPossibleRegion());
    outputImage->Allocate();

    ConstIteratorType inputIt(reader->GetOutput(),sourceInputRegion);
    IteratorType outputIt(outputImage,outputRegion);


(process pixel values in regions and send to same index in output image)
(update writer)


Many thanks in advance ~

Jared
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20060511/253b593a/attachment.htm


More information about the Insight-users mailing list