[Insight-users] metrics and image masks

Christoph Niedermayr niedermayr at trium.de
Thu Aug 17 07:57:42 EDT 2006


Hi!

I stumbled upon the following:
I'm using itk::NormalizedCorrelationImageToImageMetric with both fixed and moving image masks.
my masks are itk::ImageSpacialObjects.
since i was getting segfaults i took a look into the code of itk::NormalizedCorrelationImageToImageMetric and itk::MattesMutualInformationImageToImageMetric and this turned up:
- at first a sample from the fixed image is taken.
- then it is checked whether the sample is inside the fixed mask by calling GetPixel(index). note that GetPixel *doesn't check the array bounds*. so this works as long the fixed mask has at least the size of the fixed image (is this safe to assume? i dont think so..)
- then the sample is transformed to the moving image space
- the interpolator determines whether the sample is within the moving image
- then it is *always* checked whether the sample is inside the moving mask, again by calling GetPixel(index). this can fail because the transformed point may be outside the moving image mask' buffer (which indeed has been tested using the iterator, but is ignored!)


here's the code snippet from itkMattesMutualInformationImageToImageMetric.txx:1240
___
// Check if mapped point inside image buffer
sampleOk = this->m_Interpolator->IsInsideBuffer( mappedPoint );
[...]
// If user provided a mask over the Moving image
if ( this->m_MovingImageMask )
  {
  // Check if mapped point is within the support region of the moving image mask
  sampleOk = sampleOk && this->m_MovingImageMask->IsInside( mappedPoint );
  }
___


i recommend the following simple remedy:
___
// Check if mapped point inside image buffer
sampleOk = this->m_Interpolator->IsInsideBuffer( mappedPoint );
[...]
// If user provided a mask over the Moving image
if ( this->m_MovingImageMask && sampleOk)
  {
  // Check if mapped point is within the support region of the moving image mask
  sampleOk = sampleOk && this->m_MovingImageMask->IsInside( mappedPoint );
  }
___


i found this issue in itk 2.6 but after a quick glance at 2.8.1 the code looks the same.
also i would recommend to check if the sample from the fixed image is inside the fixed image mask by using physical coordinates instead of pixel indices.

I hope I'm not mistaken :)
Best regards,
Chris Niedermayr



More information about the Insight-users mailing list