[Insight-users] itk image iterator question??

Luis Ibanez luis.ibanez at kitware.com
Tue Jun 8 17:43:20 EDT 2004


Hi Sachin,

Do you want to do this for *ONE AND ONLY ONE* slice ?

If so,
then the simple way to do it is to define the region
as the one containing that single slice. In that case
you can use the generic ImageRegionIterator<> class


The code will look something like:


ImageType::RegionType region;
ImageType::SizeType   size;
ImageType::IndexType  start;

size[0] = NumberOfPixelsAlongX;
size[1] = NumberOfPixelsAlongY;
size[2] = 1;  // to process a single slice

start[0] = 0;
start[1] = 0;
start[2] = TheSliceNumberIwantToProcess;

region.SetSize( size );
region.SetIndex( start );

typedef itk::ImageRegionConstIterator<
                  ImageType > InputIteratorType;

typedef itk::ImageRegionIterator<
                  ImageType > OutputIteratorType;



InputIteratorType it1( inputImage1, region );
InputIteratorType it2( inputImage2, region );

OutputIteratorType ot( outputImage, region );

it1.GoToBegin();
it1.GoToBegin();
ot.GoToBeging();

while( !it1.IsAtEnd() )
   {
   if( it1.Get() == it2.Get() )
     {
     ot.Set( 255 );
     }
   else
     {
     ot.Set( 0 );
     }
   ++it1;
   ++it2;
   ++ot;
   }





Regards,



    Luis



-----------------------------
Sachin Jambawalikar wrote:

> Hi Luis,
> 
> I'm a bit confused  with the slice iterator documentation.
> 
> I 've  two input 3D image and one output  3D image.
> 
> What I need to be able to do is given a slice number  I want to
> iterate only through pixels of the  corresponding slice  in  the input
> and output images and set the output image  value
> of the iterated pixels accordingly
> 
> for example  // pseudo code
> it1.beginofSlice  //it1 pointing to begining of slice number 7 in input 1 say...
> it2.beginofSlice  //it2 pointing to begining  of slice number 7 in
> input 2 say...
>  it3.beginofSlice  //it3 pointing to begining  of slice number 7 in
> output 1 say...
> 
> /*******************************************************************************
> How to initialize it1,it2,it3 to point to the beigning of an arbitrary
> slice ???
> /**********************************************************************************
> while( !it1.EndofSlice)
> {
> if(it1.Get()==it2.Get()
> it3.Set(1);
> else 
> it3.Set(0);
> }
> 
> 
> Regards
> --Sachin
> 
> 
> On Mon, 07 Jun 2004 17:53:52 -0400, Luis Ibanez <luis.ibanez at kitware.com> wrote:
> 
>>
>>Hi Sachin,
>>
>>The use of image iterators is explained
>>in detail in the SoftwareGuide.
>>
>>  http://www.itk.org/ItkSoftwareGuide.pdf
>>
>>Chapter 11, pdf-page 481.
>>
>>Examples are available in
>>
>>    Insight/Examples/Iterators
>>
>>You probably want to use the ImageSliceIterator:
>>http://www.itk.org/Insight/Doxygen/html/classitk_1_1ImageSliceIteratorWithIndex.html
>>
>>  Regards,
>>
>>    Luis
>>
>>-------------------------------
>>
>>
>>Sachin Jambawalikar wrote:
>>
>>
>>>Hi  ,
>>>
>>>I have a 3D itk image.
>>>I want to be able to iterate through all pixels  from begining of a
>>>selected 2D slice to the end of the slice in the image.
>>>
>>>Can anybody tell me how that can  be achieved .
>>>
>>>Regards
>>>--Sachin
>>>_______________________________________________
>>>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