[ITK] [ITK-users] Conversion of itk::Image to other formats

Lambert Zijp ljzijp at gmail.com
Fri Mar 11 07:14:06 EST 2016


Hi Timothee,

Thank you for responding. That was the kind of help I hoped to get!

Following code snippet compiles and links OK:

*template<typename ValueType,unsigned int Dimension>*
*int ItkToAvs(AVSfield** ppAvs, typename
itk::Image<ValueType,Dimension>::Pointer InputImage)*
*{ *
*  return 0;*
*}*

*main()*
*{*
*  typedef   short sPixelType;*
*  typedef itk::Image<sPixelType, 3> sVolume;*

*  AVSfield  *pAvs = NULL;*
*  sVolume::Pointer itkShortVolume;*



*  rc = ItkToAvs<sPixelType, 3>(&pAvs, itkShortVolume);*
*}*

However, if I put that function in another file (included in the project of
course) and add 'extern' before the 'int' return type, it compiles, but the
linker complains with:
*error LNK2019: unresolved external symbol "int __cdecl
ItkToAvs<short,3>(struct AVSfield * *,class itk::SmartPointer<class
itk::Image<short,3> >)*
I am pretty sure that all code in that file is being linked because there
are other functions in it that are used...
Any idea what is going on?

Also, it would be nice if the conversion function ItkToAvs could figure out
what the pixeltype is and what the number of dimensions are, instead of
providing them when calling the function. How can that be done?

Greetings,
Lambert





On Fri, Mar 11, 2016 at 11:35 AM, Timothee Evain <
tevain at telecom-paristech.fr> wrote:

