[Insight-users] Problems with templated image

Mark Hastenteufel M . Hastenteufel at dkfz-heidelberg . de
Tue, 28 May 2002 19:09:27 +0200


Hi Luis,

thanks for your prompt answer. You gave me some example code for
converting inhouse images to itk images. I have some further questions.
First, are you sure the code you gave me runs? If I want to compile this
little piece of test code


switch (a) {
  case 0: typedef vector<int> bb;
    break;
  case 1: typedef vector<double> bb;
    break;
}

I get the following compile errors:

test1.cpp: In function `int main()':
test1.cpp:186: conflicting types for `typedef class
vector<double,allocator<double> > bb'
test1.cpp:184: previous declaration as `typedef class
vector<int,allocator<int> > bb'


The second questions regards the templated image dimension. What should
I do, if I do not know the dimension of the image prior reading from
disk or converting. We are working in our group with 2D, 3D as well as
4D (3D over time) images. So I want to implement code which runs for all
kind of image dimensionality. Do you have any suggestions regarding this
problem?


Thanks,

Mark


Luis Ibanez schrieb:
> 
> 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
> >
> >
> >
> >

-- 
Mark Hastenteufel
Deutsches Krebsforschungszentrum         (German Cancer Research Center)
Div. Medical and Biological Informatics H0100    Tel: (+49) 6221-42 2353
Im Neuenheimer Feld 280                          Fax: (+49) 6221-42 2345
D-69120 Heidelberg              e-mail            M.Hastenteufel@DKFZ.de
Germany                         http://www.dkfz.de/mbi/people/markh.html