otbReciprocalHAlphaImageFilter.cxx 3.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
 *
 * 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
#include "itkMacro.h"
24 25 26 27 28

#include "otbImage.h"
#include "otbVectorImage.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
29 30 31
#include "itkMeanImageFilter.h"
#include "otbPerBandVectorImageFilter.h"

32
#include "otbReciprocalHAlphaImageFilter.h"
33
#include "otbSinclairToReciprocalCovarianceMatrixImageFilter.h"
34

35
int otbReciprocalHAlphaImageFilter(int itkNotUsed(argc), char * argv[])
36
{
37 38 39 40 41
  const char * inputFilenameHH = argv[1];
  const char * inputFilenameHV = argv[2];
  const char * inputFilenameVV = argv[3];
  int size = atoi(argv[4]);
  const char * outputFilename = argv[5];
42

43

44 45
  typedef std::complex<double>  ComplexPixelType;
  const unsigned int Dimension = 2;
46 47


48 49 50 51 52 53 54 55
  typedef otb::Image<ComplexPixelType, Dimension>  	   ComplexImageType;
  typedef otb::VectorImage<ComplexPixelType, Dimension>  ComplexVectorImageType;
  typedef otb::VectorImage<double, Dimension>          RealVectorImageType;



  typedef otb::ImageFileReader<ComplexImageType>  ReaderType;
  typedef otb::ImageFileWriter<RealVectorImageType> WriterType;
56

57
  using SinclairToCovFilterType = otb::SinclairToReciprocalCovarianceMatrixImageFilter<ComplexImageType, ComplexVectorImageType>;
58

59 60
  typedef itk::MeanImageFilter<ComplexImageType, ComplexImageType>         MeanFilterType;
  typedef otb::PerBandVectorImageFilter<ComplexVectorImageType, ComplexVectorImageType, MeanFilterType> PerBandMeanFilterType;
61 62


63 64 65 66 67
  typedef otb::ReciprocalHAlphaImageFilter<ComplexVectorImageType, RealVectorImageType> HAlphaFilterType;

  ReaderType::Pointer readerHH = ReaderType::New();
  ReaderType::Pointer readerHV = ReaderType::New();
  ReaderType::Pointer readerVV = ReaderType::New();
68

69 70
  WriterType::Pointer writer = WriterType::New();

71
  SinclairToCovFilterType::Pointer sinclairtocov = SinclairToCovFilterType::New();
72 73
  PerBandMeanFilterType::Pointer perBand = PerBandMeanFilterType::New();
  HAlphaFilterType::Pointer haafilter = HAlphaFilterType::New();
74 75


76 77 78
  MeanFilterType::InputSizeType radius;
  radius.Fill( size );
  perBand->GetFilter()->SetRadius(radius);
79 80


81 82 83
  readerHH->SetFileName(inputFilenameHH);
  readerHV->SetFileName(inputFilenameHV);
  readerVV->SetFileName(inputFilenameVV);
84

85 86 87
  sinclairtocov->SetVariadicNamedInput(otb::polarimetry_tags::hh{}, readerHH->GetOutput());
  sinclairtocov->SetVariadicNamedInput(otb::polarimetry_tags::hv_or_vh{}, readerHV->GetOutput());
  sinclairtocov->SetVariadicNamedInput(otb::polarimetry_tags::vv{}, readerVV->GetOutput());
88

89
  perBand->SetInput(sinclairtocov->GetOutput());
90

91
  haafilter->SetVariadicInput<0>(perBand->GetOutput());
92

93
  writer->SetFileName(outputFilename);
94
  writer->SetInput(haafilter->GetOutput());
95 96 97 98
  writer->Update();

  return EXIT_SUCCESS;
}