<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV>Hi, Andreas:</DIV>
<DIV> </DIV>
<DIV>Thanks a lot.</DIV>
<DIV> </DIV>
<DIV>Baoyun<BR></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><BR>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><FONT face=Tahoma size=2>
<HR SIZE=1>
<B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Andreas Schuh <andreas.schuh.84@googlemail.com><BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> Baoyun Li <baoyun_li123@yahoo.com><BR><B><SPAN style="FONT-WEIGHT: bold">Cc:</SPAN></B> "insight-users@itk.org" <insight-users@itk.org><BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Monday, March 2, 2009 12:23:46 PM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: Andreas, teach me more!!!<BR></FONT><BR>
<DIV>:)</DIV>
<DIV><BR></DIV>
<DIV>Well, I think your problem is a wrong understanding of what happens when you assign an output image returned by GetOutput() to a smart pointer of the output image' type. This is my explanation why you unnecessarily instantiate (too bad I spelled this wrong last time ...) your image types in the main function</DIV>
<DIV><BR></DIV>
<DIV>image_high = OutputImageType::New();</DIV>
<DIV><BR></DIV>
<DIV>where later you actually have this statement in your template function:</DIV>
<DIV><BR></DIV>
<DIV>InternalFilter = resampler->GetOutput();<BR><BR></DIV>
<DIV>...</DIV>
<DIV><BR></DIV>
<DIV>In your first solution you passed the adress of your image object referred to by image_high pointer to IsotropicResample(). However, this function had no chance to change the pointer image_high to refer to the actual image object returned by resampler->GetOutput().</DIV>
<DIV><BR></DIV>
<DIV>Now to your probable confusion: Each filter allocates its own output image objects of type Image. So, GetOutput() returns a pointer to these created output images. Assigning the returned pointer to a smart pointer just ensures that the reference counting is done properly and that the returned image stays alive even when the filter that produced it is destroyed. The images aren't copied.</DIV>
<DIV><BR></DIV>
<DIV>In your solution you changed the object the local pointer InternalFilter is pointing to but not the object image_high is pointing to as you didn't change the pointer image_high itself. So, image_high still pointed to the image object you created at the very beginning by OutputImage::New(), which is definitely an empty not even allocated image. This image instance is totally unnecessary as the resample filter creates its own instance. The same applies to the reader.</DIV>
<DIV><BR></DIV>
<DIV>Change the beginning of your main function as follows:</DIV>
<DIV><BR></DIV>
<DIV>InputImageType::Pointer inputimage;</DIV>
<DIV>OutputImageType::Pointer image_high;</DIV>
<DIV><BR></DIV>
<DIV>// reader update</DIV>
<DIV><BR></DIV>
<DIV>inputimage = reader->GetOutput();</DIV>
<DIV><BR></DIV>
<DIV>IsotropicResample(inputimage, image_high, scale);</DIV>
<DIV><BR></DIV>
<DIV>// ...</DIV>
<DIV><BR></DIV>
<DIV>BTW you should not need to template your IsotropicResample function over the dimension as the image types already include this information. Moreover, shouldn't you need to specify the template arguments explicitly. Just call the function as it wouldn't be a template and let the compiler decide which instantiation is needed depending on the types of the passed arguments.</DIV>
<DIV><BR></DIV>
<DIV>Hope this helps and is explained well enough.</DIV>
<DIV><BR></DIV>
<DIV>--</DIV>
<DIV>regards</DIV>
<DIV>Andreas</DIV>
<DIV><BR></DIV>
<DIV>Am 02..03.2009 um 18:47 schrieb Baoyun Li <<A href="mailto:baoyun_li123@yahoo.com" target=_blank rel=nofollow ymailto="mailto:baoyun_li123@yahoo.com">baoyun_li123@yahoo.com</A>>:<BR><BR></DIV>
<DIV><SPAN></SPAN></DIV>
<BLOCKQUOTE type="cite">
<DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV>Hi, Andreas:</DIV>
<DIV> </DIV>
<DIV>Thanks for your help.</DIV>
<DIV> </DIV>
<DIV>Can you further teach me, what I actuall did in my old code:</DIV>
<DIV><BR>TInternalFilter* InternalFilter</DIV>
<DIV> </DIV>
<DIV>to me I transfered the pointer of OutputImageType to the template function, what ever I did in the sub function, I should be able to get the reampled image since I transfter a pointer to the function.</DIV>
<DIV> </DIV>
<DIV>To me, it is same to pass pointer and reference. But obviously, I am wrong. Can you please teach me more.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Baoyun</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><BR>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><FONT face=Tahoma size=2>
<HR SIZE=1>
<B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Andreas Schuh <<A href="mailto:andreas.schuh.84@googlemail.com" target=_blank rel=nofollow ymailto="mailto:andreas.schuh.84@googlemail.com">andreas.schuh.84@googlemail.com</A>><BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> Andreas Schuh <<A href="mailto:andreas.schuh.84@googlemail.com" target=_blank rel=nofollow ymailto="mailto:andreas.schuh.84@googlemail.com">andreas.schuh.84@googlemail.com</A>><BR><B><SPAN style="FONT-WEIGHT: bold">Cc:</SPAN></B> Baoyun Li <<A href="mailto:baoyun_li123@yahoo.com" target=_blank rel=nofollow ymailto="mailto:baoyun_li123@yahoo.com">baoyun_li123@yahoo.com</A>>; "<A href="mailto:insight-users@itk.org" target=_blank rel=nofollow ymailto="mailto:insight-users@itk.org">insight-users@itk.org</A>" <<A href="mailto:insight-users@itk.org" target=_blank rel=nofollow ymailto="mailto:insight-users@itk.org">insight-users@itk.org</A>><BR><B><SPAN
style="FONT-WEIGHT: bold">Sent:</SPAN></B> Monday, March 2, 2009 10:55:36 AM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> Re: [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<BR></FONT><BR>
<DIV>I guess the problem you are talking about is that you want to pass the resampled image as out parameter InternalFilter of your IsotropicResample function, isn't it? But you're actually not doing what you want to. Use TInternalFilter::Pointer& as type for your out parameter InternalFilter and you will be able to use the result of the resampling after calling IsotropicResample in your main function.</DIV>
<DIV><BR></DIV>
<DIV>--</DIV>
<DIV>regards</DIV>
<DIV>Andreas</DIV>
<DIV><BR>Am 02.03.2009 um 17:48 schrieb Andreas Schuh <<A href="mailto:andreas.schuh.84@googlemail.com" target=_blank rel=nofollow ymailto="mailto:andreas.schuh.84@googlemail.com"><A href="mailto:andreas.schuh.84@googlemail.com" target=_blank rel=nofollow ymailto="mailto:andreas.schuh..84@googlemail.com">andreas.schuh.84@googlemail.com</A></A>>:<BR><BR></DIV>
<DIV></DIV>
<BLOCKQUOTE type="cite">
<DIV>
<DIV>Hi Baoyun,</DIV>
<DIV><BR></DIV>
<DIV>your code is somehow confusing.</DIV>
<DIV><BR></DIV>
<DIV>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.</DIV>
<DIV><BR></DIV>
<DIV>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?</DIV>
<DIV><BR></DIV>
<DIV>Moreover, there is the part missing where you compute the size that you set as OutputSize of the resample filter.</DIV>
<DIV><BR></DIV>
<DIV>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.<BR><BR></DIV>
<DIV>--</DIV>
<DIV>regards</DIV>
<DIV>Andreas</DIV>
<DIV><BR>Am 02..03.2009 um 17:09 schrieb Baoyun Li <<A href="mailto:baoyun_li123@yahoo.com" target=_blank rel=nofollow ymailto="mailto:baoyun_li123@yahoo.com"></A><A href="mailto:baoyun_li123@yahoo.com" target=_blank rel=nofollow ymailto="mailto:baoyun_li123@yahoo.com"><A href="mailto:baoyun_li123@yahoo.com" target=_blank rel=nofollow ymailto="mailto:baoyun_li123@yahoo.com">baoyun_li123@yahoo.com</A></A>>:<BR><BR></DIV>
<DIV></DIV>
<BLOCKQUOTE type="cite">
<DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV><BR></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><FONT face="Times New Roman">Dear All:</FONT></DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><FONT face="Times New Roman"></FONT> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><FONT face="Times New Roman">I am trying to do some resampling of image throuth template function. Below is example of my main program.</FONT></DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><FONT face="Times New Roman"></FONT> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><FONT face="Times New Roman">In the main program, I read an image and give inputimage=reader->GetOutput().</FONT></DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><FONT face="Times New Roman">I decalare another image pointer,</FONT><FONT face=Arial>OutputImageType::Pointer image_high=OutputImageType::New();</FONT></DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><FONT face="Times New Roman">both image pass to the tempalte functin as below</FONT></DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><FONT face="Times New Roman"></FONT> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> IsotropicResample <3,InputImageType,OutputImageType,double> (inputimage,image_high,scale);</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">{ my template fucntion delcared as:</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> template <unsigned int Dim,class TInputFilter, class TInternalFilter, class TScale>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">void IsotropicResample( TInputFilter* InputFilter, TInternalFilter* InternalFilter, TScale scale)<BR></DIV></DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">}</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">In the template function, I got the reampled image as following :</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> resampler->Update();<BR> InternalFilter=resampler->GetOutput();<BR> writer->SetFileName("../data/out_test.hdr");<BR> writer->SetInput(InternalFilter);<BR> try<BR> {<BR> writer->Update();<BR> }<BR> catch( itk::ExceptionObject & excep )<BR> {<BR> std::cerr << "Exception caught !" << std::endl;<BR> std::cerr << excep << std::endl;<BR> }</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">I checked the result, the resampled image by the above writer is correct..</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">but I got empty image when I tried to write image_high defined in the main function. </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">Can somebody tell me what will be the probolem</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">Baoyun<BR></DIV></DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><FONT face="Times New Roman">////code in the main program</FONT></DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><FONT face="Times New Roman"></FONT> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> reader->SetFileName(argv[1]);</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> InputImageType::Pointer inputimage=InputImageType::New();<BR> OutputImageType::Pointer image_high=OutputImageType::New();</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> InputImageType::Pointer inputimage=InputImageType::New();<BR> OutputImageType::Pointer image_high=OutputImageType::New();</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><BR> try <BR> {<BR> reader->Update();<BR> }<BR> catch( itk::ExceptionObject & excep )<BR> {<BR> std::cerr << "Exception caught!" << std::endl;<BR> std::cerr << excep << std::endl;<BR> }</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">inputimage=reader->GetOutput();</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> IsotropicResample <3,InputImageType,OutputImageType,double> (inputimage,image_high,scale);</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">////template function<BR><BR>#ifndef _IsotropicResample_H_<BR>#define _IsotropicResample_H_</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><BR>#if defined(_MSC_VER)<BR>#pragma warning ( disable : 4786 )<BR>#endif</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">#ifdef __BORLANDC__<BR>#define ITK_LEAN_AND_MEAN<BR>#endif</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><BR>#include "itkImage.h"<BR>#include "itkImageFileReader.h"<BR>#include "itkImageFileWriter.h"</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">// Software Guide : BeginCodeSnippet<BR>#include "itkResampleImageFilter.h"<BR>#include "itkRecursiveGaussianImageFilter.h"<BR>// Software Guide : EndCodeSnippet</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><BR>// Software Guide : BeginCodeSnippet<BR>#include "itkIdentityTransform.h"<BR>#include "itkLinearInterpolateImageFunction.h"<BR>#include "itkAffineTransform.h"<BR>// Software Guide : EndCodeSnippet</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">// Software Guide : BeginCodeSnippet<BR>#include "itkIntensityWindowingImageFilter.h"<BR>#include "itkCastImageFilter.h"<BR>#include <itkWindowedSincInterpolateImageFunction.h> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">#include "itkBSplineInterpolateImageFunction.h"</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><BR>// Software Guide : EndCodeSnippet</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><BR>//template <class TInputFilter, class TInternalFilter, class TScale></DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">//void IsotropicResample( TInputFilter* InputFilter, TInternalFilter* InternalFilter, TScale scale);</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><BR>template <unsigned int Dim,class TInputFilter, class TInternalFilter, class TScale></DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">void IsotropicResample( TInputFilter* InputFilter, TInternalFilter* InternalFilter, TScale scale)<BR>{<BR> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> typedef TInputFilter InputImageType;<BR> typedef TInternalFilter OutputImageType;<BR> typedef float InternalPixelType;<BR> typedef itk::Image< InternalPixelType, Dim > InternalImageType;</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><BR> typename InputImageType::ConstPointer inputImage = InputFilter;<BR></DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> typename InputImageType::SpacingType inputSpacing= inputImage->GetSpacing();<BR></DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">///// do reampling</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> <BR> resampler->SetSize( size );<BR> resampler->Update();<BR> InternalFilter=resampler->GetOutput();<BR> writer->SetFileName("../data/out_test.hdr");<BR> writer->SetInput(InternalFilter);<BR> try<BR> {<BR> writer->Update();<BR> }<BR> catch( itk::ExceptionObject & excep )<BR> {<BR> std::cerr << "Exception caught !" << std::endl;<BR> std::cerr << excep << std::endl;<BR> }<BR> <BR>// </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"><BR>};</DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif"> </DIV>
<DIV style="FONT-SIZE: 13px; FONT-FAMILY: arial, helvetica, sans-serif">#endif<BR></DIV></DIV></DIV><BR></DIV></BLOCKQUOTE>
<BLOCKQUOTE type="cite">
<DIV><SPAN>_____________________________________</SPAN><BR><SPAN>Powered by <A href="http://www.kitware.com/" target=_blank rel=nofollow></A><A href="http://www.kitware.com/" target=_blank rel=nofollow></A><A href="http://www.kitware.com/" target=_blank rel=nofollow><A href="http://www.kitware.com/" target=_blank rel=nofollow>www.kitware.com</A></A></SPAN><BR><SPAN></SPAN><BR><SPAN>Visit other Kitware open-source projects at</SPAN><BR><SPAN><A href="http://www.kitware.com/opensource/opensource.html" target=_blank rel=nofollow>http://www.kitware.com/opensource/opensource.html</A></SPAN><BR><SPAN></SPAN><BR><SPAN>Please keep messages on-topic and check the ITK FAQ at: <A href="http://www.itk.org/Wiki/ITK_FAQ" target=_blank rel=nofollow></A><A href="http://www.itk.org/Wiki/ITK_FAQ" target=_blank rel=nofollow>http://www.itk.org/Wiki/ITK_FAQ</A></SPAN><BR><SPAN></SPAN><BR><SPAN>Follow this link to subscribe/unsubscribe:</SPAN><BR><SPAN><A
href="http://www.itk.org/mailman/listinfo/insight-users" target=_blank rel=nofollow>http://www.itk.org/mailman/listinfo/insight-users</A></SPAN><BR></DIV></BLOCKQUOTE></DIV></BLOCKQUOTE></DIV></DIV></DIV><BR>listinfo/insight-users" target=_blank rel=nofollow><A href="http://www.itk.org/mailman/listinfo/insight-users" target=_blank rel=nofollow><A href="http://www.itk.org/mailman/listinfo/insight-users" target=_blank rel=nofollow>http://www.itk.org/mailman/listinfo/insight-users</A></A><BR><BR>ml></DIV></BLOCKQUOTE></DIV></DIV></div><br>
</body></html>