[Insight-developers] ITK pipeline
XiongXiang Zhang
zhangxx110 at 126.com
Mon Oct 15 22:17:16 EDT 2012
Hi,
We try to compute the image's PSNR(Peak Signal to Noise Ratio) after MedianImageFilter and BilateralImageFilter .In
circulation, we wanted to keep the image pointer, but failed.
OutputImageType* rescaleoutputImage;
OutputImageType* outputImage;
for( i=4;i<10;i++){
for( j=4;j<10;j++)
{
radius[0]=i;
radius[1]=j;
ReaderType::Pointer reader = ReaderType::New(); //Instance reader
reader->SetFileName(noisedFile.c_str() );
mFilterType::Pointer medianFilter = mFilterType::New();//Instance itk::MedianImageFilter
medianFilter->SetRadius(radius);
medianFilter->SetInput( reader->GetOutput() );
OutputImageType* mediaoutput=medianFilter->GetOutput();
WriterType::Pointer mediawriter= WriterType::New();//Instance writer
mediawriter->SetFileName( "temporaryoutput.tif");
mediawriter->SetInput(mediaoutput);
mediawriter->Update(); //update
computePSNR->ComputeMSE(mediaoutput); //Custom function to compute PSNR
float roundmediaPSNR=computePSNR->PSNR();
ReaderType::Pointer Bilateralreader = ReaderType::New(); //Instance reader
Bilateralreader->SetFileName("temporaryoutput.tif");
FilterType::Pointer filter = FilterType::New();//Instance itk::BilateralImageFilter
filter->SetInput(Bilateralreader->GetOutput() );
const unsigned int Dimension = InputImageType::ImageDimension;// setting parameters for BilateralImageFilter
double domainSigmas[ Dimension ];
for(unsigned int ii=0; ii<Dimension; ii++)
{
domainSigmas[ii] = i;
}
const double rangeSigma = j;
filter->SetDomainSigma( domainSigmas );
filter->SetRangeSigma( rangeSigma );
typedef itk::RescaleIntensityImageFilter<
OutputImageType, WriteImageType > RescaleFilterType;
RescaleFilterType::Pointer rescaler = RescaleFilterType::New();
rescaler->SetOutputMinimum( 0 );
rescaler->SetOutputMaximum( 255 );
rescaler->SetInput( filter->GetOutput() );
rescaleoutputImage=rescaler->GetOutput();
rescaler->Update(); //update
computePSNR->ComputeMSE(rescaleoutputImage);// computer PSNR after MedianImageFilter and BilateralImageFilter
float roundPSNR=computePSNR->PSNR();
if(roundPSNR>psnr) // if the value of PSNR is greater than last turn
{
mediapsnr=roundmediaPSNR;
psnr=roundPSNR;
radiusi=radius[0];
radiusj=radius[1];
BilateraldomainSigma=domainSigmas[0];
BilateralrangeSigma=rangeSigma;
outputImage=rescaleoutputImage; //keep the image's pointer
}
}
}//for
writer = WriterType::New();
writer->SetFileName("outputImage.tif" );
writer->SetInput(outputImage); //outputImage is NULL
writer->Update();
If no circulation, it work well. Debug it, we found outputImage is NULL in the writer. We were surprised that in each round of circulation the pointer(outputImage, which point an image ) is released. How can we keep the image pointer?
Thanks.
XiongXiang Zhang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-developers/attachments/20121016/600e10db/attachment.htm>
More information about the Insight-developers
mailing list