[Insight-users] BUG in MattesMI (FixedImageMask, UseAllPixelsOn)

Christoph Niedermayr niedermayr at trium.de
Wed Aug 30 08:42:57 EDT 2006


Hi all!

I wanted to use the MattesMutualInformationImageToImageMetric with a
fixed (and moving) image masks.
The metric should use all pixels in the mask so i set UseAllPixelsOn().
After some hours of debugging :( i found the following bug:

in [1], the metric prepares for taking as much samples as the size of
the fixed image region
in [2], the whole fixed image is sampled, but "bad" samples outside the
mask are skipped (thats ok). the sample iterator only steps forward when
a "good" sample has been found. the loop only stops when the sample
container is full (thats bad).

this means that for each sample outside the mask, the iterator will step
one index *outside* the image buffer!

i hope i'm not mistaken!
chris


[1]
itkMattesMutualInformationImageToImageMetric.txx, line 237:
 if( m_UseAllPixels )
    {
    m_NumberOfSpatialSamples = 
              this->GetFixedImageRegion().GetNumberOfPixels();
    }
  
  /**
   * Allocate memory for the fixed image sample container.
   */
  m_FixedImageSamples.resize( m_NumberOfSpatialSamples );



[2]
itkMattesMutualInformationImageToImageMetric.txx, line 501:
  if( this->m_FixedImageMask )
    {

    typename Superclass::InputPointType inputPoint;

    iter=samples.begin();

    while( iter <= end )
      {
      // Get sampled index
      FixedImageIndexType index = regionIter.GetIndex();
      // Check if the Index is inside the mask, translate index to point
      this->m_FixedImage->TransformIndexToPhysicalPoint( index,
inputPoint );

      // If not inside the mask, ignore the point
      if( !this->m_FixedImageMask->IsInside( inputPoint ) )
        {
        ++regionIter; // jump to next pixel
        continue;
        }

      // Get sampled fixed image value
      (*iter).FixedImageValue = regionIter.Value();
      // Translate index to point
      (*iter).FixedImagePointValue = inputPoint;

      // Jump to random position
      ++regionIter;
      ++iter;
      }
    }



More information about the Insight-users mailing list