ScalingPipeline.cxx 4.5 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 24
//  Software Guide : BeginCommandLineArgs
//    INPUTS: {QB_Suburb.png}
//    OUTPUTS: {TutorialsScalingPipelineOutput.png}
//  Software Guide : EndCommandLineArgs


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

// Software Guide : BeginCodeSnippet
#include "otbImage.h"
#include "otbImageFileReader.h"
#include "otbStreamingImageFileWriter.h"
#include "itkCannyEdgeDetectionImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"

44
int main( int argc, char * argv[] )
45 46
{
// Software Guide : EndCodeSnippet
47

48 49
  //  Software Guide : BeginLatex
  //
50
  //  We need to declare two different image types, one for the internal
51 52
  // processing and one to output the results:
  //
53 54
  //  Software Guide : EndLatex

55 56 57 58 59 60 61
  // Software Guide : BeginCodeSnippet
  typedef double PixelType;
  typedef otb::Image<PixelType, 2> ImageType;

  typedef unsigned char OutputPixelType;
  typedef otb::Image<OutputPixelType, 2> OutputImageType;
  // Software Guide : EndCodeSnippet
62

63 64 65 66 67 68 69 70 71 72
  //  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).
  //
73 74 75
  //  Software Guide : EndLatex


76 77 78 79 80 81 82 83 84 85
  // Software Guide : BeginCodeSnippet
  typedef otb::ImageFileReader<ImageType> ReaderType;
  ReaderType::Pointer reader=ReaderType::New();

  typedef otb::StreamingImageFileWriter<OutputImageType> WriterType;
  WriterType::Pointer writer=WriterType::New();

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

87 88
  //  Software Guide : BeginLatex
  //
89
  // Now we are declaring the edge detection filter which is going to work with
90 91
  // double input and output.
  //
92 93
  //  Software Guide : EndLatex

94
  // Software Guide : BeginCodeSnippet
95
  typedef itk::CannyEdgeDetectionImageFilter
96
  <ImageType,ImageType> FilterType;
97 98
  FilterType::Pointer filter = FilterType::New();
  // Software Guide : EndCodeSnippet
99

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

117 118
  // Software Guide : BeginCodeSnippet
  typedef itk::RescaleIntensityImageFilter
119
  <ImageType,OutputImageType> RescalerType;
120
  RescalerType::Pointer rescaler = RescalerType::New();
121

122 123
  rescaler->SetOutputMinimum(0);
  rescaler->SetOutputMaximum(255);
124
  // Software Guide : EndCodeSnippet
125 126


127 128 129 130
  //  Software Guide : BeginLatex
  //
  // Let's plug the pipeline:
  //
131 132
  //  Software Guide : EndLatex

133 134 135 136 137
  // Software Guide : BeginCodeSnippet
  filter->SetInput(reader->GetOutput());
  rescaler->SetInput(filter->GetOutput());
  writer->SetInput(rescaler->GetOutput());
  // Software Guide : EndCodeSnippet
138

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

146 147 148
  // Software Guide : BeginCodeSnippet
  writer->Update();

149
  return EXIT_SUCCESS;
150 151 152 153
}
// Software Guide : EndCodeSnippet