ScalingPipeline.cxx 4.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++


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


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

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

17 18 19 20 21
//  Software Guide : BeginCommandLineArgs
//    INPUTS: {QB_Suburb.png}
//    OUTPUTS: {TutorialsScalingPipelineOutput.png}
//  Software Guide : EndCommandLineArgs

22 23
//  Software Guide : BeginLatex
//
24
//  This example illustrates the use of the
25 26 27
// \doxygen{itk}{RescaleIntensityImageFilter} to convert
// the result for proper display.
//
28
// We include the required header including the header
29
// for the \doxygen{itk}{CannyEdgeDetectionImageFilter} and the
30 31
// \doxygen{itk}{RescaleIntensityImageFilter}.
//
32
//  Software Guide : EndLatex
33 34 35 36

// Software Guide : BeginCodeSnippet
#include "otbImage.h"
#include "otbImageFileReader.h"
37
#include "otbImageFileWriter.h"
38
#include "itkUnaryFunctorImageFilter.h"
39 40 41
#include "itkCannyEdgeDetectionImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"

OTB Bot's avatar
STYLE  
OTB Bot committed
42
int main(int argc, char * argv[])
43
{
44 45 46 47 48 49 50
  if (argc != 3)
    {
    std::cerr << "Usage: "
        << argv[0]
        << " <input_filename> <output_filename>"
        << std::endl;
    }
51
// Software Guide : EndCodeSnippet
52

53 54
  //  Software Guide : BeginLatex
  //
55
  //  We need to declare two different image types, one for the internal
56 57
  // processing and one to output the results:
  //
58 59
  //  Software Guide : EndLatex

60
  // Software Guide : BeginCodeSnippet
OTB Bot's avatar
STYLE  
OTB Bot committed
61
  typedef double                   PixelType;
62 63
  typedef otb::Image<PixelType, 2> ImageType;

OTB Bot's avatar
STYLE  
OTB Bot committed
64
  typedef unsigned char                  OutputPixelType;
65 66
  typedef otb::Image<OutputPixelType, 2> OutputImageType;
  // Software Guide : EndCodeSnippet
67

68 69 70
  //  Software Guide : BeginLatex
  //
  //  We declare the reader with the image template using the pixel type
71
  // double. It is worth noticing that this instantiation does not imply
72 73 74 75 76 77
  // anything about the type of the input image. The original image can be
  // anything, the reader will just convert the result to double.
  //
  //  The writer is templated with the unsigned char image to be able to save
  // the result on one byte images (like png for example).
  //
78 79
  //  Software Guide : EndLatex

80 81
  // Software Guide : BeginCodeSnippet
  typedef otb::ImageFileReader<ImageType> ReaderType;
OTB Bot's avatar
STYLE  
OTB Bot committed
82
  ReaderType::Pointer reader = ReaderType::New();
83

84
  typedef otb::ImageFileWriter<OutputImageType> WriterType;
OTB Bot's avatar
STYLE  
OTB Bot committed
85
  WriterType::Pointer writer = WriterType::New();
86 87 88 89

  reader->SetFileName(argv[1]);
  writer->SetFileName(argv[2]);
  // Software Guide : EndCodeSnippet
90

91 92
  //  Software Guide : BeginLatex
  //
93
  // Now we are declaring the edge detection filter which is going to work with
94 95
  // double input and output.
  //
96 97
  //  Software Guide : EndLatex

98
  // Software Guide : BeginCodeSnippet
99
  typedef itk::CannyEdgeDetectionImageFilter
OTB Bot's avatar
STYLE  
OTB Bot committed
100
  <ImageType, ImageType> FilterType;
101 102
  FilterType::Pointer filter = FilterType::New();
  // Software Guide : EndCodeSnippet
103

104 105
  //  Software Guide : BeginLatex
  //
106
  // Here comes the interesting part: we declare the
107
  // \doxygen{itk}{RescaleIntensityImageFilter}. The input
108 109 110
  // image type is the output type of the edge detection
  // filter. The output type is the same as the input type
  // of the writer.
111 112
  //
  // Desired minimum and maximum values for the output are
113
  // specified by the methods \code{SetOutputMinimum()} and
114 115
  // \code{SetOutputMaximum()}.
  //
116
  // This filter will actually rescale all the pixels of
117 118
  // the image but also cast the type of these pixels.
  //
119 120
  //  Software Guide : EndLatex

121 122
  // Software Guide : BeginCodeSnippet
  typedef itk::RescaleIntensityImageFilter
OTB Bot's avatar
STYLE  
OTB Bot committed
123
  <ImageType, OutputImageType> RescalerType;
124
  RescalerType::Pointer rescaler = RescalerType::New();
125

126 127
  rescaler->SetOutputMinimum(0);
  rescaler->SetOutputMaximum(255);
128
  // Software Guide : EndCodeSnippet
129

130 131 132 133
  //  Software Guide : BeginLatex
  //
  // Let's plug the pipeline:
  //
134 135
  //  Software Guide : EndLatex

136 137 138 139 140
  // Software Guide : BeginCodeSnippet
  filter->SetInput(reader->GetOutput());
  rescaler->SetInput(filter->GetOutput());
  writer->SetInput(rescaler->GetOutput());
  // Software Guide : EndCodeSnippet
141

142 143 144 145 146
  //  Software Guide : BeginLatex
  //
  // And finally, we trigger the pipeline execution calling the Update()
  // method on the writer
  //
147 148
  //  Software Guide : EndLatex

149 150 151
  // Software Guide : BeginCodeSnippet
  writer->Update();

152
  return EXIT_SUCCESS;
153 154
}
// Software Guide : EndCodeSnippet