[Insight-users] pixel type -- slcalar or non-scalar?

Miller, James V (Research) millerjv at crd.ge.com
Wed Dec 8 14:37:48 EST 2004


You can do some compile time checking of pixel types using the 
PixelTraits<> class.  This can be used to determine whether 
the dimension of a pixel (scalar, number of components of a vector).

Unfortunately, it cannot distinguish between a scalar and a single
component vector.

You can also use Brad's "Dispatch pattern", which uses function 
overloading to direct execution down different paths based on 
some criteria (for instance pixel dimension).  This is again
a compile time approach.  You have to provide multiple implementations
but only one implementation gets instantiated (based on the pixel type).

Search for "Dispatch" in the headers of ITK.  You'll find examples 
of how to do this like in:

BasicFilters/itkExtractImageFilter
BasicFilters/itkJoinImageFilter
Algorithms/itkMinMaxCurvatureFlowFunction

Jim




-----Original Message-----
From: Julien Jomier [mailto:jjomier at cs.unc.edu]
Sent: Wednesday, December 08, 2004 2:04 PM
To: Peng (Patrick) Cheng
Cc: Insight-users at itk.org
Subject: Re: [Insight-users] pixel type -- slcalar or non-scalar?


Hi Patrick,

If you want to check the pixel type at compile time, the simple answer 
if that you cannot do it. That's why ITK has different filters for 
vector images and scalar images.

If you want to check it at runtime you can use RTTI
(typeid(mypixeltype)).

Julien

Peng (Patrick) Cheng wrote:
> Hi Julien,
> 
> I still have a question:
> How do I check if the PixelType is a scalar or non-scalar?
> Do you have an example for that?
> 
> Thanks
> 
> Patrick
> 
> Julien Jomier wrote:
> 
>> Hi Patrick,
>>
>> This is correct. ITK doesn't have a general way of initializing both 
>> scalar and vector type at this point. You can initialize scalar and 
>> RGBPixel in the same function, but you have to create a separate 
>> function/class for images of vectors.
>>
>> Hope that helps,
>>
>> Julien
>>
>> Peng (Patrick) Cheng wrote:
>>
>>> hi all,
>>> I have following code:
>>>
>>>  InputPixelType p;
>>>  if(InputPixelType::GetNumberOfComponents()>1){
>>>    p.Fill(0);
>>>  }
>>>  else{
>>>    p = NumericTraits<InputPixelType>::Zero;
>>>  }
>>>
>>> When I pass the scalar pixel to this, it doesn't work.  Is that 
>>> becasue of scalar type don't have GetNumberOfComponents() method?
>>>
>>> How to rewrite this code?
>>>
>>> Thanks
>>>
>>> Patrick
>>>
>>
> 
_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users


More information about the Insight-users mailing list