[Insight-users] Problems with templated image

Luis Ibanez luis . ibanez at kitware . com
Mon, 27 May 2002 19:01:09 -0400


Hi Mark,

There are several ways for dealing with the
integration of the ITK image and you inhouse
image class.

It depends of how much of each one is
composing your final application.

Here are some typical cases:



1) Reading Image Files into ITK

If what you want is to read your inhouse images
format from files there is a relatively easy
conversion to ITK images.  This is already done
in the ImageIO classes (for example in MetaImageIO).

ITK images and filters will definitely need to
have the type defined at compilet time. So you
have to decide which type of image you want to
process internally.  With this type of image in
mind you declare a : ImageFileReader<> templated
over the image type.

The reader will then read the header of your files
and apply an appropiate transformation to convert
the type of the image in the file to the type of
the ITK image that you selected. This transformation
typical involves a linear scaling and a casting.



2) Integrating inhouse code with ITK code

If what you want is to create an application
that uses classes and methods of your inhouse
software and at the same time uses ITK classes,
you may want to create an Adaptor class.

This adaptors will be in practice a variant of
an ITK filter capable of accepting one of your
inhouse images as input and producing an ITK
image (of particular predefined type) as output.

The filter will check the actual type of your
image at run time and according to that it will
apply an apropriate process in order to convert
your inhouse image to the ITK particular type.
This will typically require a switch statement
controlled by your image type, and each case
statement will use a particular combination of
the itkShiftScaleImageFilter.

For example:

   switch( inhouseImage->GetImageType() )
   {
    case CHAR:
       typedef ShiftScaleImageFilter< charImageType,
           itkImageType>  FilterType;
      FilterType::Pointer filter = FilterType::New();
      // here create an ITK image matching your
      // inhouse image type and share the data
      // buffer with your input image
      typedef Image< char, 3 > myImageType;
      filter->SetInput( myinhouseImageInITK );
      break;
    case  SHORT:
      typedef ShiftScaleImageFilter< shortImageType,
           itkImageType>  FilterType;
      FilterType::Pointer filter = FilterType::New();
      // here create an ITK image matching your
      // inhouse image type and share the data
      // buffer with your input image
      typedef Image< short, 3 > myImageType;
      filter->SetInput( myinhouseImageInITK );
      break;
    case ??:  //..... other possible types
     }




Please let us know if this corresponds to
what you had in mind.


Thanks


    Luis



----


Mark Hastenteufel wrote:
> Dear ITK community, dear ITK developers,
> 
> I'm using ITK for some weeks now and I like it. I use it for some
> registration tasks. But I encountered now a problem using the templated
> ITK image type. I wanted to implement a image converter to convert our
> inhouse image format to the itk image format. Our inhouse image format
> store internally the datatype and the dimension of the image, like vtk.
> But when I want to declare an itk image, I have to know before the
> dataype and the dimension. The same thing is when reading a raw image, I
> have to know the dataype and the dimension before.
> 
> It should be possible to read or convert an image without knowing its
> datatype and dimension. Do you have any suggestions how to handle this? 
> 
> Thanks in advance,
> 
> Mark
> 
> 
> 
>