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

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


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


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

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

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

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

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

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

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

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

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

70 71 72 73 74 75 76 77 78 79
  //  Software Guide : BeginLatex
  //
  //  We declare the reader with the image template using the pixel type
  // double. It is worth noticing that this instanciation does not imply
  // 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).
  //
80 81
  //  Software Guide : EndLatex

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

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

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

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

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

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

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

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

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

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

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

151 152 153
  // Software Guide : BeginCodeSnippet
  writer->Update();

154
  return EXIT_SUCCESS;
155 156
}
// Software Guide : EndCodeSnippet