[Insight-users] ImageRegion from ThresholdImageFilter

Martin Kavec kavec at messi.uku.fi
Fri Mar 11 12:15:26 EST 2005


Hi Karthik,

On Friday 11 March 2005 18:03, Karthik Krishnan wrote:
> Hi Martin,
>
> Thanks Zach. To add to Zach's solution, You can use the
> ImageMaskSpatialObject class can compute the bounding box instead of

Thanks. As I have just wrote, I did my homework and after some brainstorming I 
found that ImageMaskSpatialObject does the job for me.

> writing your own function. It has been used in some registration
> examples in the Examples/ImageRegistration12.cxx
> http://www.itk.org/Insight/Doxygen/html/classitk_1_1ImageMaskSpatialObject.
>html
>
> ::ComputeBoundingBox()
>
> Thanks
> Regards
> Karthik

Thanks and have a nice weekend.

Martin

>
> Zachary Pincus wrote:
> >> What I need is something like
> >>
> >> typedef ImageType::RegionType outputRegion;
> >> outputRegion = filter->OutputImageRegionType;
> >>
> >> but compiler doesn't like the second line.
> >
> > That's because OutputImageRegionType is a *type*, not a member
> > variable. You can't "access" a type. Plus in ITK, member variables are
> > in general private or protected so you can't access them directly any
> > way.
> >
> > As it turns out, a quick inspection of the code for this filter
> > reveals that it does not in fact maintain a bounding box around the
> > thresholded pixels. You can verify this by looking at the member
> > variables of the class in the header file -- no region information is
> > tracked.
> >
> > You have several options to do this yourself. One is to simply iterate
> > through the image, and determine the bounding region yourself. This is
> > a very small amount of code. Another would be to modify the threshold
> > filter to maintain this information. It's a bit more work, but then
> > you don't need to iterate through the image a second time (if speed is
> > important.)
> >
> > Zach
> >
> > example code (from memory; may contain bugs)
> >
> > ImageType::IndexType low, high;
> > // initialize "high" at the lowest possible index and "low" at the
> > highest.
> > // then we work our way down to the real boundaries.
> > high = myImage->GetLargestPossibleRegion()->GetIndex();
> > low = high + myImage->GetLargestPossibleRegion()->GetSize();
> >
> > itk::ImageRegionConstIteratorWithIndex<ImageType>
> >   iter(myImage, myImage->GetLargestPossibleRegion);
> >
> > for(iter.GoToBegin(); !iter.IsAtEnd(); ++iter) {
> >   if (iter.Get() == insideThresholdValue) {
> >     ImageType::IndexType index = iter.GetIndex();
> >     for (int i = 0; i < ImageType::ImageDimension; i++) {
> >       if (high[i] < index[i]) high[i] = index[i];
> >       if (low[i] > index[i]) low[i] = index[i];
> >     }
> >   }
> > }
> >
> > ImageType::SizeType size;
> > for (int i = 0; i < ImageType::ImageDimension; i++) {
> >   size[i] = static_cast<ImageType::SizeType::SizeValueType>(high[i] -
> > low[i]);
> > }
> >
> > ImageType::RegionType thresholdedRegion(low, size);
> >
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users at itk.org
> > http://www.itk.org/mailman/listinfo/insight-users

-- 
*********************************
Department of Electrical Engineering and Computer Science
University of Liege
Sart-Tilman, Bldg. B28
Liege B-4000
BELGIUM

Phone: +32 4 366-2870
*********************************


More information about the Insight-users mailing list