[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

Andreas Schuh andreas.schuh.84 at googlemail.com
Mon Mar 2 11:48:39 EST 2009


Hi Baoyun,

your code is somehow confusing.

Why do you instanciate inputimage in your main function at all? This  
isn't necessary as you later set the pointer to the image object  
create by the ImageFileReader filter.

Why do you instanciate an output image object in the main function and  
pass it to your IsotropicResample() template function where the  
parameter InternalFilter is set to the output of the ResampleFilter  
instance?

Moreover, there is the part missing where you compute the size that  
you set as OutputSize of the resample filter.

BTW To make your code more readable, you shouldn't name image types or  
image parameters using the postfix 'Filter'. Moreover, names of  
parameters or variables should start with a lower case letter for  
convenience. Upper case identifiers usually name types or functions/ 
methods.

--
regards
Andreas

Am 02.03.2009 um 17:09 schrieb Baoyun Li <baoyun_li123 at yahoo.com>:

>
> 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
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> 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://www.itk.org/mailman/listinfo/insight-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090302/3d24041e/attachment-0001.htm>


More information about the Insight-users mailing list