Orfeo Toolbox  3.16
SecondDerivativeRecursiveGaussianImageFilter.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 : BeginLatex
21 //
22 // This example illustrates how to compute second derivatives of
23 // an image using the \doxygen{itk}{RecursiveGaussianImageFilter}.
24 //
25 // In this example, all the second derivatives are computed independently in
26 // the same way as if they were intended to be used for building the Hessian
27 // matrix of the image.
28 //
29 // Software Guide : EndLatex
30 
31 // Software Guide : BeginCodeSnippet
33 #include "otbImageFileReader.h"
34 #include "otbImageFileWriter.h"
35 #include "itkImageDuplicator.h"
36 #include "otbImage.h"
37 #include <string>
38 
39 int main(int argc, char * argv[])
40 {
41 
42  if (argc < 3)
43  {
44  std::cerr << "Usage: " << std::endl;
45  std::cerr << argv[0] << " inputImage outputPrefix [sigma] " << std::endl;
46  return EXIT_FAILURE;
47  }
48 
49  typedef float PixelType;
50  typedef float OutputPixelType;
51 
52  const unsigned int Dimension = 2;
53 
54  typedef otb::Image<PixelType, Dimension> ImageType;
55  typedef otb::Image<OutputPixelType, Dimension> OutputImageType;
56 
57  typedef otb::ImageFileReader<ImageType> ReaderType;
58  typedef otb::ImageFileWriter<OutputImageType> WriterType;
59 
60  typedef itk::ImageDuplicator<OutputImageType> DuplicatorType;
61 
63  ImageType,
64  ImageType> FilterType;
65 
66  ReaderType::Pointer reader = ReaderType::New();
67  WriterType::Pointer writer = WriterType::New();
68 
69  DuplicatorType::Pointer duplicator = DuplicatorType::New();
70 
71  reader->SetFileName(argv[1]);
72 
73  std::string outputPrefix = argv[2];
74  std::string outputFileName;
75 
76  try
77  {
78  reader->Update();
79  }
80  catch (itk::ExceptionObject& excp)
81  {
82  std::cerr << "Problem reading the input file" << std::endl;
83  std::cerr << excp << std::endl;
84  return EXIT_FAILURE;
85  }
86 
90 
91  ga->SetDirection(0);
92  gb->SetDirection(1);
93  gc->SetDirection(2);
94 
95  if (argc > 3)
96  {
97  const float sigma = atof(argv[3]);
98  ga->SetSigma(sigma);
99  gb->SetSigma(sigma);
100  gc->SetSigma(sigma);
101  }
102 
103  ga->SetZeroOrder();
104  gb->SetZeroOrder();
105  gc->SetSecondOrder();
106 
107  ImageType::Pointer inputImage = reader->GetOutput();
108 
109  ga->SetInput(inputImage);
110  gb->SetInput(ga->GetOutput());
111  gc->SetInput(gb->GetOutput());
112 
113  duplicator->SetInputImage(gc->GetOutput());
114 
115  gc->Update();
116  duplicator->Update();
117 
118  ImageType::Pointer Izz = duplicator->GetOutput();
119 
120  writer->SetInput(Izz);
121  outputFileName = outputPrefix + "-Izz.hdr";
122  writer->SetFileName(outputFileName.c_str());
123  writer->Update();
124 
125  gc->SetDirection(1); // gc now works along Y
126  gb->SetDirection(2); // gb now works along Z
127 
128  gc->Update();
129  duplicator->Update();
130 
131  ImageType::Pointer Iyy = duplicator->GetOutput();
132 
133  writer->SetInput(Iyy);
134  outputFileName = outputPrefix + "-Iyy.hdr";
135  writer->SetFileName(outputFileName.c_str());
136  writer->Update();
137 
138  gc->SetDirection(0); // gc now works along X
139  ga->SetDirection(1); // ga now works along Y
140 
141  gc->Update();
142  duplicator->Update();
143 
144  ImageType::Pointer Ixx = duplicator->GetOutput();
145 
146  writer->SetInput(Ixx);
147  outputFileName = outputPrefix + "-Ixx.hdr";
148  writer->SetFileName(outputFileName.c_str());
149  writer->Update();
150 
151  ga->SetDirection(0);
152  gb->SetDirection(1);
153  gc->SetDirection(2);
154 
155  ga->SetZeroOrder();
156  gb->SetFirstOrder();
157  gc->SetFirstOrder();
158 
159  gc->Update();
160  duplicator->Update();
161 
162  ImageType::Pointer Iyz = duplicator->GetOutput();
163 
164  writer->SetInput(Iyz);
165  outputFileName = outputPrefix + "-Iyz.hdr";
166  writer->SetFileName(outputFileName.c_str());
167  writer->Update();
168 
169  ga->SetDirection(1);
170  gb->SetDirection(0);
171  gc->SetDirection(2);
172 
173  ga->SetZeroOrder();
174  gb->SetFirstOrder();
175  gc->SetFirstOrder();
176 
177  gc->Update();
178  duplicator->Update();
179 
180  ImageType::Pointer Ixz = duplicator->GetOutput();
181 
182  writer->SetInput(Ixz);
183  outputFileName = outputPrefix + "-Ixz.hdr";
184  writer->SetFileName(outputFileName.c_str());
185  writer->Update();
186 
187  ga->SetDirection(2);
188  gb->SetDirection(0);
189  gc->SetDirection(1);
190 
191  ga->SetZeroOrder();
192  gb->SetFirstOrder();
193  gc->SetFirstOrder();
194 
195  gc->Update();
196  duplicator->Update();
197 
198  ImageType::Pointer Ixy = duplicator->GetOutput();
199 
200  writer->SetInput(Ixy);
201  outputFileName = outputPrefix + "-Ixy.hdr";
202  writer->SetFileName(outputFileName.c_str());
203  writer->Update();
204  // Software Guide : EndCodeSnippet
205 
206  return EXIT_SUCCESS;
207 }

Generated at Sun Feb 3 2013 00:59:33 for Orfeo Toolbox with doxygen 1.8.1.1