[ITK] [ITK-users] Filter working on both itk::Image and itk::VectorImage

Cyril Mory cyril.mory at creatis.insa-lyon.fr
Wed Feb 22 04:38:14 EST 2017


Hi ITK users,

I am writing an itk::ImageToImageFilter<T>, and I want the filter to 
work with T=itk::Image as well as with T=itk::VectorImage.

To set/get the vectorLength of an image (which is 1 for an itk::Image, 
and varies for an itk::VectorImage), I have successfully used the 
functions Set/GetNumberOfComponentsPerPixel from the itk::ImageBase 
class, which work for both itk::Image and itk::VectorImage.

But I cannot find a way to initialize one of the pixels to a given 
value, that would work for both cases, i.e. whether that pixel is a 
scalar or a variableLengthVector. For now, the best I could do is define 
a function FillPixel in my filter, like this:

OutputImagePixelType FillPixel(OutputImageInternalPixelType value) 
{return value;}

and write a template specialization when my filter is instantiated with 
itk::VectorImage<float, 3>, like this:

template <>
itk::VariableLengthVector<float>
rtk::ConstantImageSource<itk::VectorImage<float, 3> >
::FillPixel(float value)
{
   itk::VariableLengthVector<float> vect;
   vect.SetSize(this->GetVectorLength());
   vect.Fill(value);
   return (vect);
}

Did I miss something ? Is there a better way of doing this in ITK ?

Looking forward to reading you,
Cyril

_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users


More information about the Community mailing list