Orfeo Toolbox  3.16
ComplexImageReadWrite.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  Some parts of this code are derived from ITK. See ITKCopyright.txt
13  for details.
14 
15 
16  This software is distributed WITHOUT ANY WARRANTY; without even
17  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18  PURPOSE. See the above copyright notices for more information.
19 
20 =========================================================================*/
21 
22 
23 // Software Guide : BeginLatex
24 //
25 // This example illustrates how to read and write an image of pixel type
26 // \code{std::complex}. The complex type is defined as an integral part of the
27 // C++ language.
28 //
29 // We start by including the headers of the complex class, the image, and the
30 // reader and writer classes.
31 //
32 // \index{otb::ImageFileRead!Complex images}
33 // \index{otb::ImageFileWrite!Complex images}
34 // \index{Complex images!Instantiation}
35 // \index{Complex images!Reading}
36 // \index{Complex images!Writing}
37 //
38 // Software Guide : EndLatex
39 
40 // Software Guide : BeginCodeSnippet
41 #include <complex>
42 #include "otbImage.h"
43 #include "otbImageFileReader.h"
44 #include "otbImageFileWriter.h"
45 // Software Guide : EndCodeSnippet
46 
47 int main(int argc, char * argv[])
48 {
49 
50  // Verify the number of parameters in the command line
51  if (argc < 3)
52  {
53  std::cerr << "Usage: " << std::endl;
54  std::cerr << argv[0] << " inputImageFile outputImageFile " << std::endl;
55  return EXIT_FAILURE;
56  }
57 
58 // Software Guide : BeginLatex
59 //
60 // The image dimension and pixel type must be declared. In this case we use the
61 // \code{std::complex<>} as the pixel type. Using the dimension and pixel type
62 // we proceed to instantiate the image type.
63 //
64 // Software Guide : EndLatex
65 
66 // Software Guide : BeginCodeSnippet
67  const unsigned int Dimension = 2;
68 
69  typedef std::complex<float> PixelType;
70  typedef otb::Image<PixelType, Dimension> ImageType;
71 // Software Guide : EndCodeSnippet
72 
73 // Software Guide : BeginLatex
74 //
75 // The image file reader and writer types are instantiated using the image
76 // type. We can then create objects for both of them.
77 //
78 // Software Guide : EndLatex
79 
80 // Software Guide : BeginCodeSnippet
81  typedef otb::ImageFileReader<ImageType> ReaderType;
82  typedef otb::ImageFileWriter<ImageType> WriterType;
83 
84  ReaderType::Pointer reader = ReaderType::New();
85  WriterType::Pointer writer = WriterType::New();
86 // Software Guide : EndCodeSnippet
87 
88 // Software Guide : BeginLatex
89 //
90 // Filenames should be provided for both the reader and the writer. In this
91 // particular example we take those filenames from the command line arguments.
92 //
93 // Software Guide : EndLatex
94 
95 // Software Guide : BeginCodeSnippet
96  reader->SetFileName(argv[1]);
97  writer->SetFileName(argv[2]);
98 // Software Guide : EndCodeSnippet
99 
100 // Software Guide : BeginLatex
101 //
102 // Here we simply connect the output of the reader as input to the writer.
103 // This simple program could be used for converting complex images from one
104 // fileformat to another.
105 //
106 // Software Guide : EndLatex
107 
108 // Software Guide : BeginCodeSnippet
109  writer->SetInput(reader->GetOutput());
110 // Software Guide : EndCodeSnippet
111 
112 // Software Guide : BeginLatex
113 //
114 // The execution of this short pipeline is triggered by invoking the Update()
115 // method of the writer. This invocation must be placed inside a try/catch
116 // block since its execution may result in exceptions being thrown.
117 //
118 // Software Guide : EndLatex
119 
120 // Software Guide : BeginCodeSnippet
121  try
122  {
123  writer->Update();
124  }
125  catch (itk::ExceptionObject& err)
126  {
127  std::cerr << "ExceptionObject caught !" << std::endl;
128  std::cerr << err << std::endl;
129  return EXIT_FAILURE;
130  }
131 // Software Guide : EndCodeSnippet
132 
133 // Software Guide : BeginLatex
134 //
135 // For a more interesting use of this code, you may want to add a filter in
136 // between the reader and the writer and perform any complex image to complex
137 // image operation.
138 //
139 // Software Guide : EndLatex
140 
141  return EXIT_SUCCESS;
142 }

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