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:
<br><br>typedef itk::ImageMaskSpatialObject< Dimension > MaskType;<br>MaskType::Pointer mask = MaskType::New();<br>mask->SetImage( image1 );<br>ImageType::RegionType boundingBoxRegion = mask->GetAxisAlignedBoundingBox
<div id="1fga" class="ArwC7c ckChnd">Region();
<br><br>boundingBoxRegion.PadByRadius(10);<br><br>ConstIteratorType itr1(image1, boundingBoxRegion);<br><br>for (itr1.GoToBegin(); !itr1.IsAtEnd(); ++itr1)<br> {<br> vol1 += itr1.Get() ? 1 : 0;<br> }<br><br>
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?
</div>