ScalingPipeline.cxx 4.85 KB
Newer Older
1
/*
Julien Michel's avatar
Julien Michel committed
2
 * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
20 21


22 23 24 25 26
//  Software Guide : BeginCommandLineArgs
//    INPUTS: {QB_Suburb.png}
//    OUTPUTS: {TutorialsScalingPipelineOutput.png}
//  Software Guide : EndCommandLineArgs

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

// Software Guide : BeginCodeSnippet
#include "otbImage.h"
#include "otbImageFileReader.h"
42
#include "otbImageFileWriter.h"
43
#include "itkUnaryFunctorImageFilter.h"
44 45 46
#include "itkCannyEdgeDetectionImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"

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

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

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

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

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

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

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

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

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

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

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

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

131 132
  rescaler->SetOutputMinimum(0);
  rescaler->SetOutputMaximum(255);
133
  // Software Guide : EndCodeSnippet
134

135 136 137 138
  //  Software Guide : BeginLatex
  //
  // Let's plug the pipeline:
  //
139 140
  //  Software Guide : EndLatex

141 142 143 144 145
  // Software Guide : BeginCodeSnippet
  filter->SetInput(reader->GetOutput());
  rescaler->SetInput(filter->GetOutput());
  writer->SetInput(rescaler->GetOutput());
  // Software Guide : EndCodeSnippet
146

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

154 155 156
  // Software Guide : BeginCodeSnippet
  writer->Update();

157
  return EXIT_SUCCESS;
158 159
}
// Software Guide : EndCodeSnippet