<div style="line-height:1.7;color:#000000;font-size:14px;font-family:arial"><DIV>Hi,</DIV>
<DIV>We try to compute the image's PSNR(Peak Signal to Noise Ratio) after MedianImageFilter and BilateralImageFilter&nbsp;.In </DIV>
<DIV><SPAN class="highlight" space="" rightZone="0|6" leftZone="0|6">circulation, we wanted to keep the image pointer, but failed.</SPAN></DIV>
<DIV><SPAN class="highlight" space="" rightZone="0|6" leftZone="0|6"></SPAN>&nbsp;</DIV>
<DIV><SPAN class="highlight" space="" rightZone="0|6" leftZone="0|6">OutputImageType* rescaleoutputImage;</SPAN></DIV>
<DIV><SPAN class="highlight" space="" rightZone="0|6" leftZone="0|6">OutputImageType* outputImage;</SPAN></DIV>
<DIV><SPAN class="highlight" space="" rightZone="0|6" leftZone="0|6">for( i=4;i&lt;10;i++){<BR>&nbsp;&nbsp; for( j=4;j&lt;10;j++)<BR>&nbsp;{<BR>&nbsp;&nbsp;&nbsp; radius[0]=i;<BR>&nbsp;&nbsp;&nbsp; radius[1]=j;<BR>&nbsp;&nbsp; ReaderType::Pointer reader = ReaderType::New(); //Instance reader<BR>&nbsp;&nbsp; reader-&gt;SetFileName(noisedFile.c_str() );</SPAN></DIV><SPAN class="highlight" space="" rightZone="0|6" leftZone="0|6">
<DIV><BR>&nbsp; mFilterType::Pointer medianFilter = mFilterType::New();//Instance itk::MedianImageFilter<BR>&nbsp; medianFilter-&gt;SetRadius(radius);<BR>&nbsp; medianFilter-&gt;SetInput( reader-&gt;GetOutput() );</DIV>
<DIV>&nbsp;OutputImageType* mediaoutput=medianFilter-&gt;GetOutput();</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp;&nbsp; WriterType::Pointer mediawriter= WriterType::New();//Instance writer<BR>&nbsp;&nbsp;&nbsp; mediawriter-&gt;SetFileName( "temporaryoutput.tif");<BR>&nbsp;&nbsp; mediawriter-&gt;SetInput(mediaoutput);<BR>&nbsp; mediawriter-&gt;Update();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //update<BR>&nbsp;&nbsp;</DIV>
<DIV>&nbsp; computePSNR-&gt;ComputeMSE(mediaoutput);&nbsp; //<SPAN class="highlight" space="" rightZone="0|15" leftZone="0|15">Custom function to compute PSNR</SPAN><BR>&nbsp; float roundmediaPSNR=computePSNR-&gt;PSNR();</DIV>
<DIV><BR>&nbsp;&nbsp;&nbsp;&nbsp;ReaderType::Pointer Bilateralreader = ReaderType::New(); //Instance reader&nbsp;</DIV>
<DIV>&nbsp; Bilateralreader-&gt;SetFileName("temporaryoutput.tif");</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp; FilterType::Pointer filter = FilterType::New();//Instance itk::BilateralImageFilter<BR>&nbsp; filter-&gt;SetInput(Bilateralreader-&gt;GetOutput() );</DIV>
<DIV><BR>&nbsp; const unsigned int Dimension = InputImageType::ImageDimension;//<SPAN class="highlight" space="" rightZone="0|12" leftZone="0|12"> setting p<SPAN class="highlight" space="" rightZone="0|12" leftZone="0|12">arameters for BilateralImageFilter</SPAN></SPAN><BR>&nbsp; double domainSigmas[ Dimension ];<BR>&nbsp; for(unsigned int ii=0; ii&lt;Dimension; ii++)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;domainSigmas[ii] = i;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; const double rangeSigma = j;<BR>&nbsp;&nbsp;&nbsp; filter-&gt;SetDomainSigma( domainSigmas );<BR>&nbsp; filter-&gt;SetRangeSigma(&nbsp; rangeSigma&nbsp;&nbsp; );</DIV>
<DIV><BR>&nbsp;&nbsp;&nbsp; typedef itk::RescaleIntensityImageFilter&lt; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OutputImageType, WriteImageType &gt; RescaleFilterType;<BR>&nbsp; RescaleFilterType::Pointer rescaler = RescaleFilterType::New();<BR>&nbsp; rescaler-&gt;SetOutputMinimum(&nbsp;&nbsp; 0 );<BR>&nbsp; rescaler-&gt;SetOutputMaximum( 255 );<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp; rescaler-&gt;SetInput( filter-&gt;GetOutput() );<BR>&nbsp; rescaleoutputImage=rescaler-&gt;GetOutput();<BR>&nbsp;&nbsp; rescaler-&gt;Update();&nbsp; //update<BR>&nbsp;<BR>&nbsp;&nbsp; computePSNR-&gt;ComputeMSE(rescaleoutputImage);// computer PSNR after MedianImageFilter and BilateralImageFilter<BR>&nbsp; float roundPSNR=computePSNR-&gt;PSNR();<BR>&nbsp; if(roundPSNR&gt;psnr)&nbsp; // if&nbsp;the value of PSNR is&nbsp;g<SPAN class="highlight" space="" rightZone="0|6" leftZone="0|6">reater than last turn </SPAN><BR>&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp; mediapsnr=roundmediaPSNR;<BR>&nbsp; psnr=roundPSNR;<BR>&nbsp;&nbsp;&nbsp;&nbsp; radiusi=radius[0];<BR>&nbsp;&nbsp;&nbsp;&nbsp; radiusj=radius[1];</DIV>
<DIV>&nbsp; BilateraldomainSigma=domainSigmas[0];<BR>&nbsp;&nbsp;&nbsp;&nbsp; BilateralrangeSigma=rangeSigma;<BR>&nbsp;&nbsp;&nbsp;&nbsp; outputImage=rescaleoutputImage; //keep the image's pointer</DIV>
<DIV>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;}<BR>}//for</DIV>
<DIV><BR>&nbsp;writer = WriterType::New();<BR>&nbsp;writer-&gt;SetFileName("outputImage.tif" );<BR>&nbsp;writer-&gt;SetInput(outputImage); //outputImage is NULL<BR>&nbsp;writer-&gt;Update();</DIV>
<DIV>&nbsp;</DIV>
<DIV>
<DIV id="trans-result-content" lang="EN-US" xml:lang="EN-US">
<P src="这段程序抛出错误"><SPAN space="0| " rightZone="18|6" leftZone="18|6">&nbsp;</SPAN>If no <SPAN class="highlight" space="" rightZone="0|6" leftZone="0|6">circulation, it work well</SPAN>. Debug it, we found outputImage is NULL in the writer. We were surprised that in&nbsp;each round of&nbsp;<SPAN class="highlight" space="" rightZone="0|6" leftZone="0|6">circulation the pointer(outputImage, which point&nbsp;an image&nbsp;) is released.&nbsp;How can we keep the image pointer?</SPAN></P><SPAN class="highlight" space="" rightZone="0|6" leftZone="0|6"></SPAN></DIV>
<DIV lang="EN-US" xml:lang="EN-US"><SPAN class="highlight" space="" rightZone="0|6" leftZone="0|6">Thanks.</SPAN></DIV>
<DIV lang="EN-US" xml:lang="EN-US"><SPAN class="highlight" space="" rightZone="0|6" leftZone="0|6">XiongXiang Zhang</SPAN></DIV>
<P lang="EN-US" xml:lang="EN-US" src="这段程序抛出错误"><BR>&nbsp; </P></DIV></SPAN></div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span>