[Insight-users] copy an image

Bill Lorensen bill.lorensen at gmail.com
Wed Dec 12 23:11:24 EST 2007


Alex,

I think you should pass in the smart pointer by reference. Otherwise, I
think it is copied.

Bill

On Dec 12, 2007 10:09 PM, Alex. GOUAILLARD <hanfei at caltech.edu> wrote:

> hi all,
>
> I developped (read: copied from the examples) a simple function that
> should resample a given 2D image according to the result of a
> registration (see attached file).
>
> I have a scope problem: after I copy the output of the filter in a
> separate disconnected image, if I write the image in a file from within
> the function, I have what I expect, but If I try to pass the pointer out
> and to print it from outside later, it fails. It looks like the buffer
> and a few other attributes are being wiped out.
>
> Any idea on what I am doing wrong? Better, any suggestion on what to do
> to make it right ?
>
> alex.
>
> #include "itkImageFileWriter.h"
> #include "itkVectorLinearInterpolateImageFunction.h"
> #include "itkVectorResampleImageFilter.h"
> #include "itkCastImageFilter.h"
> #include "itkTransform.h"
>
>
> template<class ImageType, class RegistrationType>
> int Resample(  typename ImageType::Pointer InImage,
>               typename ImageType::Pointer OutImage, // should be allocated
> outside
>               typename RegistrationType::Pointer InRegistration,
>               bool Write)
> {
>  //------------- resample RGB => Vector
>  typedef itk::VectorResampleImageFilter< ImageType, ImageType >
> ResampleFilterType;
>  ResampleFilterType::Pointer resampler = ResampleFilterType::New();
>  typedef itk::VectorLinearInterpolateImageFunction< ImageType, double >
>
>  ResamplerInterpolatorType;
>  ResamplerInterpolatorType::Pointer interpolator =
> ResamplerInterpolatorType::New();
>  resampler->SetInterpolator( interpolator );
>  resampler->SetInput( InImage );
>  resampler->SetTransform( InRegistration->GetOutput()->Get() );
>
>  resampler->SetSize( InImage->GetLargestPossibleRegion().GetSize() );
>  resampler->SetOutputOrigin(  InImage->GetOrigin() );
>  resampler->SetOutputSpacing( InImage->GetSpacing() );
>  resampler->SetDefaultPixelValue( 100 );
>
>  OutImage = resampler->GetOutput();
>  OutImage->DisconnectPipeline();
>
>  if(Write)
>    {
>    typedef itk::ImageFileWriter< ImageType >  WriterType;
>    WriterType::Pointer writer =  WriterType::New();
>    writer->SetFileName( "Resample.jpg" );
>    writer->SetInput( OutImage );
>    try
>      {
>      writer->Update();
>      }
>    catch ( itk::ExceptionObject &err)
>      {
>      std::cout << "ExceptionObject caught !" << std::endl;
>      std::cout << err << std::endl;
>      return -1;
>      }
>    }
>  return 0;
> }
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20071212/8eacd3a2/attachment.htm


More information about the Insight-users mailing list