[ITK Community] [Insight-developers] Different iterators that works togheter

Alessio Mazzarini alessiomazzarini89 at gmail.com
Sat Feb 1 14:16:21 EST 2014


Hi all!
I'm trying to realize a filter which takes in input two different images 
(Mask 2D and Image 3D); i need to read with an iterator the Mask,until 
it finds a pixel value of XX (for example). After that, when it has been 
found i need to go in the second image (the 3D one) at the same 
coordinate X-Y to save the value of all pixels in the third dimension 
with the ImageLinearConstIteratorWithIndex.
I have the doubt that the second iterator, which should read the third 
dimension of the Image3D, doesn't start at the same coordinate X-Y of 
the Mask.
This is a simple example of my code:
I used ImageRegionConstIterator to read the 2D image and get the X-Y 
coordinate of interest.


   typename TImage::ConstPointer inputPtr = this->GetInputImage();
   typename TMask::ConstPointer maskPtr = this->GetInputMask();

   typedef ImageRegionConstIterator <TMask> MaskIterator;    //Mask 2D
   typedef ImageLinearConstIteratorWithIndex <TImage> IteratorType;     
//Iterator of the 3th Dimension

   MaskIterator maskIt = MaskIterator (maskPtr, 
maskPtr->GetRequestedRegion() );
   IteratorType IteratorLine = IteratorType(inputPtr, 
inputPtr->GetRequestedRegion() );

   IteratorLine.SetDirection ( 2 ); //Walk along 3Dimension

   IteratorLine.GoToBegin();
   for ( maskIt.GoToBegin(); !maskIt.IsAtEnd(); ++maskIt)
   {

    if(maskIt.Get()== 100)
        {
          while( !IteratorLine.IsAtEndOfLine() )
          {
               tmpValue.push_back( IteratorLine.Get()) ; //Store and do 
something with pixels
           ++IteratorLine;
          }
        }
IteratorLine.NextLine();
}


I'm not sure that in this way these two iterators move toghether from 
the beginning to the end. Is there a better way to implement it?

P.S: I will work always with images of the same dimension: 512x512 (Mask 
2D)  and 512x512x24 (Image 3D)
Thanks for your help

Regards,
Alessio


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-developers



More information about the Community mailing list