[Insight-users] Trimming Images
Luis Ibanez
luis . ibanez at kitware . com
Sat, 31 May 2003 00:54:10 -0400
Hi Mathias,
One way to save memory is to figure out the bounding box
of the region in the image that contains the pixels of
the segmented object. Once you figure out this bounding
box you could use it to create an ImageRegion and setup
the itk::RegionOfInterestImageFitlter.
This filter will extract a subregion from your image.
It will update the origin of the output image, so it
will be automatically registered with the original image
(e.g. if you use TransformIndexToPhysicalPoint in the
reduced image, the points will map corectly into the
coordinate system of the original image.
The RegionOfInterestImageFilter is described in the
software guid:
http://www . itk . org/ItkSoftwareGuide . pdf
Section 6.4 "Extracting Regions", pdf-page 164.
------
In order to figure out the bounding box you could
do something like the following code
// The two opposite cornes of the ND bounding box
ImageType::IndexType start;
ImageType::IndexType end;
typedef itk::ImageRegionIteratorWithIndex< ImageType > Iterator;
Iterator it( image, image->GetBufferedRegion() );
it.GoToBegin();
const unsigned int dimension = image->GetImageDimension();
while( !it.IsAtEnd() )
{
if( it.Get() ) // iff pixel != 0
{
ImageType::IndexType index = it.GetIndex();
for( unsigned int i; i<dimension; i++)
{
if( index[i] < start[i] )
{
start[i] = index[i];
}
if( index[i] > end[i] )
{
end[i] = index[i];
}
}
}
++it;
}
ImageType::SizeType size = end - start;
ImageType::RegionType region;
region.SetIndex( start );
region.SetSize( size );
typedef itk::RegionOfInterestImageFilter<
ImageType, ImageType > FilterType;
FilterType::Pointer filter = FilterType::New();
filter->SetRegionOfInterest( region );
filter->SetInput( mySegmentedImage );
filter->Update();
ImageType::Pointer myBoundedSegmentedImage =
filter->GetOutput();
We should probably encapsulate this code in a
"itk::BoundingBoxImageCalculator" class.
It could even be templated over the condition
used to evaluate for the pixels, in that
way it could be used for something like
finding the bounding box of all the red
pixels in a color image.
BTW, Kent Williams from Iowa State U. is currently implementing
Octrees in ITK. This will allow to further reduce the amount of
memory required for representing segmentations.
Luis
----------------------
Mathias Seitel wrote:
> Hello all,
>
> I'm working on a software for segmenting rather large series of volumes.
> Both the original data and the segmentation results (volumes again)
> should be kept in memory. Since the segmentation regions will cover only
> a small part of the original image, in order not to waste memory, I'd
> like to trim the resulting itk::Images by cutting off as much of their
> borders as possible. The resulting image should just contain the minimum
> volume around the segmentation region. Is there any convenient way to
> achieve this? Thanks.
>
> Mathias
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at public . kitware . com
> http://public . kitware . com/mailman/listinfo/insight-users
>