[Insight-developers] Interpolation support in itk::ImageFunction

Ivan Macia imacia at vicomtech.org
Wed Feb 20 16:25:53 EST 2008


Hi Luis,

Sorry I did not explain myself very well.

1) InterpolateImageFunction and derived classes are ok as they are. They are
used to evaluate an image at continuous points by interpolating values from
the center of voxels using a given interpolation scheme (nearest, linear...)

2) When deriving a new class from image Function and implementing the method
EvaluateAtIndex() it is clear how to proceed. In my example I calculate a
Hessian Gaussian tensor locally using discrete Gaussian operators.

3) The problem arises when I want to implement Evaluate( const PointType& )
or EvaluateAtContinuousIndex( const ContinuousIndexType & ), that is
evaluating the implemented ImageFunction at continuous points. What I would
expect as a default behaviour, or at least, in a new class derived from
ImageFunction, is to be able to calculate the value at continuous points as
a function of the value at discrete index with an interpolation scheme one
could select (maybe as template parameter).

Well, as I was writing this, I implemented what I just mentioned :) (see
attached files; note that I did not even compile this and is for
demonstrative purposes but it is very close to a final implementation)

I derived a new class from ImageFunction called DiscreteImageFunction. This
would be a subclass for those ImageFunctions  that can only calculate values
at discrete indexes and the rest need to be interpolated.

The class relies on a template parameter which is an InterpolateFunctor.
Different interpolation schemes can be implemented that derive from
InterpolateFunctor (I implemented NearestNeighbour and Linear, the latter
adapting code from LinearInterpolateImageFunction). Thus
DiscreteImageFunction relies on this functor for the implementation of
Evaluate( const PointType& ) or EvaluateAtContinuousIndex( const
ContinuousIndexType & ). The user derives from DiscreteImageFunction and
simply implements EvaluateAtIndex( const IndexType & )

I will try to use this code for my implementation. If you think it might be
useful to contribute it to ITK I could incorporate it in a new release of my
previous IJ paper (as my ImageFunctions will use it in the new release) or
alternatively make a new small contribution on this.

In case you need it, the link to my previous IJ paper is
http://www.insight-journal.org/InsightJournalManager/view_reviews.php?back=publications.php%3Fjournalid%3D9%26order%3Drating%26revision_display%3Dcombined&pubid=179


Best regards

Ivan






2008/2/20, Luis Ibanez <luis.ibanez at kitware.com>:
>
>
> Hi Ivan,
>
>
> I'm not sure I'm interpreting your suggestion correctly.
>
>
> It seems that you are proposing that the ImageFunction class
> should implement the EvaluateAtIndex() method by using the
> code of the LinearInterpolateImageFunction.
>
>
> Is that right ?
>
> From looking at the current code, here is what I gather:
>
>
> 0) itk::ImageFunction has defined a pure virtual method
>     EvaluateAtIndex()
>
> 1) itk::InterpolateImageFunction (a class that derives
>     from itk::ImageFunction) has an implementation of the method
>     EvaluateAtIndex() with the following code:
>
>
>    virtual outputtype evaluateatindex( const indextype & index ) const
>      {
>      return ( static_cast<realtype>(
>         this->getinputimage()->getpixel( index ) ) );
>      }
>
>
> 2) itk::LinearInterpolateImageFunction (a class that derives
>     from itk::InterpolateImageFunction) does not have an
>     implementation of the EvaluateAtIndex() method. (e.g.
>     relies on the implementation in the superclass (1)).
>
>
>
> I don't quite see the reason for moving the implementation
> of EvaluateAtIndex() up to the itk::ImageFunction.
>
> Shouldn't the right solution be that instead of you deriving
> your new class from the itk::ImageFunction, you should derive
> it from the itk::InterpolateImageFunction or from the
> itk::LinearInterpolateImageFunction ?
>
>
> Please help us understand the  reasons why a different
> derivation would not solve the problem.
>
>
>      Thanks
>
>
>         Luis
>
>
> ------------------
> Iván Macía wrote:
> > Hi,
> >
> >
> >
> > Some time ago I implemented some image functions in a contribution to
> > the Insight Journal.
> >
> >
> >
> >
> http://www.insight-journal.org/InsightJournalManager/view_reviews.php?back=publications.php%3Fjournalid%3D9%26order%3Drating%26revision_display%3Dcombined&pubid=179
> > <
> http://www.insight-journal.org/InsightJournalManager/view_reviews.php?back=publications.php%3Fjournalid%3D9%26order%3Drating%26revision_display%3Dcombined&pubid=179
> >
> >
> >
> >
> > The code uses nearest neighbour interpolation in the Evaluate() method
> > as this interpolation mode is trivial to implement.
> >
> >
> >
> > However, in order to use linear interpolation I had to add a flag to my
> > ImageFunction-derived class and copy some code from
> > LinearInterpolateImageFunction. What I do is copy the corresponding code
> > from itk::LinearInterpolateImageFunction and replace the call
> >
> >
> >
> > this->GetInputImage()->GetPixel( neighIndex )
> >
> >
> >
> > to get the image valur of each neighbour with the call
> >
> >
> >
> > this->EvaluateAtIndex( neighIndex )
> >
> >
> >
> > as the values are not yet calculated inside the ImageFunction.
> >
> >
> >
> > In my opinion such functionality should be in the ImageFunction
> > superclass itself but I wasn't able to find any support for this. I
> > wanted to know if there is any built-in support to do this in
> > ImageFunction and otherwise what would be the best way to do it (using
> > an enum? a template parameter? reusing interpolation image functions? ).
> >
> >
> >
> > Thanks in advance
> >
> >
> >
> > Iván Macía
> >
> >
> >
> >
> > No virus found in this outgoing message.
> > Checked by AVG Free Edition.
> > Version: 7.5.516 / Virus Database: 269.19.19/1257 - Release Date:
> > 03/02/2008 17:49
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Insight-developers mailing list
> > Insight-developers at itk.org
> > http://www.itk.org/mailman/listinfo/insight-developers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.itk.org/mailman/private/insight-developers/attachments/20080220/3331f9c2/attachment.htm


More information about the Insight-developers mailing list