[Insight-users] Iterators problem

Jeremy Lecoeur jeremy.j.lecoeur at vanderbilt.edu
Wed Oct 20 18:39:13 EDT 2010


  In the project I'm working on, I need to take value from an image 
(named imagex) which data type is short and apply some complicated 
mathematical function. The results of this function is a double and is 
store in an image (named imagelambda1) which data type is double.
When I'm using iterator to traverse the first image (imagex) and want to 
write the result in imagelambda1, it seems that the resulting image is 
scrambled.

Here is the portion of the code I use :

typedef short PixelType;
typedef double  RealPixelType;
const unsigned int Dimension = 3;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::Image< RealPixelType, Dimension>    RealImageType;
typedef itk::ImageRegionIterator< ImageType > IteratorType;
typedef itk::ImageRegionIterator< RealImageType > RealIteratorType;


IteratorType iteratorx( imagex, imagex->GetRequestedRegion() );
RealIteratorType iteratorlambda1( imagelambda1, 
imagex->GetRequestedRegion() );

for (iteratorx.GoToBegin(), iteratorlambda1.GoToBegin(); 
!iteratorx.IsAtEnd(); ++iteratorx, ++iteratorlambda1){
                 iteratorlambda1.Set( some_function(iteratorx.Get()));
}

The following link to an image show the input image (bottom) and result 
(top)when I'm just copying the input (i.e. 
iteratorlambda1.Set(iteratorx.Get()); ). I'm using the copy so it's 
easier to see that everything is scrambled.

http://img28.imageshack.us/img28/3628/55031279.png

I don't really understand what's happening.

Jeremy


More information about the Insight-users mailing list