[Insight-users] Can't set pixel value to NULL using itkImageregionIterator in win32

Neil.Burdett at csiro.au Neil.Burdett at csiro.au
Wed Jun 30 00:38:44 EDT 2010


Hi,
    The following code works in a Linux (Ubuntu) environment but fails under win32. Any help would be greatly appreciated...

  typename GridImageType::SizeType size = m_Region.GetSize();
  typename GridImageType::SpacingType spacing = m_Grid->GetSpacing();
  itk::ImageRegionIterator<GridImageType> gridIterator(m_Grid, m_Region);

...

/* roundabout way to set the neighbours of each cortical voxel */
  typedef itk::Image<CorticalVoxel*, 3> VoxelPtrImageType;
  typename VoxelPtrImageType::Pointer voxelPtrs = VoxelPtrImageType::New();
  voxelPtrs->SetRegions(m_Region);
  voxelPtrs->Allocate();
  itk::ImageRegionIterator<VoxelPtrImageType> voxIterator(voxelPtrs, m_Region)

  /* initialise the cortical voxels, sample voxels and grid points */
  for (gridIterator.GoToBegin(), voxIterator.GoToBegin(); !gridIterator.IsAtEnd(); ++gridIterator, ++voxIterator)
  {
    GridPoint& point = gridIterator.Value();
    //     point.MRIData.resize(m_NumChannels);  // temporary, may not need to resize anyway (only applies if vector is used)
    const IndexType& index = gridIterator.GetIndex();

    sum = 0;
    for (unsigned int i = NUM_NON_BRAIN_GAUSSIAN; i < NUM_GAUSSIAN; ++i)
    {
      sum += point.Classification[i];
    }
    if (sum > m_MaxProbabilityValue)
    {
      for (unsigned int i = NUM_NON_BRAIN_GAUSSIAN; i < NUM_GAUSSIAN; ++i)
      {
        temp = ((milxCTEInternalPixelType) point.Classification[i]) / sum;  // gives a value from 0 to 1
        point.Classification[i] = (InternalProbabilityType) (temp * m_MaxProbabilityValue);
      }
      sum = m_MaxProbabilityValue;
    }

    /* determine whether data in any channel is zero */
    zeroData = false;
    for (unsigned int i = 0; i < m_NumChannels; ++i)
    {
      if (point.MRIData[i] == 0)
      {
        zeroData = true;
        break;
      }
    }

    if (sum > minProbability && !zeroData)
    {

       ...
    }
    Else
    {
       voxIterator.Set(NULL);
    }
  }

...


The code causes an exception at "voxIterator.Set(NULL);" under windows only (Visual Studio 9 2008) 0xC0000005: Access violation writing location 0x00000000.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100630/db2c282a/attachment.htm>


More information about the Insight-users mailing list