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

Julien Jomier jjomier at cs.unc.edu
Mon Dec 20 12:54:04 EST 2004


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 know 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() 
> <<std::endl , So the importation is OK.
>  
> 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, Dimension > ImageType;
>  ImageType* inputImage=myFunction(...);
>  
> When I try to display std:cout<<inputImage << std::endl; I have a 
> 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 
> <http://fr.rd.yahoo.com/mail/taglines/*http://fr.rd.yahoo.com/evt=25917/*http://fr.rd.yahoo.com/mail_fr/mail_campaigns/splash/taglines_250/default/*http://fr.promotions.yahoo.com/mail/creer28.html> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users


More information about the Insight-users mailing list