[Insight-developers] writing filters to support scalar and vector image types
Nicholas Tustison
ntustison at gmail.com
Thu Sep 1 15:30:50 EDT 2011
Hi Kris,
For what it's worth, I was faced with the same conundrum in writing the
itkBSplineScatteredDataPointSetToImageFilter. I opted for your first
choice since it was the easiest.
Nick
On Sep 1, 2011, at 1:59 PM, Kris Zygmunt wrote:
> Hello,
> I am currently writing a filter that will need to support both scalar pixels and vector pixels. What is the recommended approach for handling this? Are there any best-of-class examples to look at for guidance? I will be assuming that the components of the vector are independent and thus be performing component-wise math such as addition, subtraction, multiplication, division, minimization, and maximization on each channel separately. I see a few different approaches possible:
>
> 1. I could easily write a filter that only works with vector pixels, but this would require the user to take any scalar image (greyscale, T1 MR, T2 MR, etc) and convert it to a vector (On the input, they could use a scalar image as vector image accessor. For the output image, they would also have to convert it back to a scalar image.) This approach seems overly complicated for users with scalar images.
>
> 2. I can provide both a scalar and vector implementation of the filter, but this will have a ton of redundancy, making maintenance more complicated and error-prone.
>
> 3. I could provide (maybe through numeric_traits??) a definition of operator*, operator/, etc that would do the component-wise operation. If this is undesirable due to ambiguity, I could also provide ComponentMultiply(val1, val2), ComponentDivide(val1, val2), etc that would have the appropriate specializations for both scalar data (would just default to operator* in this case) and vector data. And then call these functions as appropriate. Then for the special cases like finding min/max for each channel, I could call the appropriate specialization (for scalar just use MinimumMaximumImageFilter, for vector, loop over the components, calling MinimumMaximumImageFilter for each channel independently using an accessor/filter that extracts the components).
>
>
> Also, my approach for supporting RGB pixels is going to be to treat each color component as an independent channel (I'm writing a nonlocal means denoising filter). Is the ITK-preferred approach to have the user provide the data as a VectorImage in this case, or should I also apply the chosen strategy (1, 2, or 3 above) for RGB pixels as a third class to consider, separate from scalar and vector?
>
> Thanks!
> Kris
> _______________________________________________
> 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://kitware.com/products/protraining.html
>
> 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://www.itk.org/mailman/listinfo/insight-developers
More information about the Insight-developers
mailing list