[Insight-users] ImageRegionIterator problem
Ali Mouizina
ali.mouizina at gmail.com
Mon Jan 30 07:22:37 EST 2012
I think, I figured it out why I have this problem. In the png attached to
this mail you can have a precise idea of what this function is supposed to
do. I think that the output image yield by this function has the same size
as the input region and this is not what I want. How can I fix this problem
?
Regards,
Ali
De : Ali Mouizina [mailto:ali.mouizina at gmail.com]
Envoyé : lundi 30 janvier 2012 13:05
À : insight-users at itk.org
Objet : ImageRegionIterator problem
Hi,
Im 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. Heres 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 dont
see why cant 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/facb7e6a/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example.png
Type: image/png
Size: 15063 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20120130/facb7e6a/attachment.png>
More information about the Insight-users
mailing list