[Insight-users] ImageRegionIterator problem
    Ali Mouizina 
    ali.mouizina at gmail.com
       
    Mon Jan 30 07:05:01 EST 2012
    
    
  
Hi,
 
I'm currently having a problem using ImageRegionIterator. I copy
successfully a region of my input image but when I want to process it
through a filter it crashes. Here's the code below :
 
// In the main program
..
squarediff->SetInput1(read);
squarediff->SetInput2(imshift(deltax,deltay,deltaz));
squarediff->Update(); // -> It crashes here
...
 
// imshift program
 
ImageType::Pointer Weights::imshift(int x, int y, int z){
       
       int x1s=max(1,x+1);
       int x2s=min(nb_col,nb_col+x); //nb_col is the number of columns of my
input image
       int y1s=max(1,y+1);
       int y2s=min(nb_ln,nb_ln+y);
       int z1s=max(1,z+1);
       int z2s=min(nb_slice,nb_slice+z);
 
       int x1=max (1,-x+1);
       int x2=min(nb_col,nb_col-x);
       int y1=max(1,-y+1);
       int y2=min(nb_ln,nb_ln-y);
       int z1=max(1,-z+1);
       int z2=min(nb_slice,nb_slice-z);
 
       ImageType::Pointer image = ImageType::New();
 
       typedef itk::ImageRegionConstIterator< ImageType > ConstIteratorType;
       typedef itk::ImageRegionIterator< ImageType> IteratorType;
 
       // Input region definition
       ImageType::RegionType inputRegion;
       ImageType::RegionType::IndexType inputStart;
       ImageType::RegionType::SizeType size;
       inputStart[0] = x1s-1;
       inputStart[1] = y1s-1;
       inputStart[1] = z1s-1;
       size[0] = x2s-x1s+1;
       size[1] = y2s-y1s+1;
       size[2] = z2s-z1s+1;
       inputRegion.SetSize( size );
       inputRegion.SetIndex( inputStart );
 
       // Output region definition
       ImageType::RegionType outputRegion;
       ImageType::RegionType::IndexType outputStart;
       outputStart[0] = x1-1;
       outputStart[1] = y1-1;
       outputStart[1] = z1-1;
       outputRegion.SetSize( size );
       outputRegion.SetIndex( outputStart );
       
       // !!!  Warning : Spacing and origin are not defined as we don't
expect to do image registration
       image->SetRegions( outputRegion );
       image->Allocate();
       image->FillBuffer(0);
 
       // Copying 
       ConstIteratorType inputIt( read, inputRegion );
       IteratorType outputIt( image, outputRegion );
 
       for ( inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd();
++inputIt, ++outputIt)
             outputIt.Set( inputIt.Get() );
 
       return image;
}
 
This function copies all the values properly as I checked it. Hence, I don't
see why can't I process it through a filter. By the way this functions aims
at copying the pixel values from an input image into an output image by
shifting their positions according to x,y and z values. 
Regards,
 
Ali
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120130/80149711/attachment.htm>
    
    
More information about the Insight-users
mailing list