[Insight-users] Using ExtractImageFilter in a loop
Dženan Zukić
dzenanz at gmail.com
Tue Aug 9 16:22:07 EDT 2011
I did slice extraction once. The code was posted on this list some months
ago. Take a look there.
You should set input image once, before the loops. You should not call
disconnect at all.
In loops, call setExtractionRegion, update and getOutput.
In the code excerpt you provided, you never initialize the
variable gsquare_size. It should be initialized before the loops, if it is
not already so.
I didn't know before that there exist "UpdateLargestPossibleRegion" :D
On Tue, Aug 9, 2011 at 19:48, Kevin Zhang <zhangk at uchicago.edu> wrote:
> 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
>
> ______________________________**_______
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/**opensource/opensource.html<http://www.kitware.com/opensource/opensource.html>
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/**products/protraining.html<http://www.kitware.com/products/protraining.html>
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_**FAQ <http://www.itk.org/Wiki/ITK_FAQ>
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/**listinfo/insight-users<http://www.itk.org/mailman/listinfo/insight-users>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110809/ddd9a3d2/attachment.htm>
More information about the Insight-users
mailing list