[Insight-users] Re: BilateralImageFilter
Brian Eastwood
beastwoo at email.unc.edu
Tue Aug 23 13:08:08 EDT 2005
Hi Suresh,
I'll take a stab at this. It looks like the range sigma you use is
pretty small (6). The range sigma is a measure of how similar intensity
values must be in order to be smoothed by the Bilateral filter. Check
out the excellent paper (Tomasi, C. and R. Manduchi, Bilateral
Filtering for Gray and Color Images, ICCV 1998) for a good
explaination. If you use a very large range sigma, the bilateral filter
behaves much like a regular Gaussian smoothing filter because the domain
term dominates. The trick is to find a good balance of parameters.
Is your input image particularly noisy? If so, and you're using a small
range sigma, it's likely that there is not much smoothing effect because
not many neighboring pixels are similar enough in intensity to be
smoothed. So, you would get an output image very similar to the input
image.
Also, I doubt you need to rescale the intensity of your image. If
anything, scale to intensities between 0 and 255, so that the image will
display properly in 8-bit image viewers. (Of course, you only want to
do this for display purposes, not for a real application.) Better yet,
make sure you're using an image viewer that reads 16 bit images
correctly--some viewers will clamp or wrap intensity values, making an
image appear pretty ugly.
Hope this helps,
Brian
>Message: 3
>Date: Tue, 23 Aug 2005 17:35:24 +0530
>From: Suresh G N <suresh.gn at gmail.com>
>Subject: [Insight-users] BilateralImageFilter
>To: Insight-users at itk.org
>Message-ID: <eb927c5c05082305056861461b at mail.gmail.com>
>Content-Type: text/plain; charset="iso-8859-1"
>
>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;
>}
>
>
More information about the Insight-users
mailing list