[Insight-users] ImageRegion from ThresholdImageFilter

Karthik Krishnan Karthik.Krishnan at kitware.com
Fri Mar 11 12:03:15 EST 2005


Hi Martin,

Thanks Zach. To add to Zach's solution, You can use the 
ImageMaskSpatialObject class can compute the bounding box instead of 
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

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
>



More information about the Insight-users mailing list