[Insight-users] ImportImageFilter->ItkImage ...

Mr Gaffe lagaffe74130 at yahoo.fr
Tue Dec 21 08:13:26 EST 2004


Thanks again julien, the definition is quite simple and obvious I understand why I spend all the last few years with JAVA ;-)
 
I look in the ImageToImageFilter to understand the strategy used by ITK to return an image after processing. The return type is an OutputTypeImage and not a Pointer, so I confuse because I don't know when and how to return an ImageType and when I have to return a Pointer (as I did in myFunction) ?
 
Lagaffe


Julien Jomier <jjomier at cs.unc.edu> wrote:
Hi Lagaffe,

I assume your function is inside the class MyObject.

In your .h:

typedef TImage ImageType;
typedef typename ImageType::Pointer InputImagePointer;
static InputImagePointer myFunction(...);

In your .txx:

template
MyObject::InputImagePointer
MyObject
::myFunction(...)
{
....
}

hope that helps,

Julien

Mr Gaffe wrote:
> Thanks jJulien it works,
> 
> maybe if I can another question about the implementation of static 
> methods in ITK...
> 
> myFunction is a static function and it is define in a .h and implemented 
> in a .txx
> so if I put everything in my .h like you said it works:
> 
> typedef typename ImageType::Pointer InputImagePointer;
> static InputImagePointer::Pointer myFunction(...)
> {
> ....
> }
> or if I don't want to use the typedef
> static typename TImage::Pointer myFunction(...)
> {
> ....
> }
> and you guess that My Object is templated using TImage ...
> 
> BUT, I don't know how to implement it in my .txx and just define the 
> header function in my .h as we do usually (it never compile ....)
> 
> .h
> typedef typename ImageType::Pointer InputImagePointer;
> static InputImagePointer::Pointer myFunction(...);
> .txx
> static InputImagePointer::Pointer myFunction(...)
> {
> }
> 
> Thanks julien for help,
> Lagaffe
> 
> */Julien Jomier /* wrote:
> 
> Hi Lagaffe,
> 
> This is an issue with smart pointers.
> As you probably know smart pointers delete themselves when there are
> not
> assigned anymore.
> In your case, in myFunction(), the ImportFilter is creating a smart
> pointer as output image, but myFunction() is returning a raw pointer,
> which means that the reference count is not incremented and the output
> pointer is destroyed at the end of the myFunction() scope.
> An easy fix is to make your function return a smart pointer and
> assign a
> smart pointer in your main.
> 
> Something like:
> 
> ImageType::Pointer myFunction()
> {
> ...
> return ImportFilter->GetOuput()
> }
> 
> and in your program:
> 
> typedef int PixelType;
> const int Dimension=2, Lx=7, Ly=5;
> typedef itk::Image < PixelType, Dimension > ImageType;
> ImageType::Pointer inputImage=myFunction(...);
> 
> Let us k! now if that was the problem,
> 
> Julien
> 
> Mr Gaffe wrote:
> > hello,
> >
> > I try to build an itkImage with a function wich use an
> > importImageFilter; I can display my image inside my function (so the
> > importation pipeline is ok), but when I try to do the same thing
> in my
> > program using the return itkImage pointer it doesn't work !
> >
> > basically this is my code;
> > function:
> >
> > ImageType* myFunction(...)
> > ... build the image and Import it with itkImportImageFilter
> > ... I did an Update
> > I can display my Image using std::cout << ImportFilter->GetOuput()
> > <
> >
> > finally,I return the pointer:
> > return ImportFilter->GetOuput()
> >
> > In my program:
> > typedef int PixelType;
> > const int Dimension=2, Lx=7, Ly=5;
> > typedef itk::Image < PixelType, Dimensi! on > ImageType;
> > ImageType* inputImage=myFunction(...);
> >
> > When I try to display std:cout<
> <<>> pointer value and not all the usual image information .... and
> if I try
> > to use inputImage to do something it crash !
> >
> > I think, I am not using the good return type or something like that?
> >
> > thanks for help
> > lagaffe
> >
> >
> >
> >
> >
> ------------------------------------------------------------------------
> > Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage
> pour vos
> > mails !
> > Créez votre Yahoo! Mail
> >
> >
> >
> >
> >
> ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users at itk.org
> > http://www.itk.org/mailman/listinfo/insight-users
> 
> ------------------------------------------------------------------------
> Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos 
> mails !
> Créez votre Yahoo! Mail 
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users

		
---------------------------------
 Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails !
Créez votre Yahoo! Mail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20041221/cb6ddeb4/attachment.html


More information about the Insight-users mailing list