[Insight-users] Random acess pixels using iterators

Luis Ibanez luis.ibanez@kitware.com
Sun, 20 Apr 2003 11:58:33 -0400


Hi Fucang,

For this purpose you just need to set the region
of the iterator to a particular size and start.

It is usual to set the region to iterate as the
BufferedRegion, but this doesn't have to be the case.
You can set the region to iterate to any other region
as long as it is fully contained in the BufferedRegion.


For example, in order to iterate over the fourth
slice you define the region as:


SizeType   size;
IndexType  start;

start[0] = 0;
start[1] = 0;
start[2] = 3;  // fourth slice

size[0] = sliceWidth;
size[1] = sliceHeight;
size[2] = 1;  // just one slice thick

RegionType region;

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

itk::ImageRegionItertor< ImageType >  it( image, region );

it.GoToBegin();

while( !it.IsAtEnd() )
  {
  // do your processing here...
  ++it;
  }



You may want to give a second reading to the
Chapter on Iterators that Josh Cates added recently
to the SoftwareGuide.



Regards,



   Luis


----------------------------------------
Fucang Jia wrote:
> Hi Luis,
> 
> I am working on 3D medical image, and want to process a port of image 
> region, not a pixel data. For example I want to process the fourth slice 
> image, I want to setup image iterator to begin with { size[0],size[1],3 
> }. So I want to use
> 
> unsigned long offset=size[0]*size[1]*3;
> ImageIteratorType it(image,image->GetRequestedRegion());
> it+=offset;
> or
> it.SetPosition(offset);
> 
> I can use
> it.GoToBegin();
> for(unsigned long i=0;i<offset;i++)++it;
> 
> But I think this is not very effective.
> 
> I can use itkExtractImage, but it need more memory.
> So I think there need a member function to implement
> SetPosition(offset). Is that right?
> 
> Thanks!
> 
> Fucang
> 
>> From: Luis Ibanez <luis.ibanez@kitware.com>
>> To: Fucang Jia <jiafucang@hotmail.com>
>> CC: insight-users@public.kitware.com
>> Subject: Re: [Insight-users] Random acess pixels using iterators
>> Date: Sun, 20 Apr 2003 10:28:35 -0400
>>
>>
>> Hi Fucang,
>>
>> ImageIterators are designed as a fast way of
>> getting access to image data. Their speed derives
>> from the knowledge of a particular strategy for
>> visiting all the pixels.
>>
>> If you need to access isolated pixels in the
>> image, all the advantages of iterators are lost.
>> In that case you can simply use the itk::Image
>> methods
>>
>>       -  SetPixel()
>>       -  GetPixel()
>>
>> Note however that this two methods are *very*
>> slow. So you may not want to use them for a
>> massive access to pixel data.
>>
>> Could you give us more details on the type of
>> access you need to perform ?
>>
>> There may be already an ITK iterator for the
>> process you want to perform...
>>
>>
>> Thanks
>>
>>
>>   Luis
>>
>>
>> --------------
>>
>> Fucang Jia wrote:
>>
>>> Hi Luis, hi everyone,
>>>
>>> I want to access pixel data from an offset with 
>>> itkImageRegionIterator iterator, not from begin. But I have not find 
>>> the member function implement operator+=Offset, operator-=Offset, or 
>>> operator.SetPosition(OffsetIndex). The software guide does describe 
>>> the function. Are these function purposely not implemented, or I am 
>>> wrong at the point?
>>>
>>> Thank you!
>>>
>>> Fucang
>>>
>>>
>>>
>>
> 
> 
> _________________________________________________________________
> The new MSN 8: smart spam protection and 2 months FREE*  
> http://join.msn.com/?page=features/junkmail
> 
>