FrostImageFilter.cxxΒΆ
This example illustrates the use of the otb::FrostImageFilter. This filter belongs to the family of the edge-preserving smoothing filters which are usually used for speckle reduction in radar images.
This filter uses a negative exponential convolution kernel. The output of the filter for pixel p is:
where:
- : the decrease coefficient
- : the coordinates of the pixel inside the region defined by
- : the coordinates of the pixels belonging to
- : the variation coefficient computed over
Result of applying the FrostImageFilter to a SAR image.
Example usage:
./FrostImageFilter Input/GomaSmall.png Output/GomaSmallFrostFiltered.png 5 0.1
Example source code (FrostImageFilter.cxx):
#include "otbFrostImageFilter.h"
#include "otbImage.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
int main(int argc, char* argv[])
{
if (argc != 5)
{
std::cerr << "Usage: " << argv[0] << " inputImageFile ";
std::cerr << " outputImageFile radius deramp" << std::endl;
return EXIT_FAILURE;
}
typedef unsigned char PixelType;
typedef otb::Image<PixelType, 2> InputImageType;
typedef otb::Image<PixelType, 2> OutputImageType;
// The filter can be instantiated using the image types defined previously.
typedef otb::FrostImageFilter<InputImageType, OutputImageType> FilterType;
typedef otb::ImageFileReader<InputImageType> ReaderType;
typedef otb::ImageFileWriter<OutputImageType> WriterType;
ReaderType::Pointer reader = ReaderType::New();
FilterType::Pointer filter = FilterType::New();
WriterType::Pointer writer = WriterType::New();
writer->SetInput(filter->GetOutput());
reader->SetFileName(argv[1]);
// The image obtained with the reader is passed as input to the FrostImageFilter
filter->SetInput(reader->GetOutput());
// The method SetRadius() defines the size of the window to
// be used for the computation of the local statistics. The method
// SetDeramp() sets the K coefficient.
FilterType::SizeType Radius;
Radius[0] = atoi(argv[3]);
Radius[1] = atoi(argv[3]);
filter->SetRadius(Radius);
filter->SetDeramp(atof(argv[4]));
writer->SetFileName(argv[2]);
writer->Update();
}