AssymmetricFusionOfLineDetectorExample.cxx 7.03 KB
Newer Older
Jordi Inglada's avatar
Jordi Inglada committed
1 2
/*=========================================================================

Patrick Imbo's avatar
Patrick Imbo committed
3 4 5 6 7 8 9 10 11 12
  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


13 14
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Patrick Imbo's avatar
Patrick Imbo committed
15
     PURPOSE.  See the above copyright notices for more information.
Jordi Inglada's avatar
Jordi Inglada committed
16 17

=========================================================================*/
Patrick Imbo's avatar
Patrick Imbo committed
18

19

Jordi Inglada's avatar
Jordi Inglada committed
20 21
//  Software Guide : BeginCommandLineArgs
//    INPUTS: {amst.png}
22
//    OUTPUTS: {amstLineFusion.png}
23
//    5 1
Jordi Inglada's avatar
Jordi Inglada committed
24 25 26 27
//  Software Guide : EndCommandLineArgs

// Software Guide : BeginLatex
//
28
// This example illustrates the use of the \doxygen{otb}{AssymmetricFusionOfLineDetectorImageFilter}.
Jordi Inglada's avatar
Jordi Inglada committed
29
//
30
// The first step required to use this filter is to include its header file.
Jordi Inglada's avatar
Jordi Inglada committed
31
//
32
// Software Guide : EndLatex
Jordi Inglada's avatar
Jordi Inglada committed
33 34 35 36 37

// Software Guide : BeginCodeSnippet
#include "otbAssymmetricFusionOfLineDetectorImageFilter.h"
// Software Guide : EndCodeSnippet

38
#include "otbImage.h"
Jordi Inglada's avatar
Jordi Inglada committed
39
#include "otbImageFileReader.h"
40
#include "itkUnaryFunctorImageFilter.h"
Jordi Inglada's avatar
Jordi Inglada committed
41 42 43
#include "itkRescaleIntensityImageFilter.h"
#include "otbImageFileWriter.h"

