Try <div><div><br></div><div><div>OutputImageType* rescaleoutputImage;</div><div>itk::SmartPointer&lt;OutputImageType&gt; outputImage;</div></div><div><br></div><br><div class="gmail_quote">On Tue, Oct 16, 2012 at 10:17 AM, XiongXiang Zhang <span dir="ltr">&lt;<a href="mailto:zhangxx110@126.com" target="_blank">zhangxx110@126.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="line-height:1.7;font-size:14px;font-family:arial"><div>Hi,</div>
<div>We try to compute the image&#39;s PSNR(Peak Signal to Noise Ratio) after MedianImageFilter and BilateralImageFilter .In </div>
<div><span>circulation, we wanted to keep the image pointer, but failed.</span></div>
<div><span></span> </div>
<div><span>OutputImageType* rescaleoutputImage;</span></div>
<div><span>OutputImageType* outputImage;</span></div>
<div><span>for( i=4;i&lt;10;i++){<br>   for( j=4;j&lt;10;j++)<br> {<br>    radius[0]=i;<br>    radius[1]=j;<br>   ReaderType::Pointer reader = ReaderType::New(); //Instance reader<br>   reader-&gt;SetFileName(noisedFile.c_str() );</span></div>
<span>
<div><br>  mFilterType::Pointer medianFilter = mFilterType::New();//Instance itk::MedianImageFilter<br>  medianFilter-&gt;SetRadius(radius);<br>  medianFilter-&gt;SetInput( reader-&gt;GetOutput() );</div>
<div> OutputImageType* mediaoutput=medianFilter-&gt;GetOutput();</div>
<div> </div>
<div>     WriterType::Pointer mediawriter= WriterType::New();//Instance writer<br>    mediawriter-&gt;SetFileName( &quot;temporaryoutput.tif&quot;);<br>   mediawriter-&gt;SetInput(mediaoutput);<br>  mediawriter-&gt;Update();         //update<br>
  </div>
<div>  computePSNR-&gt;ComputeMSE(mediaoutput);  //<span>Custom function to compute PSNR</span><br>  float roundmediaPSNR=computePSNR-&gt;PSNR();</div>
<div><br>    ReaderType::Pointer Bilateralreader = ReaderType::New(); //Instance reader </div>
<div>  Bilateralreader-&gt;SetFileName(&quot;temporaryoutput.tif&quot;);</div>
<div> </div>
<div>   FilterType::Pointer filter = FilterType::New();//Instance itk::BilateralImageFilter<br>  filter-&gt;SetInput(Bilateralreader-&gt;GetOutput() );</div>
<div><br>  const unsigned int Dimension = InputImageType::ImageDimension;//<span> setting p<span>arameters for BilateralImageFilter</span></span><br>  double domainSigmas[ Dimension ];<br>  for(unsigned int ii=0; ii&lt;Dimension; ii++)<br>
    {<br>      domainSigmas[ii] = i;<br>    }<br>  const double rangeSigma = j;<br>    filter-&gt;SetDomainSigma( domainSigmas );<br>  filter-&gt;SetRangeSigma(  rangeSigma   );</div>
<div><br>    typedef itk::RescaleIntensityImageFilter&lt; <br>               OutputImageType, WriteImageType &gt; RescaleFilterType;<br>  RescaleFilterType::Pointer rescaler = RescaleFilterType::New();<br>  rescaler-&gt;SetOutputMinimum(   0 );<br>
  rescaler-&gt;SetOutputMaximum( 255 );<br>  <br>    rescaler-&gt;SetInput( filter-&gt;GetOutput() );<br>  rescaleoutputImage=rescaler-&gt;GetOutput();<br>   rescaler-&gt;Update();  //update<br> <br>   computePSNR-&gt;ComputeMSE(rescaleoutputImage);// computer PSNR after MedianImageFilter and BilateralImageFilter<br>
  float roundPSNR=computePSNR-&gt;PSNR();<br>  if(roundPSNR&gt;psnr)  // if the value of PSNR is g<span>reater than last turn </span><br>  {<br>     mediapsnr=roundmediaPSNR;<br>  psnr=roundPSNR;<br>     radiusi=radius[0];<br>
     radiusj=radius[1];</div>
<div>  BilateraldomainSigma=domainSigmas[0];<br>     BilateralrangeSigma=rangeSigma;<br>     outputImage=rescaleoutputImage; //keep the image&#39;s pointer</div>
<div>    }<br>   }<br>}//for</div>
<div><br> writer = WriterType::New();<br> writer-&gt;SetFileName(&quot;outputImage.tif&quot; );<br> writer-&gt;SetInput(outputImage); //outputImage is NULL<br> writer-&gt;Update();</div>
<div> </div>
<div>
<div lang="EN-US">
<p><span> </span>If no <span>circulation, it work well</span>. Debug it, we found outputImage is NULL in the writer. We were surprised that in each round of <span>circulation the pointer(outputImage, which point an image ) is released. How can we keep the image pointer?</span></p>
<span></span></div>
<div lang="EN-US"><span>Thanks.</span></div><span class="HOEnZb"><font color="#888888">
<div lang="EN-US"><span>XiongXiang Zhang</span></div>
<p lang="EN-US"><br>  </p></font></span></div></span></div><br><br><span title="neteasefooter"><span></span></span><br>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://kitware.com/products/protraining.php" target="_blank">http://kitware.com/products/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-developers" target="_blank">http://www.itk.org/mailman/listinfo/insight-developers</a><br>
<br></blockquote></div><br></div>