[Insight-users] A bug (?) in ImageSliceConstIteratorWithIndex class
Luis Ibanez
luis.ibanez@kitware.com
Mon, 11 Nov 2002 11:23:00 -0500
Hi Paul,
Thanks for pointing this out.
There seems to be a problem with the SliceIterator when
used in this way. The "m_Position" internal member is
not being updated correctly.
The historical reason is that "NextSlice() was expected
to be called when the iterator was at the end of the
previous slice...
I'm looking for a fix in this class.
---
In any case,
If your objective is to extract a slice from an image,
it is far more natural to define the Region for the iterator
as being of size=1 in Z and starting at the corresponnding
slice. In this way the Region will naturaly control the
iterator for walking along the corresponding slice.
For example,
In an image of size (100x200x300) if you want to extract
slice z = 139
you could rather do:
ImageType::IndexType start;
start[0] = 0;
start[1] = 0;
start[2] = 139;
ImageType::SizeType size;
size[0] = 100;
size[1] = 200;
size[2] = 1; // <<---- Only one slice
ImageType::RegionType region
region.SetSize( size );
region.SetIndex( start );
ImageIteratorType it( image, region );
it.GoToBegin();
it.SetFirstDirection(0);
it.SetSecondDirection(1);
while( !it.IsAtEndOfSlice() )
{
while( !it.IsAtEndOfLine() )
{
// access the pixels here with it.Get();
++it;
}
it.NextLine();
}
// slice done !
-----
I'll let you know as soon as the SliceIterator
NextSlice method is fixed.
Thanks
Luis
========================================
Paul Yushkevich wrote:
> Hi everyone,
>
> I found what I think may be a bug in ImageSliceConstIteratorWithIndex
> class.
> The following code is intended to copy the contents of a slice 'slice'
> to the 2D array 'sliceArray'.
>
> SomeClass::SomeClass(...) {
> // Create a slice iterator and choose a slice
> slicer =
> ImageSliceConstIteratorWithIndex<ImageType>(imagePtr,imagePtr->getLargestPossibleRegion());
>
> slicer.setFirstDimension(0);
> slicer.setFirstDimension(1);
> }
>
> void SomeClass::setSlice(int slice) {
>
> // Skip to the right slice
> slicer.GoToBegin();
> for(int i=0;i<slice;i++) {
> slicer.NextSlice();
> }
>
> // BUG-SOLVING-LINE: slicer.SetIndex(slicer.GetIndex());
>
> // Fill out the 2D image
> int sliceIdx = 0;
> while ( !slicer.IsAtEndOfSlice() ) {
> while ( !slicer.IsAtEndOfLine() ) {
> sliceArray[sliceIdx++] = (unsigned char) floor(255 *
> slicer.Value());
> ++slicer;
> } slicer.NextLine();
> }
> }
>
> No matter which slice number I pass on to this piece of code, it places
> the first slice of the 3D image into the 2D array.
>
> However, if I uncomment the line labeled BUG-SOLVING-LINE, things start
> working again. Seems like the iterator is keeping a pair
> of internal references to the currently selected pixel, and they are
> getting out of sync.
>
> BTW, can someone tell me how to get a userid and password for posting a
> bug using the online system?
>
> Thanks!
>
> Paul Yushkevich
> Cognitica Corporation
> pauly@cognitica.com
>
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
>