OTB Bot's avatar
OTB Bot committed
44
int main(int argc, char * argv[])
Jordi Inglada's avatar
Jordi Inglada committed
45 46
{

OTB Bot's avatar
OTB Bot committed
47 48
  if (argc != 5)
    {
Jordi Inglada's avatar
Jordi Inglada committed
49
    std::cerr << "Usage: " << argv[0] << " inputImageFile ";
50
    std::cerr << " outputEdgesImageFile length width" << std::endl;
Jordi Inglada's avatar
Jordi Inglada committed
51
    return EXIT_FAILURE;
OTB Bot's avatar
OTB Bot committed
52
    }
53

Jordi Inglada's avatar
Jordi Inglada committed
54 55 56 57 58 59
  //  Software Guide : BeginLatex
  //
  //  Then we must decide what pixel type to use for the image. We
  //  choose to make all computations with floating point precision
  //  and rescale the results between 0 and 255 in order to export PNG images.
  //
60
  //  Software Guide : EndLatex
Jordi Inglada's avatar
Jordi Inglada committed
61 62

  // Software Guide : BeginCodeSnippet
OTB Bot's avatar
OTB Bot committed
63 64
  typedef  float         InternalPixelType;
  typedef  unsigned char OutputPixelType;
Jordi Inglada's avatar
Jordi Inglada committed
65 66 67 68 69 70
  // Software Guide : EndCodeSnippet

  //  Software Guide : BeginLatex
  //
  //  The images are defined using the pixel type and the dimension.
  //
71
  //  Software Guide : EndLatex
Jordi Inglada's avatar
Jordi Inglada committed
72 73

  // Software Guide : BeginCodeSnippet
OTB Bot's avatar
OTB Bot committed
74 75
  typedef otb::Image<InternalPixelType,  2> InternalImageType;
  typedef otb::Image<OutputPixelType,  2>   OutputImageType;
Jordi Inglada's avatar
Jordi Inglada committed
76 77 78 79 80 81
  // Software Guide : EndCodeSnippet

  //  Software Guide : BeginLatex
  //
  //  The filter can be instantiated using the image types defined above.
  //
82
  //  Software Guide : EndLatex
Jordi Inglada's avatar
Jordi Inglada committed
83 84

  // Software Guide : BeginCodeSnippet
OTB Bot's avatar
OTB Bot committed
85
  typedef otb::AssymmetricFusionOfLineDetectorImageFilter<InternalImageType,
OTB Bot's avatar
OTB Bot committed
86
      InternalImageType>
OTB Bot's avatar
OTB Bot committed
87
  FilterType;
Jordi Inglada's avatar
Jordi Inglada committed
88 89 90 91
  // Software Guide : EndCodeSnippet

  //  Software Guide : BeginLatex
  //
92
  //  An \doxygen{otb}{ImageFileReader} class is also instantiated in order to read
93
  //  image data from a file.
Jordi Inglada's avatar
Jordi Inglada committed
94
  //
95
  //  Software Guide : EndLatex
Jordi Inglada's avatar
Jordi Inglada committed
96 97

  // Software Guide : BeginCodeSnippet
OTB Bot's avatar
OTB Bot committed
98
  typedef otb::ImageFileReader<InternalImageType> ReaderType;
Jordi Inglada's avatar
Jordi Inglada committed
99 100 101
  // Software Guide : EndCodeSnippet

  //  Software Guide : BeginLatex
102
  //
103
  // An \doxygen{otb}{ImageFileWriter} is instantiated in order to write the
Jordi Inglada's avatar
Jordi Inglada committed
104 105
  // output image to a file.
  //
106
  //  Software Guide : EndLatex
Jordi Inglada's avatar
Jordi Inglada committed
107 108

  // Software Guide : BeginCodeSnippet
OTB Bot's avatar
OTB Bot committed
109
  typedef otb::ImageFileWriter<OutputImageType> WriterType;
Jordi Inglada's avatar
Jordi Inglada committed
110 111 112
  // Software Guide : EndCodeSnippet

  //  Software Guide : BeginLatex
113
  //
Jordi Inglada's avatar
Jordi Inglada committed
114 115 116 117
  // The intensity rescaling of the results will be carried out by the
  // \code{itk::RescaleIntensityImageFilter} which is templated by the
  // input and output image types.
  //
118
  //  Software Guide : EndLatex
Jordi Inglada's avatar
Jordi Inglada committed
119 120

  // Software Guide : BeginCodeSnippet
OTB Bot's avatar
OTB Bot committed
121
  typedef itk::RescaleIntensityImageFilter<InternalImageType,
OTB Bot's avatar
OTB Bot committed
122
      OutputImageType> RescalerType;
Jordi Inglada's avatar
Jordi Inglada committed
123 124 125 126 127 128 129
  // Software Guide : EndCodeSnippet

  //  Software Guide : BeginLatex
  //
  //  Both the filter and the reader are created by invoking their \code{New()}
  //  methods and assigning the result to SmartPointers.
  //
130
  //  Software Guide : EndLatex
Jordi Inglada's avatar
Jordi Inglada committed
131 132 133 134 135 136 137 138 139

  // Software Guide : BeginCodeSnippet
  ReaderType::Pointer reader = ReaderType::New();
  FilterType::Pointer filter = FilterType::New();
  // Software Guide : EndCodeSnippet

  //  Software Guide : BeginLatex
  //
  //  The same is done for the rescaler and the writer.
140 141
  //
  //  Software Guide : EndLatex
Jordi Inglada's avatar
Jordi Inglada committed
142

143
  // Software Guide : BeginCodeSnippet
Jordi Inglada's avatar
Jordi Inglada committed
144
  RescalerType::Pointer rescaler = RescalerType::New();
OTB Bot's avatar
OTB Bot committed
145
  WriterType::Pointer   writer = WriterType::New();
Jordi Inglada's avatar
Jordi Inglada committed
146 147
  // Software Guide : EndCodeSnippet

OTB Bot's avatar
OTB Bot committed
148
  reader->SetFileName(argv[1]);
Jordi Inglada's avatar
Jordi Inglada committed
149 150 151 152 153 154 155 156

  //  Software Guide : BeginLatex
  //
  //  The \code{itk::RescaleIntensityImageFilter} needs to know which
  //  is the minimu and maximum values of the output generated
  //  image. Those can be chosen in a generic way by using the
  //  \code{NumericTraits} functions, since they are templated over
  //  the pixel type.
157 158
  //
  //  Software Guide : EndLatex
Jordi Inglada's avatar
Jordi Inglada committed
159

160
  // Software Guide : BeginCodeSnippet
OTB Bot's avatar
OTB Bot committed
161 162
  rescaler->SetOutputMinimum(itk::NumericTraits<OutputPixelType>::min());
  rescaler->SetOutputMaximum(itk::NumericTraits<OutputPixelType>::max());
Jordi Inglada's avatar
Jordi Inglada committed
163 164 165
  // Software Guide : EndCodeSnippet

  //  Software Guide : BeginLatex
166
  //
Jordi Inglada's avatar
Jordi Inglada committed
167
  //  The image obtained with the reader is passed as input to the
168
  //  \doxygen{otb}{AssymetricFusionOfDetectorImageFilter}. The pipeline is built as follows.
Jordi Inglada's avatar
Jordi Inglada committed
169 170 171
  //
  //  \index{otb::AssymetricFusionOfDetectorImageFilter!SetInput()}
  //
172
  //  Software Guide : EndLatex
Jordi Inglada's avatar
Jordi Inglada committed
173 174

  // Software Guide : BeginCodeSnippet
OTB Bot's avatar
OTB Bot committed
175 176 177
  filter->SetInput(reader->GetOutput());
  rescaler->SetInput(filter->GetOutput());
  writer->SetInput(rescaler->GetOutput());
Jordi Inglada's avatar
Jordi Inglada committed
178 179 180
  // Software Guide : EndCodeSnippet

  //  Software Guide : BeginLatex
181
  //
Jordi Inglada's avatar
Jordi Inglada committed
182
  //  The methods \code{SetLengthLine()} and \code{SetWidthLine()}
183
  //  allow setting the minimum length and the typical witdh of the
Jordi Inglada's avatar
Jordi Inglada committed
184 185 186
  //  lines which are to be detected.
  //
  //  \index{otb::AssymetricFusionOfDetector!SetWidthLine()}
187
  //  \index{otb::AssymetricFusionOfDetector!SetLengthLine()}
Jordi Inglada's avatar
Jordi Inglada committed
188
  //
189
  //  Software Guide : EndLatex
Jordi Inglada's avatar
Jordi Inglada committed
190 191

  // Software Guide : BeginCodeSnippet
OTB Bot's avatar
OTB Bot committed
192 193
  filter->SetLengthLine(atoi(argv[3]));
  filter->SetWidthLine(atoi(argv[4]));
Jordi Inglada's avatar
Jordi Inglada committed
194 195 196
  // Software Guide : EndCodeSnippet

  //  Software Guide : BeginLatex
197
  //
Jordi Inglada's avatar
Jordi Inglada committed
198 199 200 201 202
  //  The filter is executed by invoking the \code{Update()} method. If the
  //  filter is part of a larger image processing pipeline, calling
  //  \code{Update()} on a downstream filter will also trigger update of this
  //  filter.
  //
203
  //  Software Guide : EndLatex
Jordi Inglada's avatar
Jordi Inglada committed
204 205 206 207 208

  // Software Guide : BeginCodeSnippet
  filter->Update();
  // Software Guide : EndCodeSnippet

OTB Bot's avatar
OTB Bot committed
209
  writer->SetFileName(argv[2]);
Jordi Inglada's avatar
Jordi Inglada committed
210 211
  writer->Update();

Jordi Inglada's avatar
Jordi Inglada committed
212
  //  Software Guide : BeginLatex
213
  // Figure~\ref{fig:LINEFUSION_FILTER}
Jordi Inglada's avatar
Jordi Inglada committed
214 215 216 217 218
  // shows the result of applying the AssymetricFusionOf edge detector filter
  // to a SAR image.  \begin{figure} \center
  // \includegraphics[width=0.25\textwidth]{amst.eps}
  // \includegraphics[width=0.25\textwidth]{amstLineFusion.eps}
  // \itkcaption[Line Correlation Detector Application]{Result of applying
219
  // the \doxygen{otb}{AssymetricFusionOfDetectorImageFilter} to a SAR
220
  // image. From left to right : original image, line intensity.}  \label{fig:LINEFUSION_FILTER} \end{figure}
Jordi Inglada's avatar
Jordi Inglada committed
221
  //
222
  //  Software Guide : EndLatex
Jordi Inglada's avatar
Jordi Inglada committed
223 224 225

  return EXIT_SUCCESS;
}