ScalingPipeline.cxx 4.38 KB
Newer Older
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 143 144 145 146 147
/*=========================================================================

  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 : BeginLatex
//
//  This example illustrates the use of the 
// \doxygen{itk}{RescaleIntensityImageFilter} to convert
// the result for proper display.
//
// We include the required header including the header 
// for the \doxygen{itk}{CannyEdgeImageFilter} and the 
// \doxygen{itk}{RescaleIntensityImageFilter}.
//
//  Software Guide : EndLatex 

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

int main(int argc, char ** argv)
{
// Software Guide : EndCodeSnippet
  
  //  Software Guide : BeginLatex
  //
  //  We need to declare two different image types, one for the internal 
  // processing and one to output the results:
  //
  //  Software Guide : EndLatex 
  
  // 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
  
  //  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).
  //
  //  Software Guide : EndLatex 
  
  
  // 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
  
  //  Software Guide : BeginLatex
  //
  // Now we are declaring the edge detection filter which is going to work with 
  // double input and output.
  //
  //  Software Guide : EndLatex 
  
   // Software Guide : BeginCodeSnippet
  typedef itk::CannyEdgeDetectionImageFilter
      <ImageType,ImageType> FilterType;
  FilterType::Pointer filter = FilterType::New();
  // Software Guide : EndCodeSnippet
  
  //  Software Guide : BeginLatex
  //
  // Here comes the interesting part: we declare the 
  // \doxygen{itk}{RescaleIntensityImageFilter}. The input
  // image type is the output type of the edge detection 
  // filter. The output type is the same as the input type 
  // of the writer. 
  //
  // Desired minimum and maximum values for the output are
  // specified by the methods \code{SetOutputMinimum()} and 
  // \code{SetOutputMaximum()}.
  //
  // This filter will actually rescale all the pixels of 
  // the image but also cast the type of these pixels.
  //
  //  Software Guide : EndLatex 
  
  // Software Guide : BeginCodeSnippet
  typedef itk::RescaleIntensityImageFilter
      <ImageType,OutputImageType> RescalerType;
  RescalerType::Pointer rescaler = RescalerType::New();
  
  rescaler->SetOutputMinimum(0);
  rescaler->SetOutputMaximum(255);
   // Software Guide : EndCodeSnippet
  
  
  //  Software Guide : BeginLatex
  //
  // Let's plug the pipeline:
  //
  //  Software Guide : EndLatex 
  
  // Software Guide : BeginCodeSnippet
  filter->SetInput(reader->GetOutput());
  rescaler->SetInput(filter->GetOutput());
  writer->SetInput(rescaler->GetOutput());
  // Software Guide : EndCodeSnippet
  
  //  Software Guide : BeginLatex
  //
  // And finally, we trigger the pipeline execution calling the Update()
  // method on the writer
  //
  //  Software Guide : EndLatex 
  
  // Software Guide : BeginCodeSnippet
  writer->Update();

  return 0; 
}
// Software Guide : EndCodeSnippet