[Insight-users] BilateralImageFilter

Suresh G N suresh.gn at gmail.com
Tue Aug 23 08:05:24 EDT 2005


Hi All,

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? 

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.

Thanks in advance
Suresh




/* BilateralImageFilter.cxx (Gaussian smoothing filter )
* Performs smoothing by using both domain and range neighborhoods. Pixels 
that are close to a
* pixel in the image domain and similar to a pixel in the image range are 
used to calculate the
* filtered value. Two Gaussian kernels (one in the image domain and one in 
the image range) are
* used to smooth the image. The result is an image that is smoothed in 
homogeneous regions yet
* has edges preserved. The result is similar to anisotropic diffusion but 
the implementation in
* non-iterative. Another benefit to bilateral filtering is that any distance 
metric can be used
* for kernel smoothing the image range. Bilateral filtering is capable of 
reducing the noise in
* an image by an order of magnitude while maintaining edges.
*/


Here is my code:
==========================================================
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkBilateralImageFilter.h"
#include "itkCastImageFilter.h"
#include "itkStatisticsImageFilter.h"

int main( int argc, char * argv[] )
{
if( argc < 5 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputImageFile outputImageFile domainSigma 
rangeSigma" << std::endl;//using 5.0 6.0
return 1;
}

typedef short InputPixelType;
typedef short OutputPixelType;

typedef itk::Image< InputPixelType, 2 > InputImageType;
typedef itk::Image< OutputPixelType, 2 > OutputImageType;

typedef itk::ImageFileReader< InputImageType > ReaderType;

typedef itk::BilateralImageFilter< InputImageType, OutputImageType > 
FilterType;
FilterType::Pointer filter = FilterType::New();

typedef itk::CastImageFilter< InputImageType, OutputImageType > 
CastFilterType;
CastFilterType::Pointer castFilter = CastFilterType::New();

typedef itk::StatisticsImageFilter< InputImageType > StatisticsFilterType;
StatisticsFilterType::Pointer statisticsFilter = 
StatisticsFilterType::New();

ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );

filter->SetInput( reader->GetOutput() );
statisticsFilter->SetInput( reader->GetOutput() );

double maxValue = statisticsFilter->GetMaximum();

const unsigned int Dimension = InputImageType::ImageDimension;
double domainSigmas[ Dimension ];
for(unsigned int i=0; i<Dimension; i++)
{
domainSigmas[i] = atof( argv[3] );
}
const double rangeSigma = atof( argv[4] );

filter->SetDomainSigma( domainSigmas );
filter->SetRangeSigma( rangeSigma );

typedef short WritePixelType;
typedef itk::Image< WritePixelType, 2 > WriteImageType;
typedef itk::RescaleIntensityImageFilter< OutputImageType, WriteImageType > 
RescaleFilterType;
RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();

rescaleFilter->SetOutputMinimum( 0 );
rescaleFilter->SetOutputMaximum( 1372); //Maximum intensity of the image

typedef itk::ImageFileWriter< WriteImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( argv[2] );

castFilter->SetInput( filter->GetOutput() );
rescaleFilter->SetInput( castFilter->GetOutput() );
writer->SetInput( rescaleFilter->GetOutput() );
writer->Update();

return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20050823/0dd0c2ea/attachment.htm


More information about the Insight-users mailing list