File: PrintableImageFilterExample.cxx

package info (click to toggle)
otb 5.8.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 38,496 kB
  • ctags: 40,282
  • sloc: cpp: 306,573; ansic: 3,575; python: 450; sh: 214; perl: 74; java: 72; makefile: 70
file content (142 lines) | stat: -rw-r--r-- 5,365 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


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


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/


//  Software Guide : BeginCommandLineArgs
//    INPUTS: {IMAGERY_SSECH.tif}
//    OUTPUTS: {PrintableExampleOutput1.jpg}
//    1 2 3
//  Software Guide : EndCommandLineArgs

//  Software Guide : BeginCommandLineArgs
//    INPUTS: {IMAGERY_SSECH.tif}
//    OUTPUTS: {PrintableExampleOutput2.jpg}
//    1 4 2
//  Software Guide : EndCommandLineArgs

//  Software Guide : BeginLatex
//
//  Most of the time, satellite images have more than three spectral bands. As we
// are only able to see three colors (red, green and blue), we have to find a way to
// represent these images using only three bands. This is called creating a color
// composition.
//
// Of course, any color composition will not be able to render all the information
// available in the original image. As a consequence, sometimes, creating more than
// one color composition will be necessary.
//
// If you want to obtain an image with natural colors, you have to match the wavelength
// captured by the satellite with those captured by your eye: thus matching the red band
// with the red color, etc.
//
// Some satellites (SPOT 5 is an example) do not acquire all the {\em human} spectral bands:
// the blue can be missing and replaced by some other wavelength of interest for a specific application.
// In these situations, another mapping has to be created. That's why, the vegetation often appears in
// red in satellite images (see on left of figure~\ref{fig:PRINTABLE_FILTER}).
//
// The band order in the image products can be also quite tricky. It could be in the wavelength order,
// as it is the case for Quickbird (1: Blue, 2: Green, 3: Red, 4: NIR), in this case, you
// have to be careful to reverse the order if you want a natural display. It could also be reverse
// to facilitate direct viewing, as for SPOT5 (1: NIR, 2: Red, 3: Green, 4: SWIR) but in this situations
// you have to be careful when you process the image.
//
//  Software Guide : EndLatex

#include "otbVectorImage.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "otbPrintableImageFilter.h"

int main(int argc, char * argv[])
{

  if (argc != 6)
    {
    std::cerr << "Usage: " << argv[0] << " <inputImageFile> ";
    std::cerr << " <outputImageFile> <RedBand> <GreenBand> <BlueBand>" <<
    std::endl;
    return EXIT_FAILURE;
    }

  const char * inputFilename  = argv[1];
  const char * outputFilename = argv[2];
  int          redChannelNumber = atoi(argv[3]);
  int          greenChannelNumber = atoi(argv[4]);
  int          blueChannelNumber = atoi(argv[5]);

  typedef double InputPixelType;
  const unsigned int Dimension = 2;

  typedef otb::VectorImage<InputPixelType, Dimension> InputImageType;

  typedef otb::ImageFileReader<InputImageType> ReaderType;

  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(inputFilename);

  //  Software Guide : BeginLatex
  //
  //  To easily convert the image to a {\em printable} format, i.e. 3 bands
  // \code{unsigned char} value, you can use the \doxygen{otb}{PrintableImageFilter}.
  //
  //  Software Guide : EndLatex

  // Software Guide : BeginCodeSnippet
  typedef otb::PrintableImageFilter<InputImageType> PrintableFilterType;
  PrintableFilterType::Pointer printableImageFilter = PrintableFilterType::New();

  printableImageFilter->SetInput(reader->GetOutput());
  printableImageFilter->SetChannel(redChannelNumber);
  printableImageFilter->SetChannel(greenChannelNumber);
  printableImageFilter->SetChannel(blueChannelNumber);
  // Software Guide : EndCodeSnippet

  //  Software Guide : BeginLatex
  //
  //  When you create the writer to plug at the output of the \code{printableImageFilter}
  // you may want to use the direct type definition as it is a good way to avoid mismatch:
  //
  //  Software Guide : EndLatex

  // Software Guide : BeginCodeSnippet
  typedef PrintableFilterType::OutputImageType           OutputImageType;
  typedef otb::ImageFileWriter<OutputImageType> WriterType;
  // Software Guide : EndCodeSnippet

  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(outputFilename);
  writer->SetInput(printableImageFilter->GetOutput());

  writer->Update();

  //  Software Guide : BeginLatex
  // Figure~\ref{fig:PRINTABLE_FILTER} illustrates different color compositions for a SPOT 5 image.
  // \begin{figure}
  // \center
  // \includegraphics[width=0.44\textwidth]{PrintableExampleOutput1.eps}
  // \includegraphics[width=0.44\textwidth]{PrintableExampleOutput2.eps}
  // \itkcaption[Scaling images]{On the left, a classic SPOT5
  // combination: XS3 in red, XS2 in green and XS1 in blue. On the
  // right another composition: XS3 in red, XS4 in green and XS2 in blue.}
  // \label{fig:PRINTABLE_FILTER}
  // \end{figure}
  //
  //  Software Guide : EndLatex

  return EXIT_SUCCESS;
}