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

Miller, James V (GE, Research) millerjv at crd.ge.com
Fri May 12 09:36:51 EDT 2006


At first glance, the only issue I see is your calculation of the origin.  In ITK, the origin corresponds to the physical coordinate (mm or ft, etc.) of the pixel at index [0, 0, ...].  Since your output region starts at a non-zero index, you should not need to move the origin.  So just copy the origin and spacing from the input image to the output image.
 
Can you describe the "problem" in more detail?  How does the output image look?
 
There could be a problem with the ImageFileWriter when the BufferedRegion does not start at index [0,0,...].  You could place a RegionOfInterestImageFilter before the ImageFileWriter (or an ChangeInformationImageFilter) to adjust the image so that the BufferedRegion starts at [0,0,...]
 
Here are the definitions of regions:
 
RequestedRegion: How much of the image to process.
BufferedRegion: How much of the image is in memory.
LargestPossibleRegion: How big could the image be.  
 
Filters are told to process a RequestedRegion.  When a filter runs, the RequestedRegion must be a subset of the BufferedRegion. The LargestPossibleRegion is typically used to tell whether a pixel is a true boundary condition or just a voxel at the edge of BufferedRegion.
 
Jim
 
 
 

-----Original Message-----
From: insight-users-bounces+millerjv=crd.ge.com at itk.org [mailto:insight-users-bounces+millerjv=crd.ge.com at itk.org]On Behalf Of Jared Hoover
Sent: Thursday, May 11, 2006 8:33 PM
To: insight-users at itk.org
Subject: [Insight-users] Using regions to control iterators...


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/20060512/cbd12b22/attachment.htm


More information about the Insight-users mailing list