Gradient of an itk::image of itk::Vector<float, 3>

Hi,

I have a filter that uses the itk::GradientImageFilter for regularization. It is templated over its input image type, and works correctly when that type is itk::Image<float, n>. I am trying to make that filter able to process multi-channel images, and in this process the current roadblock is the itk::GradientImageFilter. Is there a way to have the itk::GradientImageFilter process images of itk::Vector<float, 3> instead of plain floats ? The calculations only involve multiplications by scalars, sums and differences, which are all defined on itk::Vector<float, 3>.

I have tried the following, which fails to compile (error message below):

#include <itkGradientImageFilter.h>
#include <itkImageFileReader.h>

int main(){
typedef itk::Vector<float, 3> VectorPixelType;
typedef itk::Image<VectorPixelType, 2> VectorImageType;
typedef itk::Image<itk::CovariantVector<VectorPixelType, 2>, 2> GradientOfVectorImageType;

typedef itk::ImageFileReader<VectorImageType> VectorImageReaderType;
VectorImageReaderType::Pointer imageReader = VectorImageReaderType::New();
imageReader->SetFileName("image.mha");
imageReader->Update();

typedef itk::GradientImageFilter<VectorImageType, float, VectorPixelType, GradientOfVectorImageType> GradientFilterType;
GradientFilterType::Pointer gradientFilter = GradientFilterType::New();
gradientFilter->SetInput(imageReader->GetOutput());
gradientFilter->Update();

return EXIT_SUCCESS;
}

The error message: /home/mory/sources/itk/ITK/Modules/Core/Common/include/itkNeighborhoodInnerProduct.hxx:51: error: no match for ‘operator*’ (operand types are ‘float’ and ‘InputPixelRealType {aka itk::Vector<double, 3u>}’)
static_cast< OutputPixelValueType >( *o_it ) *

I am wondering if I am instantiating the itk::GradientImageFilter with the correct template arguments. Can anyone help ?

Hi @cyril.mory, from itkCovariantVector documentation:

 * CovariantVector is a templated class that holds a single vector
 * (i.e., an array of values).  CovariantVector can be used as the data
 * type held at each pixel in an Image or at each vertex of an Mesh.
 * The template parameter T can be any data type that behaves like a
 * primitive (or atomic) data type (int, short, float, complex).
 * The NVectorDimension defines the number of components in the vector array.

The class does not accept a VectorPixelType as the template parameter as you have in:
itk::CovariantVector<VectorPixelType, 2>

OK, thanks for the answer