> Hello Lambert,
>
> Try something like this :
>
> template<typename ValueType,unsigned int Dimension>
> extern int ItkToAvs(AVSfield** ppAvs, typename
> itk::Image<ValueType,Dimension>::Pointer InputImage);
>
> This way you should be able to use the function for any itkImage type,
> given that you provide the ValueType and the Dimension to the function at
> compile time like :
>
> [...]=ItkToAvs<ValueType,Dimension>([...]);
>
> But I cannot guarantee that this is the best way to do it, since I'm quite
> a beginner with templates.
>
> HTH,
>
> Tim
>
> ----- Mail original -----
> De: "Lambert Zijp" <ljzijp at gmail.com>
> À: "Matt McCormick" <matt.mccormick at kitware.com>
> Cc: insight-users at itk.org
> Envoyé: Jeudi 10 Mars 2016 18:06:35
> Objet: Re: [ITK] [ITK-users] Conversion of itk::Image to other formats
>
> Hi Matt,
>
> Let me try it this way. I tried all the following prototypes, but none of
> them worked. Probably some C++ syntax problem...
>
> template <class T1, int T2>
> extern int ItkToAvs(AVSfield** ppAvs, itk::Image<T1, T2> pItkImage);
>
> template <int T2>
> extern int ItkToAvs(AVSfield** ppAvs, itk::Image<fPixelType, T2>
> pItkImage);
>
> extern int ItkToAvs(AVSfield** ppAvs, itk::Image<fPixelType, 3> pItkImage);
>
> template< typename TImage>
> extern int ItkToAvs(AVSfield** ppAvs, TImage* pItkImage);
>
> template< typename TPixel, unsigned int VImageDimension>
> extern int ItkToAvs(AVSfield** ppAvs, const itk::Image<TPixel,
> VImageDimension> pItkImage);
>
> template< typename TObjectType>
> extern int ItkToAvs(AVSfield** ppAvs, const itk::SmartPointer<TObjectType>
> pItkImage);
>
> The first parameter is the output of the function. The second parameter is
> any itk image.
> As you can see, I don't know what I'm doing... Any idea what a good
> prototype would be?
>
> Greetings,
> Lambert
>
>
> On Thu, Mar 10, 2016 at 5:40 PM, Matt McCormick <
> matt.mccormick at kitware.com > wrote:
>
>
> Hi Lambert,
>
> A function prototype without templates would be run-time to run-time
> type comparison and conversion. The example shows how to do run-time
> to compile-time comparison, and it is relevant to both in-memory and
> file conversion.
>
> HTH,
> Matt
>
> On Thu, Mar 10, 2016 at 11:28 AM, Lambert Zijp < ljzijp at gmail.com > wrote:
> > Hi Sarthak,
> > There is no file I/O involved. It is about conversion in memory. In my
> > original post, MyFormat is a struct containing things like pixeltype and
> > number of dimensions and a couple of pointers to the pixels, the sizes of
> > the dimensions, and the coordinates. Conversion from MyFormat to itk, I
> got
> > more or less working. Now I want to convert from itk to MyFormat. A
> function
> > prototype is needed...
> >
> > Greetings,
> > Lambert
> >
> > On Thu, Mar 10, 2016 at 5:02 PM, Scapegoat Sarthak
> > < scapegoat.sarthak at gmail.com > wrote:
> >>
> >> Hi Lambert,
> >>
> >> What you could do is to make a function what just takes in a file name
> as
> >> input and call the templated ITK function inside as an inline function.
> >> There is no way I know to do I/O in ITK without using templates.
> >>
> >> Best,
> >> Sarthak
> >>
> >>
> >> On 10 March 2016 at 10:55, Lambert Zijp < ljzijp at gmail.com > wrote:
> >>>
> >>> Hi Scapegoat,
> >>> Thank you for responding. What would the function prototype then be (of
> >>> function that accepts any itk image. I mean, the syntax, preferably not
> >>> templated)?
> >>> Because I deal mostly with 3D or 4D signed short pixels (medical
> images),
> >>> I keep them as they are: half the memory consumption and easier
> histogram
> >>> computations.
> >>>
> >>> Greetings,
> >>> Lambert
> >>>
> >>> On Thu, Mar 10, 2016 at 4:35 PM, Scapegoat Sarthak
> >>> < scapegoat.sarthak at gmail.com > wrote:
> >>>>
> >>>> I would advice you to perform a check on the image dimensions (2 or 3)
> >>>> and keep the pixel type as float throughout. In any case you will be
> doing
> >>>> computation so the extra memory is going to be helpful.
> >>>>
> >>>>
> >>>> On 10 March 2016 at 10:28, Matt McCormick <
> matt.mccormick at kitware.com >
> >>>> wrote:
> >>>>>
> >>>>> Hi Lambert,
> >>>>>
> >>>>> This example shows how to read in an unknown image type. It
> >>>>> demonstrates how to go between run-time type specification and the
> >>>>> compile-image type specification of ITK.
> >>>>>
> >>>>>
> >>>>>
> http://itk.org/ITKExamples/src/IO/ImageBase/ReadUnknownImageType/Documentation.html
> >>>>>
> >>>>> This approach could be used for your problem.
> >>>>>
> >>>>> HTH,
> >>>>> Matt
> >>>>>
> >>>>> On Thu, Mar 10, 2016 at 9:56 AM, Lambert Zijp < ljzijp at gmail.com >
> wrote:
> >>>>> > Dear itk users,
> >>>>> > I'm new to itk and also not very proficient in C++...
> >>>>> > I want to try some deformable registration methods implemented in
> >>>>> > itk, and
> >>>>> > need to convert my own format of images and volumes to itk, and
> back.
> >>>>> > For conversion to itk, I use 'ImportImageFilter', because I do not
> >>>>> > want to
> >>>>> > make a copy of the pixels/voxels.
> >>>>> > Converting itk images and volumes back to my own format, is giving
> me
> >>>>> > a
> >>>>> > headache; I'm confused about 'Image', SmartPointer and ConstPointer
> >>>>> > and
> >>>>> > template stuff.
> >>>>> > Could you get me started by suggesting me a function prototype?
> >>>>> >
> >>>>> > Something like:
> >>>>> > int ItkToMyFormat(MyFormat** ppMyFormat, itk::Image* pItkImage);
> >>>>> >
> >>>>> > The ItkImage can be any pixeltype, any dimension, and vector images
> >>>>> > should
> >>>>> > also be accepted by the conversion routine. In that conversion
> >>>>> > function, and
> >>>>> > need to be able to put a switch on pixeltype and number of
> >>>>> > dimensions.
> >>>>> >
> >>>>> > Greetings,
> >>>>> > Lambert
> >>>>> >
> >>>>> > _____________________________________
> >>>>> > Powered by www.kitware.com
> >>>>> >
> >>>>> > Visit other Kitware open-source projects at
> >>>>> > http://www.kitware.com/opensource/opensource.html
> >>>>> >
> >>>>> > Kitware offers ITK Training Courses, for more information visit:
> >>>>> > http://www.kitware.com/products/protraining.php
> >>>>> >
> >>>>> > Please keep messages on-topic and check the ITK FAQ at:
> >>>>> > http://www.itk.org/Wiki/ITK_FAQ
> >>>>> >
> >>>>> > Follow this link to subscribe/unsubscribe:
> >>>>> > http://public.kitware.com/mailman/listinfo/insight-users
> >>>>> >
> >>>>> _____________________________________
> >>>>> Powered by www.kitware.com
> >>>>>
> >>>>> Visit other Kitware open-source projects at
> >>>>> http://www.kitware.com/opensource/opensource.html
> >>>>>
> >>>>> Kitware offers ITK Training Courses, for more information visit:
> >>>>> http://www.kitware.com/products/protraining.php
> >>>>>
> >>>>> Please keep messages on-topic and check the ITK FAQ at:
> >>>>> http://www.itk.org/Wiki/ITK_FAQ
> >>>>>
> >>>>> Follow this link to subscribe/unsubscribe:
> >>>>> http://public.kitware.com/mailman/listinfo/insight-users
> >>>>
> >>>>
> >>>
> >>
> >
>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users
>
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20160311/03f03c39/attachment-0001.html>
-------------- next part --------------
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users


More information about the Community mailing list