[Insight-developers] Image-based cost function

Luis Ibanez luis.ibanez at kitware.com
Mon Jul 9 18:56:21 EDT 2007


Hi Dan,


Thanks for your detailed question.


1) The API of the CentralDifferenceImageFunction and
    GaussianDerivativeImageFunction classes is different
    due to an evolutionary bug.

    CovariantVector is the technically correct class
    for storing the gradient of a function. Gradients
    are not Vectors.  They behave different from vectors
    under AffineTransformations.

    This is indeed a bug in the GaussianDerivativeImageFunction
    which would be easy to fix, except for the fact that the
    backward compatibility policy of ITK requires us to make
    the change in such a way that previous code will still
    work.

    Please fell free to log a bug entry about this issue
    in the bug tracker.

       http://public.kitware.com/Bug/index.php



2) Half answered in (1), but just to go ahead with a
    pragmatic solution.


    Option A:

    One way to satisfy the backward compatibility policy
    and still solve the bug is to introduce a new class
    with a slightly different name, and mark this class
    as the one that will superseed the buggy one.

    At this point that will be the simplest solution:

    create a copy/pasted version of the GaussianDerivativeImageFunction
    and use the correct return type (CovariantVector). In this way
    you could unify the API of your class, so that the function that
    computes the derivates is indeed connected at run time.


    Option B:

    Yet another option, less elegant, but even more pragmatic
    is to take advantage of the fact that the Vector and CovariantVector,
    both derive from the FixedArray class.

    You could attempt to define the API of your class based on
    functions that feature the Fixed Array.



    Option A is by far a better solution than Option B.



      Regards,


      Luis



===========================
Dan Mueller wrote:
> Hi,
> 
> I am developing a simple cost function which computes the value and 
> derivative by interpolating a single underlying image (I have been 
> unable to find an existing class which achieves this). For the 
> GetValue() method, I have followed the ImageToImageMetric and defined an 
> InterpolatorType and Get/SetInterpolator methods (allowing the user to 
> define the interpolation method at run-time).
> 
> I wish to do something similar for the GetDerivative() method, but the 
> gradient image functions (eg. CentralDifferenceImageFunction and 
> GaussianDerivativeImageFunction) do not share a common base class 
> (except for ImageFunction which lacks the overriden output type). The 
> output types for these two functions are different (Vector for 
> GaussianDerivativeImageFunction and CovariantVector for 
> CentralDifferenceImageFunction).
> 
> *My first question:* Why are the output types different for these two 
> functions? I would have thought they compute similar information and 
> would therefore have the same output type.
> 
> I assume (I have not tried this yet so I could be wrong) that if these 
> two functions had the /same/ output type (ie. both Vector or both 
> CovariantVector) then I could define a GradientImageFunctionType in my 
> cost function similar to below:
> 
> typedef Vector< CoordRepType, ImageDimension > GradientOutputType;
> typedef ImageFunction< GradientOutputType, CoordRepType > 
> GradientImageFunctionType;
> itkSetObjectMacro( GradientImageFunction, GradientImageFunctionType );
> itkGetConstObjectMacro( GradientImageFunction, GradientImageFunctionType );
> 
> The user would then be able to specify the gradient image function at 
> run-time (which offers more control than using an explicitly typed 
> function). At present, the only way of achieving this is to template the 
> cost function over the GradientImageFunctionType, which is not very nice 
> for wrapping.
> 
> *My second question:* If there is no good reason for these functions to 
> have different output types, is it possible to change the output types 
> to be the same? Do I submit a bug to request this? Furthermore, is there 
> some merit in creating a base GradientImageFunction class from which 
> these (and any other) image functions derive?
> 
> Thanks for your help.
> 
> Cheers, Dan
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers


More information about the Insight-developers mailing list