[Insight-developers] TransformIndexToPhysicalPoint/TransformPhysicalPointToIndex seem slow

kent williams norman-k-williams at uiowa.edu
Tue Jun 2 18:07:08 EDT 2009


I'll state in advance I haven't tried a release build, which I'm sure would
help somewhat, but...

I'm trying to blend two images that potentially have different origins,
spacing and dimensions.  So I am using this idiom:

    ImageType::Pointer curImage; // set elsewhere...
    itk::ImageRegionIteratorWithIndex<ImageType>
      curIt(accumulator,accumulator->GetLargestPossibleRegion());
    ImageType::PointType accPoint;

    for(;!curIt.IsAtEnd(); ++curIt)
      {
      ImageType::IndexType index(curIt.GetIndex());
      accumulator->TransformIndexToPhysicalPoint(index,accPoint);
      ImageType::IndexType curIndex;
      if(curImage->TransformPhysicalPointToIndex(accPoint,curIndex))
        {
        ImageType::PixelType curPixel(curImage->GetPixel(curIndex));
        curIt.Set(Blend(curIt.Value(),curPixel));
        }
      }
    }

This sort of Index->Point->Index transformation seems unavoidable, unless
I'm missing something, but it's dog slow compared to (for example) stepping
through two images with a regular ImageRegionIterator for both images.  And
this code doesn't even address proper interpolation of the voxels from the
second image.

It would probably be quicker to resample the second image to the first
image's spacing, then figure out the overlapping regions and use regular
RegionIterators, but that seems like overkill.  Certainly I could detect
cases where both images have the same spacing and do the simpler traversal
too.

But is there a way to make this sort of idiom faster?



More information about the Insight-developers mailing list