[Insight-developers] writing filters to support scalar and vector image types

Kris Zygmunt krismz at sci.utah.edu
Thu Sep 1 13:59:54 EDT 2011


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


More information about the Insight-developers mailing list