Hi All,<br>
<br>
I am trying to use BilateralImageFilter to perform the Guassian
operation on the image. When I run the code I am getting some noisy
images. Can any one tell me what's wrong with my code? <br>
<br>
I tried using StatisticsImageFilter to find out the Maximum Intensity
value in the image to rescale the image (Assuming that is causing
noise) It did not give any correction.<br>
<br>
Thanks in advance<br>
Suresh<br>
<br>
<br>
<br>
<br>
/* BilateralImageFilter.cxx (Gaussian smoothing filter )<br>
* Performs smoothing by using both domain and range neighborhoods. Pixels that are close to a<br>
* pixel in the image domain and similar to a pixel in the image range are used to calculate the<br>
* filtered value. Two Gaussian kernels (one in the image domain and one in the image range) are<br>
* used to smooth the image. The result is an image that is smoothed in homogeneous regions yet<br>
* has edges preserved. The result is similar to anisotropic diffusion but the implementation in<br>
* non-iterative. Another benefit to bilateral filtering is that any distance metric can be used<br>
* for kernel smoothing the image range. Bilateral filtering is capable of reducing the noise in<br>
* an image by an order of magnitude while maintaining edges.<br>
*/<br>
<br>
<br>
Here is my code:<br>
==========================================================<br>
#include "itkImage.h"<br>
#include "itkImageFileReader.h"<br>
#include "itkImageFileWriter.h"<br>
#include "itkRescaleIntensityImageFilter.h"<br>
#include "itkBilateralImageFilter.h"<br>
#include "itkCastImageFilter.h"<br>
#include "itkStatisticsImageFilter.h"<br>
<br>
int main( int argc, char * argv[] )<br>
{<br>
if( argc < 5 )<br>
{<br>
std::cerr << "Usage: " << std::endl;<br>
std::cerr << argv[0] << "
inputImageFile outputImageFile domainSigma
rangeSigma" << std::endl;//using 5.0 6.0<br>
return 1;<br>
}<br>
<br>
typedef short InputPixelType;<br>
typedef short OutputPixelType;<br>
<br>
typedef itk::Image< InputPixelType, 2 > InputImageType;<br>
typedef itk::Image< OutputPixelType, 2 > OutputImageType;<br>
<br>
typedef itk::ImageFileReader< InputImageType > ReaderType;<br>
<br>
typedef itk::BilateralImageFilter< InputImageType, OutputImageType > FilterType;<br>
FilterType::Pointer filter = FilterType::New();<br>
<br>
typedef itk::CastImageFilter< InputImageType, OutputImageType > CastFilterType;<br>
CastFilterType::Pointer
castFilter = CastFilterType::New();<br>
<br>
typedef itk::StatisticsImageFilter< InputImageType > StatisticsFilterType;<br>
StatisticsFilterType::Pointer statisticsFilter = StatisticsFilterType::New();<br>
<br>
ReaderType::Pointer reader = ReaderType::New();<br>
reader->SetFileName( argv[1] );<br>
<br>
filter->SetInput( reader->GetOutput() );<br>
statisticsFilter->SetInput( reader->GetOutput() );<br>
<br>
double maxValue = statisticsFilter->GetMaximum();<br>
<br>
const unsigned int Dimension = InputImageType::ImageDimension;<br>
double domainSigmas[ Dimension ];<br>
for(unsigned int i=0; i<Dimension; i++)<br>
{<br>
domainSigmas[i] = atof( argv[3] );<br>
}<br>
const double rangeSigma = atof( argv[4] );<br>
<br>
filter->SetDomainSigma( domainSigmas );<br>
filter->SetRangeSigma( rangeSigma );<br>
<br>
typedef short WritePixelType;<br>
typedef itk::Image< WritePixelType, 2 > WriteImageType;<br>
typedef itk::RescaleIntensityImageFilter< OutputImageType, WriteImageType > RescaleFilterType;<br>
RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();<br>
<br>
rescaleFilter->SetOutputMinimum( 0 );<br>
rescaleFilter->SetOutputMaximum( 1372); //Maximum intensity of the image<br>
<br>
typedef itk::ImageFileWriter< WriteImageType > WriterType;<br>
WriterType::Pointer writer = WriterType::New();<br>
writer->SetFileName( argv[2] );<br>
<br>
castFilter->SetInput( filter->GetOutput() );<br>
rescaleFilter->SetInput( castFilter->GetOutput() );<br>
writer->SetInput( rescaleFilter->GetOutput() );<br>
writer->Update();<br>
<br>
return 0;<br>
}<br>
<br>
<br>