[Insight-users] Using ExtractImageFilter in a loop

Kevin Zhang zhangk at uchicago.edu
Tue Aug 9 13:48:52 EDT 2011


Hello all,

I am attempting to implement a grid-based thresholding algorithm over a 
3D image volume. I am trying to use ExtractImageFilter to extract 2D 
square subregions from each slice in the volume. Code is as follows:

ExtractFilterType::Pointer ExtractSquareFilter = ExtractFilterType::New();
     for(unsigned int i = 0; i < numslices; i++)
     {
         // extract grid square, iterating across row and column of slice
         for(unsigned int sr = 0; sr < num; sr++)
         {
             for(unsigned int sc = 0; sc < num; sc++)
             {
                 FloatImageType::RegionType gsquare_region;
                 FloatImageType::RegionType::IndexType gsquare_index;
                 gsquare_index[0] = sc * sidelength;
                 gsquare_index[1] = sr * sidelength;
                 gsquare_index[2] = i; // set slice
                 gsquare_region.SetSize(gsquare_size);
                 gsquare_region.SetIndex(gsquare_index);
                 ExtractSquareFilter->SetInput(inputimg);
                ExtractSquareFilter->SetExtractionRegion(gsquare_region);
                 ExtractSquareFilter->UpdateLargestPossibleRegion();
                 Float2DImageType::Pointer square = 
ExtractSquareFilter->GetOutput();
                 square->DisconnectPipeline();
                 std::cerr << "Grid square extracted successfully" << 
std::endl;

The input dataset is a series of 128x128 images. I am currently trying 
to divide each slice into a 4x4 grid, where each square would be 32x32.

The errors I get when executing are:
itkImageConstIteratorWithIndex.txx:90: 
itk::ImageConstIteratorWithIndex<TImage>::ImageConstIteratorWithIndex(const 
TImage*, const typename TImage::RegionType&) [with TImage = 
itk::OrientedImage<float, 2u>]: Assertion `Region ImageRegion (0xbf7ff6ec)
   Dimension: 2
   Index: [0, 0]
   Size: [32, 32]
  is outside of buffered region ImageRegion (0x97d3680)
   Dimension: 2
   Index: [32, 0]
   Size: [32, 32]
' failed.

I have tried several things to fix this, including:
1. Instantiate the ExtractImageFilter inside the loop
2. Use UpdateLargestPossibleRegion() instead of Update() on 
ExtractImageFilter

Thanks in advance for any insights! No pun intended.)

Kevin Zhang
Student Research Assistant
Department of Radiology / Cancer Research Center
University of Chicago



More information about the Insight-users mailing list