Orfeo Toolbox  3.16
FrostImageFilter.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12 
13  This software is distributed WITHOUT ANY WARRANTY; without even
14  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  PURPOSE. See the above copyright notices for more information.
16 
17 =========================================================================*/
18 
19 
20 // Software Guide : BeginCommandLineArgs
21 // INPUTS: {GomaSmall.png}
22 // OUTPUTS: {GomaSmallFrostFiltered.png}
23 // 5 0.1
24 // Software Guide : EndCommandLineArgs
25 
26 // Software Guide : BeginLatex
27 //
28 // This example illustrates the use of the \doxygen{otb}{FrostImageFilter}.
29 // This filter belongs to the family of the edge-preserving smoothing
30 // filters which are usually used for speckle reduction in radar
31 // images.
32 //
33 // This filter uses a negative exponential convolution kernel.
34 // The output of the filter for pixel p is:
35 // $ \hat I_{s}=\sum_{p\in\eta_{p}} m_{p}I_{p} $
36 //
37 // where : $ m_{p}=\frac{KC_{s}^{2}\exp(-KC_{s}^{2}d_{s, p})}{\sum_{p\in\eta_{p}} KC_{s}^{2}\exp(-KC_{s}^{2}d_{s, p})} $
38 // and $ d_{s, p}=\sqrt{(i-i_{p})^2+(j-j_{p})^2} $
39 //
40 // \begin{itemize}
41 // \item $ K $ : the decrease coefficient
42 // \item $ (i, j)$ : the coordinates of the pixel inside the region
43 // defined by $ \eta_{s} $
44 // \item $ (i_{p}, j_{p})$ : the coordinates of the pixels belonging to $ \eta_{p} \subset \eta_{s} $
45 // \item $ C_{s}$ : the variation coefficient computed over $ \eta_{p}$
46 // \end{itemize}
47 //
48 //
49 //
50 // Most of this example is similar to the previous one and only the differences
51 // will be highlighted.
52 //
53 // First, we need to include the header:
54 //
55 // Software Guide : EndLatex
56 
57 // Software Guide : BeginCodeSnippet
58 #include "otbFrostImageFilter.h"
59 // Software Guide : EndCodeSnippet
60 
61 #include "otbImage.h"
62 #include "otbImageFileReader.h"
63 #include "otbImageFileWriter.h"
64 
65 int main(int argc, char * argv[])
66 {
67 
68  if (argc != 5)
69  {
70  std::cerr << "Usage: " << argv[0] << " inputImageFile ";
71  std::cerr << " outputImageFile radius deramp" << std::endl;
72  return EXIT_FAILURE;
73  }
74 
75  typedef unsigned char PixelType;
76 
77  typedef otb::Image<PixelType, 2> InputImageType;
78  typedef otb::Image<PixelType, 2> OutputImageType;
79 
80  // Software Guide : BeginLatex
81  //
82  // The filter can be instantiated using the image types defined previously.
83  //
84  // Software Guide : EndLatex
85 
86  // Software Guide : BeginCodeSnippet
88  // Software Guide : EndCodeSnippet
89 
90  typedef otb::ImageFileReader<InputImageType> ReaderType;
91 
92  typedef otb::ImageFileWriter<OutputImageType> WriterType;
93 
94  ReaderType::Pointer reader = ReaderType::New();
96 
97  WriterType::Pointer writer = WriterType::New();
98  writer->SetInput(filter->GetOutput());
99  reader->SetFileName(argv[1]);
100 
101  // Software Guide : BeginLatex
102  //
103  // The image obtained with the reader is passed as input to the
104  // \doxygen{otb}{FrostImageFilter}.
105  //
106  // \index{otb::FrostImageFilter!SetInput()}
107  // \index{otb::FileImageReader!GetOutput()}
108  //
109  // Software Guide : EndLatex
110 
111  // Software Guide : BeginCodeSnippet
112  filter->SetInput(reader->GetOutput());
113  // Software Guide : EndCodeSnippet
114 
115  // Software Guide : BeginLatex
116  //
117  // The method \code{SetRadius()} defines the size of the window to
118  // be used for the computation of the local statistics. The method
119  // \code{SetDeramp()} sets the $K$ coefficient.
120  //
121  // \index{otb::FrostImageFilter!SetRadius()}
122  // \index{otb::FrostImageFilter!SetDeramp()}
123  // \index{SetDeramp()!otb::FrostImageFilter}
124  //
125  // Software Guide : EndLatex
126 
127  // Software Guide : BeginCodeSnippet
128  FilterType::SizeType Radius;
129  Radius[0] = atoi(argv[3]);
130  Radius[1] = atoi(argv[3]);
131 
132  filter->SetRadius(Radius);
133  filter->SetDeramp(atof(argv[4]));
134  // Software Guide : EndCodeSnippet
135 
136  writer->SetFileName(argv[2]);
137  writer->Update();
138 
139  // Software Guide : BeginLatex
140  // Figure~\ref{fig:FROST_FILTER} shows the result of applying the Frost
141  // filter to a SAR image.
142  // \begin{figure}
143  // \center
144  // \includegraphics[width=0.44\textwidth]{GomaSmall.eps}
145  // \includegraphics[width=0.44\textwidth]{GomaSmallFrostFiltered.eps}
146  // \itkcaption[Frost Filter Application]{Result of applying the
147  // \doxygen{otb}{FrostImageFilter} to a SAR image.}
148  // \label{fig:FROST_FILTER}
149  // \end{figure}
150  //
151  // \relatedClasses
152  // \begin{itemize}
153  // \item \doxygen{otb}{LeeImageFilter}
154  // \end{itemize}
155  //
156  // Software Guide : EndLatex
157 
158  return EXIT_SUCCESS;
159 }

Generated at Sat Feb 2 2013 23:22:52 for Orfeo Toolbox with doxygen 1.8.1.1