[Insight-users] ImageRegion from ThresholdImageFilter

Zachary Pincus zpincus at stanford.edu
Thu Mar 10 18:25:10 EST 2005


> 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);



More information about the Insight-users mailing list