Orfeo Toolbox  3.16
ComplexMomentsImageFunctionExample.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 #include "itkMacro.h"
21 #include "otbImage.h"
22 
23 #include "otbImageFileReader.h"
24 
25 // Software Guide : BeginCommandLineArgs
26 // INPUTS: {ROISpot5.png}
27 // 2 2
28 // Software Guide : EndCommandLineArgs
29 
30 // Software Guide : BeginLatex
31 //
32 // This example illustrates the use of the \doxygen{otb}{ComplexMomentsImageFunction}.
33 //
34 // The first step required to use this filter is to include its header file.
35 //
36 // Software Guide : EndLatex
37 
38 // Software Guide : BeginCodeSnippet
40 // Software Guide : EndCodeSnippet
41 
42 int main(int argc, char * argv[])
43 {
44  if (argc != 4)
45  {
46  std::cerr << "Usage: " << argv[0] << " inputImageFile ";
47  std::cerr << " p q" << std::endl;
48  return EXIT_FAILURE;
49  }
50 
51  const char * inputFilename = argv[1];
52 
53  unsigned int P((unsigned char) ::atoi(argv[2]));
54  unsigned int Q((unsigned char) ::atoi(argv[3]));
55 
56  typedef unsigned char InputPixelType;
57  const unsigned int Dimension = 2;
58  typedef otb::Image<InputPixelType, Dimension> InputImageType;
59 
60  typedef otb::ImageFileReader<InputImageType> ReaderType;
61 
62  ReaderType::Pointer reader = ReaderType::New();
63 
64  reader->SetFileName(inputFilename);
65 
66  // Software Guide : BeginLatex
67  //
68  // The \doxygen{otb}{ComplexMomentImageFunction} is templated over the
69  // input image type and the output complex type value, so we start by
70  // defining:
71  //
72  // Software Guide : EndLatex
73 
74  // Software Guide : BeginCodeSnippet
76  typedef CMType::OutputType OutputType;
77 
78  CMType::Pointer cmFunction = CMType::New();
79  // Software Guide : EndCodeSnippet
80 
81  // Software Guide : BeginLatex
82  //
83  // Next, we plug the input image into the complex moment fucntion
84  // and we set its parameters.
85  //
86  // Software Guide : EndLatex
87 
88  // Software Guide : BeginCodeSnippet
89  reader->Update();
90  cmFunction->SetInputImage(reader->GetOutput());
91  cmFunction->SetQmax(Q);
92  cmFunction->SetPmax(P);
93  // Software Guide : EndCodeSnippet
94 
95  // Software Guide : BeginLatex
96  // We can chose the pixel of the image which will used as center
97  // for the moment computation
98  //
99  // Software Guide : EndLatex
100 
101  // Software Guide : BeginCodeSnippet
102  InputImageType::IndexType center;
103  center[0] = 50;
104  center[1] = 50;
105  // Software Guide : EndCodeSnippet
106 
107  // Software Guide : BeginLatex
108  // We can also choose the size of the neighborhood around the
109  // center pixel for the moment computation.
110  //
111  // Software Guide : EndLatex
112 
113  cmFunction->SetNeighborhoodRadius(15);
114 
115  // Software Guide : BeginLatex
116  // In order to get the value of the moment, we call the
117  // \code{EvaluateAtIndex} method.
118  //
119  // Software Guide : EndLatex
120 
121  // Software Guide : BeginCodeSnippet
122  OutputType Result = cmFunction->EvaluateAtIndex(center);
123 
124  std::cout << "The moment of order (" << P << "," << Q <<
125  ") is equal to " << Result.at(P).at(Q) << std::endl;
126  // Software Guide : EndCodeSnippet
127 
128  return EXIT_SUCCESS;
129 }

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