otbMultivariateAlterationDetectorImageFilter.h 7.01 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
/*=========================================================================

  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.

=========================================================================*/
#ifndef __otbMultivariateAlterationDetectorImageFilter_h
#define __otbMultivariateAlterationDetectorImageFilter_h

#include "itkImageToImageFilter.h"

#include "otbStreamingStatisticsVectorImageFilter.h"
#include "otbConcatenateVectorImageFilter.h"

#include "vnl/vnl_vector.h"
#include "vnl/vnl_matrix.h"

namespace otb
{

/** \class MultivariateAlterationDetectorImageFilter
33
 * \brief This filter implements the Multivariate Alteration Detector
OTB Bot's avatar
STYLE  
OTB Bot committed
34
 *
35 36
 * This filter implements the Multivariate Alteration Detector, based
 * on the following work:
OTB Bot's avatar
STYLE  
OTB Bot committed
37
 *
38
 * A. A. Nielsen and K. Conradsen, "Multivariate alteration detection
39
 * (mad) in multispectral, bi-temporal image data: a new approach to
40 41
 * change detection studies," Remote Sens. Environ., vol. 64,
 * pp. 1-19, (1998)
OTB Bot's avatar
STYLE  
OTB Bot committed
42
 *
43 44 45 46
 * Multivariate Alteration Detector takes two images as inputs and
 * produce a set of N change maps as a VectorImage (where N is the
 * maximum of number of bands in first and second image) with the
 * following properties:
OTB Bot's avatar
STYLE  
OTB Bot committed
47
 *
48 49 50 51
 * - Change maps are differences of a pair of linear combinations of
 * bands from image 1 and bands from image 2 chosen to maximize the
 * correlation.
 * - Each change map is orthogonal to the others.
OTB Bot's avatar
STYLE  
OTB Bot committed
52
 *
53 54
 * This is a statistical method which can handle different modalities
 * and even differents bands and number of bands between images.
OTB Bot's avatar
STYLE  
OTB Bot committed
55
 *
56 57 58
 * If numbers of bands in image 1 and 2 are equal, then change maps
 * are sorted by increasing correlation. If number of bands is
 * different, the change maps are sorted by decreasing correlation.
OTB Bot's avatar
STYLE  
OTB Bot committed
59
 *
60
 * The GetV1() and GetV2() methods allow to retrieve the linear
Julien Michel's avatar
Julien Michel committed
61
 * combinations used to generate the Mad change maps as a vnl_matrix of
62 63
 * double, and the GetRho() method allows to retrieve the correlation
 * associated to each Mad change maps as a vnl_vector.
OTB Bot's avatar
STYLE  
OTB Bot committed
64
 *
65 66 67
 * This filter has been implemented from the Matlab code kindly made
 * available by the authors here:
 * http://www2.imm.dtu.dk/~aa/software.html
OTB Bot's avatar
STYLE  
OTB Bot committed
68
 *
69 70 71 72
 * Both cases (same and different number of bands) have been validated
 * by comparing the output image to the output produced by the Matlab
 * code, and the reference images for testing have been generated from
 * the Matlab code using Octave.
73
 *
74
 * \ingroup Streamed, Multithreaded
75 76
 */
template <class TInputImage, class TOutputImage>
OTB Bot's avatar
STYLE  
OTB Bot committed
77 78
class ITK_EXPORT MultivariateAlterationDetectorImageFilter
  : public itk::ImageToImageFilter<TInputImage, TOutputImage>
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
{
public:
  /** Standard class typedefs. */
  typedef MultivariateAlterationDetectorImageFilter           Self;
  typedef itk::ImageToImageFilter<TInputImage, TOutputImage>  Superclass;
  typedef itk::SmartPointer<Self>                             Pointer;
  typedef itk::SmartPointer<const Self>                       ConstPointer;

  /** Method for creation through the object factory. */
  itkNewMacro(Self);

  /** Run-time type information (and related methods). */
  itkTypeMacro(MultivariateAlterationDetectorImageFilter, ImageToImageFilter);

  /** Some convenient typedefs. */
  typedef TInputImage                            InputImageType;
  typedef typename InputImageType::Pointer      InputImagePointer;
  typedef typename InputImageType::ConstPointer InputImageConstPointer;
  typedef typename InputImageType::RegionType   InputImageRegionType;
  typedef typename InputImageType::PixelType     InputImagePixelType;
  typedef TOutputImage                           OutputImageType;
  typedef typename OutputImageType::Pointer      OutputImagePointer;
  typedef typename OutputImageType::RegionType   OutputImageRegionType;
  typedef typename OutputImageType::PixelType    OutputImagePixelType;

  /** Internal filters types */
  typedef StreamingStatisticsVectorImageFilter<InputImageType> CovarianceEstimatorType;
  typedef typename CovarianceEstimatorType::Pointer            CovarianceEstimatorPointer;
OTB Bot's avatar
STYLE  
OTB Bot committed
107
  typedef otb::ConcatenateVectorImageFilter<InputImageType, InputImageType, InputImageType> ConcatenateImageFilterType;
108 109 110 111 112 113 114 115 116 117 118 119
  typedef typename ConcatenateImageFilterType::Pointer         ConcatenateImageFilterPointer;

  typedef typename CovarianceEstimatorType::MatrixObjectType   MatrixObjectType;
  typedef typename MatrixObjectType::ComponentType             MatrixType;
  typedef typename MatrixType::InternalMatrixType              InternalMatrixType;
  typedef typename CovarianceEstimatorType::RealPixelType      VectorType;

  typedef typename VectorType::ValueType                       RealType;

  typedef vnl_vector<RealType>                                 VnlVectorType;
  typedef vnl_matrix<RealType>                                 VnlMatrixType;

Julien Michel's avatar
Julien Michel committed
120 121 122 123 124 125
  /** Get the mean of bands from image 1 */
  itkGetMacro(Mean1,VnlVectorType);

  /** Get the mean of bands from image 2 */
  itkGetMacro(Mean2,VnlVectorType);

126 127 128
  /** Get the linear combinations of bands of image 1 associated to
   *  multivariate alteration detector. This is a square matrix of
   *  size nbBand of image 1. */
OTB Bot's avatar
STYLE  
OTB Bot committed
129
  itkGetMacro(V1, VnlMatrixType);
130 131 132 133

  /** Get the linear combinations of bands of image 2 associated to
   *  multivariate alteration detector. This is a square matrix of
   *  size nbBand of image 2. */
OTB Bot's avatar
STYLE  
OTB Bot committed
134
  itkGetMacro(V2, VnlMatrixType);
135 136

  /** Get the correlation coefficient associated with each mad.*/
OTB Bot's avatar
STYLE  
OTB Bot committed
137
  itkGetMacro(Rho, VnlVectorType);
138

139
  /** Get the covariance estimator (for progress reporting purposes) */
OTB Bot's avatar
STYLE  
OTB Bot committed
140
  itkGetObjectMacro(CovarianceEstimator, CovarianceEstimatorType);
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
  
  /** Connect one of the operands for pixel-wise addition */
  void SetInput1(const TInputImage * image1);

  /** Connect one of the operands for pixel-wise addition */
  void SetInput2(const TInputImage * image2);

  /** Get the inputs */
  const TInputImage * GetInput1();
  const TInputImage * GetInput2();

protected:
  MultivariateAlterationDetectorImageFilter();
  virtual ~MultivariateAlterationDetectorImageFilter() {}

OTB Bot's avatar
STYLE  
OTB Bot committed
156
  virtual void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId);
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171

  virtual void GenerateOutputInformation();

private:
  MultivariateAlterationDetectorImageFilter(const Self &); //purposely not implemented
  void operator =(const Self&); //purposely not implemented

  CovarianceEstimatorPointer m_CovarianceEstimator;
  MatrixType                 m_CovarianceMatrix;
  VectorType                 m_MeanValues;

  VnlMatrixType              m_V1;
  VnlMatrixType              m_V2;
  VnlVectorType              m_Mean1;
  VnlVectorType              m_Mean2;
172
  VnlVectorType              m_Rho;
173 174 175 176 177 178 179 180 181
};

} // end namespace otb

#ifndef OTB_MANUAL_INSTANTIATION
#include "otbMultivariateAlterationDetectorImageFilter.txx"
#endif

#endif