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

Matt McCormick matt.mccormick at kitware.com
Sun Feb 2 13:56:28 EST 2014


Hi Alessio,

Another option is to create the iterator with the desired region on
demand.  For instance:

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

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

  MaskIterator maskIt = MaskIterator (maskPtr, maskPtr->GetRequestedRegion() );
  TImage::RegionType inputRegion = inputPtr->GetRequestedRegion();
  TImage::IndexType inputIndex = inputRegion.GetIndex();
  TImage::SizeType inputSize = inputRegion.GetSize();
  inputSize[0] = 1;
  inputSize[1] = 1;
  inputRegion.SetSize( inputSize );

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

   if(maskIt.Get()== 100)
       {
       TMask::IndexType maskIndex = maskIt.GetIndex();
       inputIndex[0] = maskIndex[0];
       inputIndex[1] = maskIndex[1];
       inputRegion.SetIndex( inputIndex );
       IteratorType inputIt = IteratorType(inputPtr, inputRegion );
       inputIt.GoToBegin();
         while( !inputIt.IsAtEnd() )
         {
         tmpValue.push_back( inputIt.Get()) ; //Store and do something
with pixels
          ++inputIt;
         }
       }
}

Hope this helps,
Matt

On Sat, Feb 1, 2014 at 2:16 PM, Alessio Mazzarini
<alessiomazzarini89 at gmail.com> wrote:
> 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
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/cgi-bin/mailman/listinfo/community


More information about the Insight-developers mailing list