[Insight-users] indices and iterators

David Fuentes fuentesdt at gmail.com
Wed Feb 4 10:21:36 EST 2009


Thank you very much for the reply Luis,

I am attempting to use the Petsc structured grid infrastructure to
parallelize the image processing, handle all mpi communication, etc... 
After a few iterations of trial and error, 
the ImageSliceIteratorWithIndex seems to
interface quite naturally w/ the Petsc 3D (i,j,k) indices


   // initialize ITK iterators
   typedef itk::ImageSliceIteratorWithIndex< VecOutputImageType > VecOutIterType;
   VecOutIterType    outputIt( outputImage,  outputImage->GetRequestedRegion() );
   outputIt.SetFirstDirection(  0 ); outputIt.SetSecondDirection( 1 );

   PetscScalar   ****MapPixel;
   VecOutputImageType::PixelType   pixelValue;
   DAVecGetArray(dac,localVec,&MapPixel);

   /*
      loop through parallel data structures
   */
   outputIt.GoToBegin();
   for (PetscInt k=0; k<size[2]; k++)
   {
     for (PetscInt j=0; j<size[1]; j++)
     {
       for (PetscInt i=0; i<size[0]; i++)
       {
         for(PetscInt ivar = 0; ivar < nvarplot ; ivar++)
                     pixelValue[ivar] = MapPixel[k][j][i][ivar];
         outputIt.Set( pixelValue ) ;
         ++outputIt; // update iterators
       }
       outputIt.NextLine(); // get next line
     }
     outputIt.NextSlice(); // get next slice
   }
   DAVecRestoreArray(dac,localVec,&MapPixel);







df




On Wed, 4 Feb 2009, Luis Ibanez wrote:

>
> Hi David,
>
>
>  A) There are no ITK iterators that provide I,J,K access to pixel data.
>     You could use the GetPixel( index ) method, which internally
>     performs a computation very similar to what you are showing below
>     in your code example. It is inefficient.. but it should work.
>
>  B) You could certainly use the code in your example below, that should
>     work fine. Note however, that if you are planning to visit all the
>     pixels sequentially, then you can as well use the ImageRegion
>     iterator.
>
>  C) It may not be a bad idea to create an IJK iterator class for ITK,
>     it will simply become one iterator more, and you can find tune it
>     for 3D images. It will be very useful for other ITK users who
>     integrate ITK with other libraries. We will be happy to advice
>     you on how to write such class, and of course we will strongly
>     encourage you to contribute it to the Insight Journal   :-)
>
>  D) Could you describe the type of walk that you are planning to make
>     through the image pixels ?  It may be that there are existing
>     ITK iterators that provide that kind of sequence.
>
>
>
>  Regards,
>
>
>     Luis
>
>
>
> ---------------------
> David Fuentes wrote:
>> 
>> I know this goes against the ITK philosophy, but I am interfacing
>> ITK w/ Petsc's Structured grid solvers. Are there any iterator classes
>> that provide i,j,k access to an ITK pixel buffer?
>> 
>> if not,
>> 
>> would I be able to use something like
>> 
>> data = Image->GetBufferPointer();
>> 
>> data[i+nwidth*j+(nwidth*nheight)*k] = ...
>> 
>> 
>> ?
>> 
>> 
>> thanks,
>> df
>> _______________________________________________
>> 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