Try <div><div><br></div><div><div>OutputImageType* rescaleoutputImage;</div><div>itk::SmartPointer<OutputImageType> 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"><<a href="mailto:zhangxx110@126.com" target="_blank">zhangxx110@126.com</a>></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'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<10;i++){<br> for( j=4;j<10;j++)<br> {<br> radius[0]=i;<br> radius[1]=j;<br> ReaderType::Pointer reader = ReaderType::New(); //Instance reader<br> reader->SetFileName(noisedFile.c_str() );</span></div>
<span>
<div><br> mFilterType::Pointer medianFilter = mFilterType::New();//Instance itk::MedianImageFilter<br> medianFilter->SetRadius(radius);<br> medianFilter->SetInput( reader->GetOutput() );</div>
<div> OutputImageType* mediaoutput=medianFilter->GetOutput();</div>
<div> </div>
<div> WriterType::Pointer mediawriter= WriterType::New();//Instance writer<br> mediawriter->SetFileName( "temporaryoutput.tif");<br> mediawriter->SetInput(mediaoutput);<br> mediawriter->Update(); //update<br>
</div>
<div> computePSNR->ComputeMSE(mediaoutput); //<span>Custom function to compute PSNR</span><br> float roundmediaPSNR=computePSNR->PSNR();</div>
<div><br> ReaderType::Pointer Bilateralreader = ReaderType::New(); //Instance reader </div>
<div> Bilateralreader->SetFileName("temporaryoutput.tif");</div>
<div> </div>
<div> FilterType::Pointer filter = FilterType::New();//Instance itk::BilateralImageFilter<br> filter->SetInput(Bilateralreader->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<Dimension; ii++)<br>
{<br> domainSigmas[ii] = i;<br> }<br> const double rangeSigma = j;<br> filter->SetDomainSigma( domainSigmas );<br> filter->SetRangeSigma( rangeSigma );</div>
<div><br> typedef itk::RescaleIntensityImageFilter< <br> OutputImageType, WriteImageType > RescaleFilterType;<br> RescaleFilterType::Pointer rescaler = RescaleFilterType::New();<br> rescaler->SetOutputMinimum( 0 );<br>
rescaler->SetOutputMaximum( 255 );<br> <br> rescaler->SetInput( filter->GetOutput() );<br> rescaleoutputImage=rescaler->GetOutput();<br> rescaler->Update(); //update<br> <br> computePSNR->ComputeMSE(rescaleoutputImage);// computer PSNR after MedianImageFilter and BilateralImageFilter<br>
float roundPSNR=computePSNR->PSNR();<br> if(roundPSNR>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's pointer</div>
<div> }<br> }<br>}//for</div>
<div><br> writer = WriterType::New();<br> writer->SetFileName("outputImage.tif" );<br> writer->SetInput(outputImage); //outputImage is NULL<br> writer->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>