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

Luis Ibanez luis.ibanez at kitware.com
Fri May 12 09:40:19 EDT 2006


Hi Jared,


Please read the ITK Software Guide:


    http://www.itk.org/ItkSoftwareGuide.pdf


In particular the chapter on "DataRepresentation",
and the chapter on "Image Iterators".

Image iterators are constrained to walk along the BufferedRegion
of the image, not because ITK check for them, but because if you
attempt to make them walk outside of that region your program will
crash  :-/


It seems that you didn't posted the entire source code of your
program. in your email we can only see the initialization of the
iterators.

Could you please also post the while loop of the iterators,
including the Set/Get methods, and the section where you write
your image out ?

actually, just send to the list the full .cxx file that you
are using. In this way we can attempt to reproduce the problem
that you are reporting.


    Thanks


      Luis



====================
Jared Hoover wrote:
> 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
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users




More information about the Insight-users mailing list