[Insight-users] Region.PadByRadius results in infinite loop during iteration

Bill Lorensen bill.lorensen at gmail.com
Thu Nov 22 13:15:07 EST 2007


Charlotte,

After you pad a region by a radius, the region may extend beyond the region
of the image. You should use the Crop method applied to your region. You
should crop the padded region by the buffered region of your image.

In fact, in itk itself, the call to PadByRadius is always followed by a
Crop. For example several filters have code like this:

////////////////////
  typename TInputImage::RegionType inputRequestedRegion;
  inputRequestedRegion = inputPtr->GetRequestedRegion();

  // pad the input requested region by the operator radius
  inputRequestedRegion.PadByRadius( radius );

  // crop the input requested region at the input's largest possible region
  if ( inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()) )
    {
    inputPtr->SetRequestedRegion( inputRequestedRegion );
    return;
    }
/////////////////

Of course, your code should not go into an infinite loop, so there is still
a problem. Please submit a bug

http://public.kitware.com/Bug/my_view_page.php

You will need to create an account if you do not already have one.

Bill

On Nov 22, 2007 12:37 PM, Bill Lorensen <bill.lorensen at gmail.com> wrote:

> Have you printed the region?
>
> On Nov 22, 2007 10:46 AM, Charlotte Curtis <curtisc at uoguelph.ca> wrote:
>
> > I'm trying to iterate over a subregion of an image, but the iterator
> > never seems to know when it reaches the end of the region.  My image is
> > fairly large, but only a small portion of it is non-zero (it's a
> > segmentation), so I don't want to waste time iterating through the whole
> > image.  The code that doesn't work is as follows:
> >
> > typedef itk::ImageMaskSpatialObject< Dimension >   MaskType;
> > MaskType::Pointer  mask = MaskType::New();
> > mask->SetImage( image1 );
> > ImageType::RegionType boundingBoxRegion =
> > mask->GetAxisAlignedBoundingBox Region();
> >
> > boundingBoxRegion.PadByRadius(10);
> >
> > ConstIteratorType itr1(image1, boundingBoxRegion);
> >
> > for (itr1.GoToBegin(); !itr1.IsAtEnd(); ++itr1)
> >     {
> >          vol1 += itr1.Get() ? 1 : 0;
> >     }
> >
> > The reason I am doing this is to compare two manual segmentations of the
> > same object.  It works just fine if I iterate over the entire image, but it
> > takes a while.  It also works if I don't try to pad the region, but then I
> > won't get accurate results because the discrepancies of one segmentation may
> > be slightly outside of the AxisAlignedBoundingBoxRegion of the other.  10
> > voxels seems like a fair margin of error, I doubt I could be off by that
> > much in my manual segmentation, so it seemed a reasonable approach.
> > However, the iteration loop keeps on going until it seg faults.  Is there
> > something else I should be doing to slightly increase the size of my
> > bounding box?
> >
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users at itk.org
> > http://www.itk.org/mailman/listinfo/insight-users
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20071122/e13bc25f/attachment.htm


More information about the Insight-users mailing list