[ITK-users] Buffered Region out of Range error
Matt McCormick
matt.mccormick at kitware.com
Tue Oct 27 18:22:23 EDT 2015
Hi Mike,
Does calling
UpdateLargestPossibleRegion()
instead of
Update()
help?
Matt
On Tue, Oct 27, 2015 at 5:59 PM, Michael Jackson
<mike.jackson at bluequartz.net> wrote:
> I have been struggling with this error all afternoon and I just can not “see” what I am doing wrong. I am getting the following exception message from our program:
>
> Failed to execute itk::SignedMaurerDistanceMapImage filter for Feature 9. Error Message returned from ITK:
> itk::ERROR: MultiThreader(0x7fb53486e200): Exception occurred during SingleMethodExecute
> /Users/Shared/DREAM3D_SDK/InsightToolkit-4.7.2/Modules/Core/Common/include/itkImageConstIterator.h:211:
> itk::ERROR: Region ImageRegion (0x12e6f6730)
> Dimension: 3
> Index: [0, 0, 0]
> Size: [64, 64, 4]
> is outside of buffered region ImageRegion (0x7fb53c0a8040)
> Dimension: 3
> Index: [0, 0, 0]
> Size: [0, 0, 0]
>
> So what are the reasons that this can happen? Basically we creating an unsigned char image where we fill in the pixels, then run the Itk filter on each unsigned char image. Finally we want to copy the final output data into one of our own arrays. I will post the code under here. Any help is greatly appreciated.
>
> size_t iDims[3] = { 0, 0, 0 };
> float origin[3] = { 0.0f, 0.0f, 0.0f };
> float resolution[3] = { 0.0f, 0.0f, 0.0f };
>
> image->getDimensions(iDims);
> image->getOrigin(origin);
> image->getResolution(resolution);
>
> int32_t numFeatures = m_SignedDistanceFields.size();
>
> typedef itk::Image<unsigned char, 3> BoolImageType;
> typedef itk::Image<float, 3> FloatImageType;
> std::vector<BoolImageType::Pointer> booleanFeatureImages(numFeatures);
> BoolImageType::IndexType start;
> BoolImageType::SizeType size;
> BoolImageType::RegionType region;
>
> start.Fill(0);
>
> size[0] = iDims[0];
> size[1] = iDims[1];
> size[2] = iDims[2];
>
> region.SetIndex(start);
> region.SetSize(size);
>
> for (int32_t i = 0; i < numFeatures; i++)
> {
> BoolImageType::Pointer tmpBoolImage = BoolImageType::New();
> tmpBoolImage->SetRegions(region);
> tmpBoolImage->Allocate();
> tmpBoolImage->SetOrigin(origin);
> tmpBoolImage->SetSpacing(resolution);
> tmpBoolImage->FillBuffer(0);
> booleanFeatureImages[i] = tmpBoolImage;
> }
>
> size_t zStride = 0;
> size_t yStride = 0;
> size_t index = 0;
>
> for (size_t z = 0; z < iDims[2]; z++)
> {
> zStride = z * iDims[1] * iDims[2];
> for (size_t y = 0; y < iDims[1]; y++)
> {
> yStride = y * iDims[0];
> for (size_t x = 0; x < iDims[0]; x++)
> {
> index = zStride + yStride + x;
> BoolImageType::IndexType pixelIndex;
> pixelIndex[0] = x;
> pixelIndex[1] = y;
> pixelIndex[2] = z;
> if (x == y && y == z) { booleanFeatureImages[0]->SetPixel(pixelIndex, 255); }
> booleanFeatureImages[m_FeatureIds[index]]->SetPixel(pixelIndex, 255);
> }
> }
> }
> // Compute signed distance field for each Feature
> typedef itk::SignedMaurerDistanceMapImageFilter<BoolImageType, FloatImageType> SignedMaurerFilter;
>
> for (int32_t i = 0; i < numFeatures; i++)
> {
> if (getCancel() == true) { return; }
> SignedMaurerFilter::Pointer signedDistMap = SignedMaurerFilter::New();
> float* tmpDistField = m_SignedDistanceFields[i].lock()->getPointer(0);
> signedDistMap->SetInsideIsPositive(false);
> signedDistMap->SetSquaredDistance(true);
> signedDistMap->SetUseImageSpacing(true);
> signedDistMap->SetInput(booleanFeatureImages[i]);
> try
> {
> signedDistMap->Update();
>
> for (size_t z = 0; z < iDims[2]; z++)
> {
> zStride = z * iDims[1] * iDims[2];
> for (size_t y = 0; y < iDims[1]; y++)
> {
> yStride = y * iDims[0];
> for (size_t x = 0; x < iDims[0]; x++)
> {
> index = zStride + yStride + x;
> BoolImageType::IndexType pixelIndex;
> pixelIndex[0] = x;
> pixelIndex[1] = y;
> pixelIndex[2] = z;
> FloatImageType::Pointer out = signedDistMap->GetOutput();
> out->SetBufferedRegion(region);
> tmpDistField[index] = out->GetPixel(pixelIndex);
> }
> }
> }
> }
> catch (itk::ExceptionObject& err)
> {
> setErrorCondition(-5);
> QString ss = QObject::tr("Failed to execute itk::SignedMaurerDistanceMapImage filter for Feature %1. Error Message returned from ITK:\n %2").arg(i).arg(err.GetDescription());
> notifyErrorMessage(getHumanLabel(), ss, getErrorCondition());
> }
> }
> --
> Mike Jackson
> BlueQuartz Software, LLC
> [e]: mike.jackson at bluequartz.net
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users
More information about the Insight-users
mailing list