[Insight-users] Howto write custom pixelTypes

Karthik Krishnan karthik.krishnan at kitware.com
Fri Jun 27 14:57:37 EDT 2008


 
luke bloy wrote:
> Hi Karthik,
>
> That was pretty much what I had feared.
>
> The ability to extend the existing pixeltypes is pretty key to what i
> need to do, so I'm stuck with figuring out how to do it. Writing my own
> ImageIO classes seems like duplicating alot of good work and would be
> problematic if any integration into itk proper was done (which is the
> hope).
>
> So I have 2 questions.
>
> 1) Is there any documentation on the intricacies of the read write
> process? i've skimmed through some of the code, and seen all the type id
> checks, but i'm not sure of how it all works together. Any advice
> pointing in the right direction would be appreciated.
>   
Just add...


  else if ( ptype == typeid(MyPixelThatDerivesFromFixedArray<T,6>) ) 
       
    {
    This->SetNumberOfComponents(6);
    This->SetPixelType(ImageIOBase::FIXEDARRAY);
    This->SetComponentType(ntype);
    return true;
    }
  // Replace 6 above with whatever length your pixels are supposed to be


at the end of the long if.. else block in
    itkSetPixelType(...)
in itkImageIOBase.cxx

and your pixel type should work with ITK.  (I think).

Try it out.
> 2) Short term, I'm going to use an ImageCastFilter to upcast my class
> before the write. I had trouble instantiating the ImageCastFilter, do
> you know of any example code that uses it.
>   
You have to write your own filter.. Just iterate over all the pixels and 
copy it into a fixed array.

You can also write an adaptor if you like
> -luke
>
> These questions seem more appropriate to the developers group, but i
> don't think I was approved :)
>   
>  
>
> On Fri, 2008-06-27 at 10:45 -0400, Karthik Krishnan wrote:
>   
>> Unfortunately you cannot expect your created pixel types (whether they 
>> derive from existing ITK classes or not) to be readable and writable by 
>> ITK's ImageIO classes.
>>
>> We have typeid checks riddled throughout the ImageIO classes. These have 
>> the intent of serializing the pixel types, deriving information from 
>> them such as the number of components etc..
>>
>> In short, either
>>
>> 1. Stick with the existing pixel types in ITK.
>> 2. If you feel you must write your own pixel type, you'll have to either 
>> modify the ITK sources or write your own ImageIO classes as well.
>>
>> --
>> karthik
>>
>> luke bloy wrote:
>>     
>>> Hi all,
>>>
>>> I've written a subclass of itkFixedArray, that i am using as the
>>> pixeltype for some images. I'd like to be able to use the itk classes to
>>> do the file IO but i'm not sure how to tell the ImageIOBase classes
>>> about my class. When I try to use the niftiImageIO i get this error.
>>>
>>> itk::ERROR: NiftiImageIO(0x8117c30): Pixel type currently not supported.
>>>
>>> Since it's a basically a vector image i thought this should work. What
>>> should I do?
>>>
>>> -Luke
>>>
>>> _______________________________________________
>>> Insight-users mailing list
>>> Insight-users at itk.org
>>> http://www.itk.o
>>>       
>
>   

-- 
--
Karthik Krishnan
R & D Engineer,
Kitware Inc,




More information about the Insight-users mailing list