[Insight-users] Image Pointer was passed to the template functin, disirable change happended in the template function, image informatin was lost in the main function

Baoyun Li baoyun_li123 at yahoo.com
Mon Mar 2 11:09:10 EST 2009



Dear All:
 
I am trying to do some resampling of image throuth template function. Below is example of my main program.
 
In the main program, I read an image and give inputimage=reader->GetOutput().
I decalare another image pointer,OutputImageType::Pointer image_high=OutputImageType::New();
both image pass to the tempalte functin as below
 
 IsotropicResample <3,InputImageType,OutputImageType,double> (inputimage,image_high,scale);

{ my template fucntion delcared as:

 template <unsigned int Dim,class TInputFilter, class TInternalFilter, class TScale> 
void IsotropicResample( TInputFilter* InputFilter, TInternalFilter* InternalFilter, TScale scale)


}

In the template function, I got the reampled image as following :

 resampler->Update();
   InternalFilter=resampler->GetOutput();
   writer->SetFileName("../data/out_test.hdr");
   writer->SetInput(InternalFilter);
       try
       {
      writer->Update();
       }
     catch( itk::ExceptionObject & excep )
      {
       std::cerr << "Exception caught !" << std::endl;
       std::cerr << excep << std::endl;
       }

I checked the result, the resampled image by the above writer is correct.

but I got empty image when I tried to write image_high defined in the main function. 

Can somebody tell me what will be the probolem

Baoyun

////code in the main program
 
  reader->SetFileName(argv[1]);
  InputImageType::Pointer inputimage=InputImageType::New();
  OutputImageType::Pointer image_high=OutputImageType::New();

   InputImageType::Pointer inputimage=InputImageType::New();
  OutputImageType::Pointer image_high=OutputImageType::New();

  try 
    {
    reader->Update();
    }
  catch( itk::ExceptionObject & excep )
    {
    std::cerr << "Exception caught!" << std::endl;
    std::cerr << excep << std::endl;
    }
inputimage=reader->GetOutput();

 IsotropicResample <3,InputImageType,OutputImageType,double> (inputimage,image_high,scale);

////template function

#ifndef _IsotropicResample_H_
#define _IsotropicResample_H_

#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#ifdef __BORLANDC__
#define ITK_LEAN_AND_MEAN
#endif

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
// Software Guide : BeginCodeSnippet
#include "itkResampleImageFilter.h"
#include "itkRecursiveGaussianImageFilter.h"
// Software Guide : EndCodeSnippet



// Software Guide : BeginCodeSnippet
#include "itkIdentityTransform.h"
#include "itkLinearInterpolateImageFunction.h"
#include "itkAffineTransform.h"
// Software Guide : EndCodeSnippet
// Software Guide : BeginCodeSnippet
#include "itkIntensityWindowingImageFilter.h"
#include "itkCastImageFilter.h"
#include <itkWindowedSincInterpolateImageFunction.h> 
#include "itkBSplineInterpolateImageFunction.h"

// Software Guide : EndCodeSnippet


//template <class TInputFilter, class TInternalFilter, class TScale>
//void IsotropicResample( TInputFilter* InputFilter, TInternalFilter* InternalFilter, TScale scale);

template <unsigned int Dim,class TInputFilter, class TInternalFilter, class TScale>
void IsotropicResample( TInputFilter* InputFilter, TInternalFilter* InternalFilter, TScale scale)
{
  
  typedef  TInputFilter InputImageType;
  typedef TInternalFilter OutputImageType;
  typedef   float           InternalPixelType;
  typedef itk::Image< InternalPixelType, Dim >   InternalImageType;

  typename InputImageType::ConstPointer inputImage = InputFilter;

  typename InputImageType::SpacingType inputSpacing= inputImage->GetSpacing();

///// do reampling
  
   resampler->SetSize( size );
   resampler->Update();
   InternalFilter=resampler->GetOutput();
   writer->SetFileName("../data/out_test.hdr");
   writer->SetInput(InternalFilter);
       try
       {
      writer->Update();
       }
     catch( itk::ExceptionObject & excep )
      {
       std::cerr << "Exception caught !" << std::endl;
       std::cerr << excep << std::endl;
       }
 
// 

};

#endif



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090302/a2f1a6b0/attachment.htm>


More information about the Insight-users mailing list