Orfeo Toolbox  3.16
ExtractSegmentsExample.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: {amst.png}
22 // OUTPUTS: {amstSegmentExtraction.png}
23 // 10 3 10 0.5 10 10 3 10 0.5
24 // Software Guide : EndCommandLineArgs
25 
26 // Software Guide : BeginLatex
27 //
28 // This example illustrates the use of the \doxygen{otb}{ExtractSegmentsImageFilter}.
29 //
30 // The first step required to use this filter is to include its header file.
31 //
32 // Software Guide : EndLatex
33 
34 // Software Guide : BeginCodeSnippet
37 // Software Guide : EndCodeSnippet
38 
39 #include "otbImage.h"
40 #include "otbImageFileReader.h"
42 #include "otbImageFileWriter.h"
43 
44 int main(int argc, char * argv[])
45 {
46 
47  if (argc != 12)
48  {
49  for (int i = 0; i < argc; ++i)
50  std::cerr << argv[i] << std::endl;
51  std::cerr << "Usage: " << argv[0] << " inputImageFile ";
52  std::cerr << " outputSegmentsImageFile length width ";
53  std::cerr << " PixelSuppressionRadiusX PixelSuppressionAngularBeam ";
54 
55  std::cerr << " LocalHoughRadiusX LocalHoughRadiusY LocalHoughNumberOfLines";
56  std::cerr << " FillGapsRadius FillGapsAngularBeam" << std::endl;
57 
58  return EXIT_FAILURE;
59  }
60 
61  // Software Guide : BeginLatex
62  //
63  // Then we must decide what pixel type to use for the image. We
64  // choose to make all computations with floating point precision
65  // and rescale the results between 0 and 255 in order to export PNG images.
66  //
67  // Software Guide : EndLatex
68 
69  // Software Guide : BeginCodeSnippet
70  typedef float InternalPixelType;
71  typedef unsigned char OutputPixelType;
72  // Software Guide : EndCodeSnippet
73 
74  // Software Guide : BeginLatex
75  //
76  // The images are defined using the pixel type and the dimension.
77  //
78  // Software Guide : EndLatex
79 
80  // Software Guide : BeginCodeSnippet
81  typedef otb::Image<InternalPixelType, 2> InternalImageType;
82  typedef otb::Image<OutputPixelType, 2> OutputImageType;
83  // Software Guide : EndCodeSnippet
84 
85  // Software Guide : BeginLatex
86  //
87  // The filter can be instantiated using the image types defined above.
88  //
89  // Software Guide : EndLatex
90 
91  // Software Guide : BeginCodeSnippet
92  typedef otb::LineRatioDetectorImageFilter<InternalImageType,
93  InternalImageType> DetectorType;
94  typedef otb::ExtractSegmentsImageFilter<InternalImageType,
95  InternalImageType> ExtractorType;
96  // Software Guide : EndCodeSnippet
97 
98  // Software Guide : BeginLatex
99  //
100  // An \doxygen{ImageFileReader} class is also instantiated in order to read
101  // image data from a file.
102  //
103  // Software Guide : EndLatex
104 
105  // Software Guide : BeginCodeSnippet
106  typedef otb::ImageFileReader<InternalImageType> ReaderType;
107  // Software Guide : EndCodeSnippet
108 
109  // Software Guide : BeginLatex
110  //
111  // An \doxygen{ImageFileWriter} is instantiated in order to write the
112  // output image to a file.
113  //
114  // Software Guide : EndLatex
115 
116  // Software Guide : BeginCodeSnippet
117  typedef otb::ImageFileWriter<OutputImageType> WriterType;
118  // Software Guide : EndCodeSnippet
119 
120  // Software Guide : BeginLatex
121  //
122  // The intensity rescaling of the results will be carried out by the
123  // \code{itk::RescaleIntensityImageFilter} which is templated by the
124  // input and output image types.
125  //
126  // Software Guide : EndLatex
127 
128  // Software Guide : BeginCodeSnippet
129  typedef itk::RescaleIntensityImageFilter<InternalImageType,
130  OutputImageType> RescalerType;
131  // Software Guide : EndCodeSnippet
132 
133  // Software Guide : BeginLatex
134  //
135  // Both the filter and the reader are created by invoking their \code{New()}
136  // methods and assigning the result to SmartPointers.
137  //
138  // Software Guide : EndLatex
139 
140  // Software Guide : BeginCodeSnippet
141  ReaderType::Pointer reader = ReaderType::New();
142  DetectorType::Pointer detector = DetectorType::New();
143  ExtractorType::Pointer extractor = ExtractorType::New();
144  // Software Guide : EndCodeSnippet
145 
146  // Software Guide : BeginLatex
147  //
148  // The same is done for the rescaler and the writer.
149  //
150  // Software Guide : EndLatex
151 
152  // Software Guide : BeginCodeSnippet
153  RescalerType::Pointer rescaler = RescalerType::New();
154  WriterType::Pointer writer = WriterType::New();
155  // Software Guide : EndCodeSnippet
156 
157  reader->SetFileName(argv[1]);
158 
159  // Software Guide : BeginLatex
160  //
161  // The \code{itk::RescaleIntensityImageFilter} needs to know which
162  // is the minimu and maximum values of the output generated
163  // image. Those can be chosen in a generic way by using the
164  // \code{NumericTraits} functions, since they are templated over
165  // the pixel type.
166  //
167  // Software Guide : EndLatex
168 
169  // Software Guide : BeginCodeSnippet
170  rescaler->SetOutputMinimum(itk::NumericTraits<OutputPixelType>::min());
171  rescaler->SetOutputMaximum(itk::NumericTraits<OutputPixelType>::max());
172  // Software Guide : EndCodeSnippet
173 
174  // Software Guide : BeginLatex
175  //
176  // The image obtained with the reader is passed as input to the
177  // \doxygen{otb}{ExtractSegmentsImageFilter}. The pipeline is built as follows.
178  //
179  // \index{otb::ExtractSegmentsImageFilter!SetInput()}
180  //
181  // Software Guide : EndLatex
182 
183  // Software Guide : BeginCodeSnippet
184  detector->SetInput(reader->GetOutput());
185  extractor->SetInputImage(detector->GetOutput());
186  extractor->SetInputImageDirection(detector->GetOutputDirection());
187  extractor->SetLineValue(0.);
188  rescaler->SetInput(extractor->GetOutput());
189  writer->SetInput(rescaler->GetOutput());
190  // Software Guide : EndCodeSnippet
191 
192  // Software Guide : BeginLatex
193  //
194  // The methods \code{SetLengthLine()} and \code{SetWidthLine()}
195  // allow to set the minimum length and the typical witdh of the
196  // lines which are to be detected.
197  //
198  //
199  // Software Guide : EndLatex
200 
201  // Software Guide : BeginCodeSnippet
202  detector->SetLengthLine(atoi(argv[3]));
203  detector->SetWidthLine(atoi(argv[4]));
204 
205  unsigned int PixelSuppressionRadiusX((unsigned int) ::atoi(argv[5]));
206  float PixelSuppressionAngularBeam((float) ::atof(argv[6]));
207 
208  unsigned int LocalHoughRadiusX((unsigned int) ::atoi(argv[7]));
209  unsigned int LocalHoughRadiusY((unsigned int) ::atoi(argv[8]));
210  unsigned int LocalHoughNumberOfLines((unsigned int) ::atoi(argv[9]));
211 
212  float FillGapsRadius((float) ::atoi(argv[10]));
213  float FillGapsAngularBeam((float) ::atof(argv[11]));
214 
215  ExtractorType::SizeType PixelSuppressionRadius;
216  PixelSuppressionRadius[0] = PixelSuppressionRadiusX;
217  PixelSuppressionRadius[1] = PixelSuppressionRadiusX;
218 
219  extractor->SetPixelSuppressionRadius(PixelSuppressionRadius);
220  extractor->SetPixelSuppressionAngularBeam(PixelSuppressionAngularBeam);
221 
222  ExtractorType::SizeType LocalHoughRadius;
223  LocalHoughRadius[0] = LocalHoughRadiusX;
224  LocalHoughRadius[1] = LocalHoughRadiusY;
225 
226  extractor->SetLocalHoughRadius(LocalHoughRadius);
227  extractor->SetLocalHoughNumberOfLines(LocalHoughNumberOfLines);
228 
229  extractor->SetFillGapsRadius(FillGapsRadius);
230  extractor->SetFillGapsAngularBeam(FillGapsAngularBeam);
231  // Software Guide : EndCodeSnippet
232 
233  // Software Guide : BeginLatex
234  // \textbf{FIXME: set the methods}
235  // \index{otb::AssymetricFusionOfDetector!SetWidthLine()}
236  // \index{otb::AssymetricFusionOfDetector!SetLengthLine()}
237 
238  // The filter is executed by invoking the \code{Update()} method. If the
239  // filter is part of a larger image processing pipeline, calling
240  // \code{Update()} on a downstream filter will also trigger update of this
241  // filter.
242  //
243  // Software Guide : EndLatex
244 
245  // Software Guide : BeginCodeSnippet
246  extractor->Update();
247  // Software Guide : EndCodeSnippet
248 
249  writer->SetFileName(argv[2]);
250  writer->Update();
251 
252  // Software Guide : BeginLatex Figure~\ref{fig:LINECORRELATION_FILTER}
253  // shows the result of applying the AssymetricFusionOf edge detector filter
254  // to a SAR image. \begin{figure} \center
255  // \includegraphics[width=0.25\textwidth]{amst.eps}
256  // \includegraphics[width=0.25\textwidth]{amstSegmentExtraction.eps}
257  // \itkcaption[Line Correlation Detector Application]{Result of applying
258  // the \doxygen{otb}{AssymetricFusionOfDetectorImageFilter} to a SAR
259  // image. From left to right : original image, line intensity and
260  // edge orientation.} \label{fig:LINECORRELATION_FILTER} \end{figure}
261  //
262  // \relatedClasses
263  // \begin{itemize}
264  // \item \doxygen{otb}{AssymetricFusionOfDetectorImageFilter}
265  // \end{itemize}
266  // Software Guide : EndLatex
267 
268  return EXIT_SUCCESS;
269 }

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