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

Cyril Mory cyril.mory at creatis.insa-lyon.fr
Wed Feb 22 05:52:22 EST 2017


Answering my own question:

I found a way to do what I needed using itk::NumericTraits<T> :

   OutputImagePixelType pix;
   itk::NumericTraits<OutputImagePixelType>::SetLength(pix, 
this->GetVectorLength());
   pix = itk::NumericTraits<OutputImagePixelType>::OneValue(pix) * value;

It works for both cases with the same code. However, if there is a 
better way (cleaner, safer, more compact, ... whatever the wayin which 
it is better), I'd be happy to learn about it.

Best regards,
Cyril

On 22/02/2017 10:38, Cyril Mory wrote:
> 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

_____________________________________
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