diff --git a/Code/Projections/otbGCPsToRPCSensorModelImageFilter.h b/Code/Projections/otbGCPsToRPCSensorModelImageFilter.h index c348608518381de286ba39f5070cce2b02b72eea..8932ecd899a95b58634e84cab57fa04397884782 100644 --- a/Code/Projections/otbGCPsToRPCSensorModelImageFilter.h +++ b/Code/Projections/otbGCPsToRPCSensorModelImageFilter.h @@ -9,11 +9,9 @@ Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. See OTBCopyright.txt for details. - Copyright (c) Institut Telecom / Telecom Bretagne. All rights reserved. - See ITCopyright.txt for details. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + 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. =========================================================================*/ diff --git a/Code/Projections/otbGCPsToRPCSensorModelImageFilter.txx b/Code/Projections/otbGCPsToRPCSensorModelImageFilter.txx index 6e0033e3c77a4fed8db06d28202c48511fa5759d..30a46772d8da71c594be69b25011e0aebbbee477 100644 --- a/Code/Projections/otbGCPsToRPCSensorModelImageFilter.txx +++ b/Code/Projections/otbGCPsToRPCSensorModelImageFilter.txx @@ -9,11 +9,9 @@ Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. See OTBCopyright.txt for details. - Copyright (c) Institut Telecom / Telecom Bretagne. All rights reserved. - See ITCopyright.txt for details. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + 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. =========================================================================*/ diff --git a/Code/Projections/otbLeastSquareAffineTransformEstimator.h b/Code/Projections/otbLeastSquareAffineTransformEstimator.h index a1ccf036b2d64d2c4ad1075731072a20b0630683..96043b7122c327496431b7299d99b6106e954407 100644 --- a/Code/Projections/otbLeastSquareAffineTransformEstimator.h +++ b/Code/Projections/otbLeastSquareAffineTransformEstimator.h @@ -9,11 +9,9 @@ Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. See OTBCopyright.txt for details. - Copyright (c) Institut Telecom / Telecom Bretagne. All rights reserved. - See ITCopyright.txt for details. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + 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. =========================================================================*/ diff --git a/Code/Projections/otbLeastSquareAffineTransformEstimator.txx b/Code/Projections/otbLeastSquareAffineTransformEstimator.txx index 6ece03fd192ecb92f44fdf9c77cea581fe0f6627..3b0a36886cf32f8a2f24b618c108d41bc148e5f7 100644 --- a/Code/Projections/otbLeastSquareAffineTransformEstimator.txx +++ b/Code/Projections/otbLeastSquareAffineTransformEstimator.txx @@ -9,11 +9,9 @@ Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. See OTBCopyright.txt for details. - Copyright (c) Institut Telecom / Telecom Bretagne. All rights reserved. - See ITCopyright.txt for details. - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + 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. =========================================================================*/ diff --git a/Code/Radiometry/otbTerraSarBrightnessFunctor.h b/Code/Radiometry/otbTerraSarBrightnessFunctor.h new file mode 100644 index 0000000000000000000000000000000000000000..871a5ce91130bad19a56b7e8453afaa73f79f355 --- /dev/null +++ b/Code/Radiometry/otbTerraSarBrightnessFunctor.h @@ -0,0 +1,92 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + Some parts of this code are derived from ITK. See ITKCopyright.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 __otbTerraSarBrightnessFunctor_h +#define __otbTerraSarBrightnessFunctor_h + +#include "otbMath.h" + +#include <complex> + +namespace otb +{ +namespace Functor +{ +/** + * \class TerraSarBrightnessImageFunctor + * \brief Compute beta naught coefficient. + * + * This functor is intended to be used by the + * TerrasarBrightnessImageFilter. + * + * For more information on Terrasar calibration, + * please refer to the + * documentation of this filter. + * + * \sa TerraSarBrightnessImageFilter + * \ingroup Functor + * \ingroup Radiometry + */ + +template <class TInput, class TOutput> +class TerraSarBrightnessFunctor +{ +public: + TerraSarBrightnessFunctor(); + virtual ~TerraSarBrightnessFunctor() {}; + + /** Accessors */ + void SetCalibrationFactor( double val ) { m_CalibrationFactor = val; }; + double GetCalibrationFactor() { return m_CalibrationFactor; }; + + /** Set results in decibels */ + void SetResultsInDecibels(bool db) + { + m_ResultsInDecibels = db; + } + + /** Get the value of the flag */ + bool GetResultsInDecibels() + { + return m_ResultsInDecibels; + } + + /** We assume that the input pixel is a scalar -> modulus image */ + inline TOutput operator() (const TInput & inPix); + /** We assume that the input pixel is a complex -> complex image */ + inline std::complex<TOutput> operator() (const std::complex<TInput> & inPix); + +private: + /** Calibration Factor */ + double m_CalibrationFactor; + + /** Shall we compute results in decibels ? */ + bool m_ResultsInDecibels; +}; + +}// end namespace functor +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbTerraSarBrightnessFunctor.txx" +#endif + +#endif diff --git a/Code/Radiometry/otbTerraSarBrightnessFunctor.txx b/Code/Radiometry/otbTerraSarBrightnessFunctor.txx new file mode 100644 index 0000000000000000000000000000000000000000..76b0fd61e15b15dfee278fee36a7559bbe22db72 --- /dev/null +++ b/Code/Radiometry/otbTerraSarBrightnessFunctor.txx @@ -0,0 +1,83 @@ +/*========================================================================= + + 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 __otbTerraSarBrightnessFunctor_txx +#define __otbTerraSarBrightnessFunctor_txx + +#include "otbTerraSarBrightnessFunctor.h" + +#include "itkNumericTraits.h" + +namespace otb +{ +namespace Functor +{ + +template <class TInput, class TOutput> +TerraSarBrightnessFunctor<TInput, TOutput> +::TerraSarBrightnessFunctor() +{ + m_CalibrationFactor = itk::NumericTraits<double>::Zero; + m_ResultsInDecibels = true; +} + + +template <class TInput, class TOutput> +TOutput +TerraSarBrightnessFunctor<TInput, TOutput> +::operator() (const TInput & inPix) +{ + // Formula: Beta^0 = Ks * |DN|² + + // First, square the input pixel + double squareInPix = vcl_pow( static_cast<double>(inPix), 2.); + + // Then apply the calibration factor + double beta = m_CalibrationFactor*squareInPix; + + // Results in decibels case + if(m_ResultsInDecibels) + { + beta = 10 * vcl_log10(beta); + } + + return static_cast<TOutput>(beta); +} + + +template <class TInput, class TOutput> +std::complex<TOutput> +TerraSarBrightnessFunctor<TInput, TOutput> +::operator() (const std::complex<TInput> & inPix) +{ + // First, extract modulus and phase + double modulus = vcl_sqrt(inPix.real()*inPix.real() + inPix.imag()*inPix.imag()); + double phase = vcl_atan2(inPix.imag(),inPix.real()); + + // Then, calibrate the modulus + double beta = this->operator()(modulus); + + // Last, put back the phase + std::complex<TOutput> out(std::polar(beta,phase)); + + return out; +} + +}// namespace Functor + +} // namespace otb +#endif diff --git a/Code/Radiometry/otbTerraSarBrightnessImageFilter.h b/Code/Radiometry/otbTerraSarBrightnessImageFilter.h index ae1856952ede0f96ea3324ab659bff2e4347d79a..8e026c704ea36461f3e1aee06435a735a922a630 100644 --- a/Code/Radiometry/otbTerraSarBrightnessImageFilter.h +++ b/Code/Radiometry/otbTerraSarBrightnessImageFilter.h @@ -19,32 +19,57 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#ifndef __otbTerraSarRadarBrightnessImageFilter_h -#define __otbTerraSarRadarBrightnessImageFilter_h - +#ifndef __otbTerraSarBrightnessImageFilter_h +#define __otbTerraSarBrightnessImageFilter_h #include "itkUnaryFunctorImageFilter.h" #include "itkMetaDataDictionary.h" + #include "otbMath.h" -#include "otbTerraSarFunctors.h" +#include "otbTerraSarBrightnessFunctor.h" namespace otb { - - -/** \class TerraSarRadarBrightnessImageFilter - * \brief Calculates the intra calibration of TerraSar sensor images. +/** \class TerraSarBrigthnessImageFilter + * \brief Calculates the brightness of TerraSar sensor images. + * + * Implementation of the brightness algorithm has been made following + * Infoterra documentation "Radiometric Calibration of TerraSAR-X + * Data". + * + * This filter computes the beta naught (\f$ \beta^{0} \f$) using the following formula: + * \f[\beta^{0} = k_{s} \cdot |DN|^{2} \f] + * + * Where \f$ k_{s} \f$ is the calibration factor, which is imported + * from the input image metadata, even if one can set different values + * using the proper accessors. + * + * Results can be obtained either in linear or logarithmic scale + * (decibels), using the ResultsInDecibels flag. + * + * This filter works with either real or complex image. In the case of + * the complex images (SLC products for instance), modulus and phase + * are extracted, sigma naught is computed from the modulus and the + * phase is set back to the result. + * + * For implementation details, consider reading the code + * TerraSarBrightnessFunctor. * + * \sa TerraSarBrightnessFunctor + * \sa TerraSarBrightnessImageFilter + * + * \ingroup Streamed + * \ingroup Multithreaded * \ingroup Radiometry */ - template <class TInputImage, class TOutputImage > class ITK_EXPORT TerraSarBrightnessImageFilter : public itk::UnaryFunctorImageFilter< TInputImage, TOutputImage, - ITK_TYPENAME Functor::TerraSarBrightnessImageFunctor< ITK_TYPENAME itk::NumericTraits<ITK_TYPENAME TInputImage::InternalPixelType>::ValueType, - ITK_TYPENAME itk::NumericTraits<ITK_TYPENAME TOutputImage::InternalPixelType>::ValueType > > + ITK_TYPENAME Functor::TerraSarBrightnessFunctor< + ITK_TYPENAME itk::NumericTraits<ITK_TYPENAME TInputImage::InternalPixelType>::ValueType, + ITK_TYPENAME itk::NumericTraits<ITK_TYPENAME TOutputImage::InternalPixelType>::ValueType > > { public: /** Extract input and output images dimensions.*/ @@ -52,20 +77,22 @@ public: itkStaticConstMacro( OutputImageDimension, unsigned int, TOutputImage::ImageDimension); /** "typedef" to simplify the variables definition and the declaration. */ - typedef TInputImage InputImageType; - typedef TOutputImage OutputImageType; - typedef typename InputImageType::InternalPixelType InputInternalPixelType; - typedef typename OutputImageType::InternalPixelType OutputInternalPixelType; - typedef typename itk::NumericTraits<InputInternalPixelType>::ValueType InputValueType; - typedef typename itk::NumericTraits<OutputInternalPixelType>::ValueType OutputValueType; - typedef typename Functor::TerraSarBrightnessImageFunctor< InputValueType, OutputValueType> FunctorType; + typedef TInputImage InputImageType; + typedef TOutputImage OutputImageType; + typedef typename InputImageType::InternalPixelType InputInternalPixelType; + typedef typename OutputImageType::InternalPixelType OutputInternalPixelType; + typedef typename itk::NumericTraits<InputInternalPixelType>::ValueType InputValueType; + typedef typename itk::NumericTraits<OutputInternalPixelType>::ValueType OutputValueType; + typedef typename Functor::TerraSarBrightnessFunctor + < InputValueType, OutputValueType> FunctorType; + typedef itk::MetaDataDictionary MetaDataDictionaryType; /** "typedef" for standard classes. */ - typedef TerraSarBrightnessImageFilter Self; - typedef itk::UnaryFunctorImageFilter< InputImageType, OutputImageType, FunctorType > - Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; + typedef TerraSarBrightnessImageFilter Self; + typedef itk::UnaryFunctorImageFilter< InputImageType, + OutputImageType, FunctorType > Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; /** object factory method. */ itkNewMacro(Self); @@ -73,19 +100,30 @@ public: /** return class name. */ itkTypeMacro(TerraSarBrightnessImageFilter, itk::UnaryFunctorImageFilter); - - typedef itk::MetaDataDictionary MetaDataDictionaryType; - typedef std::vector<double> DoubleVectorType; - typedef std::vector<DoubleVectorType> DoubleVectorVectorType; - - /** Accessors */ - void SetCalFactor(double pCalFactor) + /** Set the calibration factor*/ + void SetCalibrationFactor(double pCalibrationFactor) { - this->GetFunctor().SetCalFactor( pCalFactor ); + this->GetFunctor().SetCalibrationFactor( pCalibrationFactor ); this->Modified(); } - double GetCalFactor(){ - return this->GetFunctor().GetCalFactor(); + + /** Get the calibration factor */ + double GetCalibrationFactor() + { + return this->GetFunctor().GetCalibrationFactor(); + } + + /** Set the ResultsInDecibels flag */ + void SetResultsInDecibels(bool db) + { + this->GetFunctor().SetResultsInDecibels(db); + this->Modified(); + } + + /** Get the ResultsInDecibels flag */ + bool GetResultsInDecibels() + { + return this->GetFunctor().GetResultsInDecibels(); } protected: @@ -98,7 +136,8 @@ protected: void BeforeThreadedGenerateData(); private: - + TerraSarBrightnessImageFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented }; } // end namespace otb diff --git a/Code/Radiometry/otbTerraSarBrightnessImageFilter.txx b/Code/Radiometry/otbTerraSarBrightnessImageFilter.txx index 46bdcf14b5e5510d052cba20ba84a6ec2ccc9fbe..55fdb22926531a9803315700065e8316ae3123e5 100644 --- a/Code/Radiometry/otbTerraSarBrightnessImageFilter.txx +++ b/Code/Radiometry/otbTerraSarBrightnessImageFilter.txx @@ -19,8 +19,6 @@ #define __otbTerraSarBrightnessImageFilter_txx #include "otbTerraSarBrightnessImageFilter.h" -//#include "otbImageMetadataInterfaceFactory.h" -//#include "otbImageMetadataInterfaceBase.h" #include "otbTerraSarImageMetadataInterface.h" namespace otb @@ -38,11 +36,11 @@ TerraSarBrightnessImageFilter<TInputImage,TOutputImage> bool mdIsAvailable = lImageMetadata->CanRead(this->GetInput()->GetMetaDataDictionary()); // If the user doesn't set it AND the metadata is available, set calFactor using image metadata - if (this->GetCalFactor() == itk::NumericTraits<double>::min()) + if (this->GetCalibrationFactor() == itk::NumericTraits<double>::Zero) { if (mdIsAvailable) { - this->SetCalFactor( lImageMetadata->GetCalibrationFactor(this->GetInput()->GetMetaDataDictionary()) ); + this->SetCalibrationFactor( lImageMetadata->GetCalibrationFactor(this->GetInput()->GetMetaDataDictionary()) ); } else { diff --git a/Code/Radiometry/otbTerraSarCalibrationFunctor.h b/Code/Radiometry/otbTerraSarCalibrationFunctor.h new file mode 100644 index 0000000000000000000000000000000000000000..d817c98113a63acdabf389aaf1d84391aa588a4c --- /dev/null +++ b/Code/Radiometry/otbTerraSarCalibrationFunctor.h @@ -0,0 +1,213 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + + Some parts of this code are derived from ITK. See ITKCopyright.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 __otbTerraSarCalibrationFunctor_h +#define __otbTerraSarCalibrationFunctor_h + +#include "otbMath.h" +#include "otbTerraSarBrightnessFunctor.h" + +#include "itkSize.h" +#include "itkIndex.h" + +#include <complex> + +#include <otb/ImageNoise.h> + +namespace otb +{ +namespace Functor +{ +/** + * \class TerraSarCalibrationImageFunctor + * \brief Compute sigma naught coefficient. + * + * This functor is intended to be used by the + * TerrasarCalibrationImageFilter. + * + * For more information on Terrasar calibration, + * please refer to the + * documentation of this filter. + * + * \sa TerraSarCalibrationImageFilter + * \ingroup Functor + * \ingroup Radiometry + */ +template<class TInput, class TOutput> +class TerraSarCalibrationFunctor +{ +public: + /** Constructor */ + TerraSarCalibrationFunctor(); + /** Destructor */ + virtual ~TerraSarCalibrationFunctor() {}; + + /** Typedef to define the noise records map */ + typedef ossimplugins::ImageNoise ImageNoiseType; + + /** Typedef for image size and index */ + typedef itk::Size<2> SizeType; + typedef itk::Index<2> IndexType; + + /** Typedef for the brightness functor */ + typedef TerraSarBrightnessFunctor<double, double> BrightnessFunctorType; + + /** + * Set the noise record + */ + void SetNoiseRecord(const ImageNoiseType& record) + { + m_NoiseRecord = record; + } + + /** + * Get the noise record + */ + const ImageNoiseType & GetNoiseRecord() const + { + return m_NoiseRecord; + } + + /** Set the calibration factor */ + void SetCalibrationFactor( double val ) + { + m_CalibrationFactor = val; + m_Brightness.SetCalibrationFactor(val); + }; + + /** Get the calibration factor */ + double GetCalibrationFactor() const + { + return m_CalibrationFactor; + }; + + /** Set the local incidence angle */ + void SetLocalIncidentAngle( double val ) + { + m_LocalIncidentAngle = val; + m_SinLocalIncidentAngle = vcl_sin(m_LocalIncidentAngle*CONST_PI_180); + }; + + /** Get the local incidence angle */ + double GetLocalIncidentAngle() const + { + return m_LocalIncidentAngle; + }; + + /** Set the image size */ + void SetOriginalProductSize( SizeType size ) + { + m_OriginalProductSize = size; + }; + + /** Get the image size */ + const SizeType & GetOriginalProductSize() const + { + return m_OriginalProductSize; + }; + + /** Set the UseFastCalibration flag */ + void SetUseFastCalibration( bool b ) + { + m_UseFastCalibration = b; + }; + + /** Get the UseFastCalibration flag */ + bool GetUseFastCalibration() const + { + return m_UseFastCalibration; + }; + + /** Set the ResultsInDecibels flag */ + void SetResultsInDecibels( bool b ) + { + m_ResultsInDecibels = b; + }; + + /** Get the ResultsInDecibelsMethod flag */ + bool GetResultsInDecibels() const + { + return m_ResultsInDecibels; + }; + + /** Set the default value */ + void SetDefaultValue(double value) + { + m_DefaultValue = value; + } + + /** Get the default value */ + void GetDefaultValue(void) + { + return m_DefaultValue; + } + + /** Perform the calibration for one pixel (scalar -> modulus image) */ + inline TOutput operator() (const TInput & inPix, IndexType index); + + /** Perform the calibration for one pixel (complex -> complex image) */ + inline std::complex<TOutput> operator() (const std::complex<TInput> & inPix, IndexType index); + +private: + /** Return the current range position */ + inline double ComputeRangePosition(const IndexType& index) const; + + /** Return the current NEBN value */ + inline double ComputeNoiseEquivalentBetaNaught(double range) const; + + /** Calibration Factor */ + double m_CalibrationFactor; + + /** Radar Brightness functor */ + BrightnessFunctorType m_Brightness; + + /** Noise record vector */ + ImageNoiseType m_NoiseRecord; + + /** Sensor local incident angle in degree */ + double m_LocalIncidentAngle; + + /** sin of the LocalIncidentAngle */ + double m_SinLocalIncidentAngle; + + /** Image Size */ + SizeType m_OriginalProductSize; + + /** Fast Calibration Method. If set to true, will consider only the first noise coefficient else, + * will use all of them and applied it according to its acquisition UTC time and the coordinates + * of the pixel in the image. */ + bool m_UseFastCalibration; + + /** Compute results in dB */ + bool m_ResultsInDecibels; + + /** Default value for negative sigma */ + double m_DefaultValue; +}; + +}// end namespace functor +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbTerraSarCalibrationFunctor.txx" +#endif + +#endif diff --git a/Code/Radiometry/otbTerraSarCalibrationFunctor.txx b/Code/Radiometry/otbTerraSarCalibrationFunctor.txx new file mode 100644 index 0000000000000000000000000000000000000000..fa09df4cadcaea543b71679c41877909111dbdea --- /dev/null +++ b/Code/Radiometry/otbTerraSarCalibrationFunctor.txx @@ -0,0 +1,160 @@ +/*========================================================================= + + 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 __otbTerraSarCalibrationFunctor_txx +#define __otbTerraSarCalibrationFunctor_txx + +#include "otbTerraSarCalibrationFunctor.h" + + +namespace otb +{ +namespace Functor +{ +template <class TInput, class TOutput> +TerraSarCalibrationFunctor<TInput, TOutput> +::TerraSarCalibrationFunctor() +{ + // Initialise values + m_CalibrationFactor = itk::NumericTraits<double>::Zero; + m_LocalIncidentAngle = itk::NumericTraits<double>::Zero; + m_SinLocalIncidentAngle = itk::NumericTraits<double>::Zero; + m_OriginalProductSize.Fill(0); + m_UseFastCalibration = false; + m_ResultsInDecibels = true; + m_Brightness.SetResultsInDecibels(false); + m_DefaultValue = 0.00001; // Default value is 10^-5 +} + +template <class TInput, class TOutput> +double +TerraSarCalibrationFunctor<TInput, TOutput> +::ComputeRangePosition(const IndexType & index) const +{ + // First compute the range step for the given noise record + double rangeStep = (m_NoiseRecord.get_validityRangeMax()-m_NoiseRecord.get_validityRangeMin()) + /static_cast<double>(m_OriginalProductSize[0]); + + // Compute the range position using the rangeStep + double position = index[0] * rangeStep + m_NoiseRecord.get_validityRangeMin(); + + return position; +} + +template <class TInput, class TOutput> +double +TerraSarCalibrationFunctor<TInput, TOutput> +::ComputeNoiseEquivalentBetaNaught(double range) const +{ + // Formula: NEBN = Ks * SUM( coef_i * (tau - tau_ref)^i) + + // Retrieve the polynomial degree + unsigned int polynomialDegree = m_NoiseRecord.get_polynomialDegree(); + + // Compute tau - tau_ref + double deltaTau = range - m_NoiseRecord.get_referencePoint(); + + // Get polynomial coefficients + std::vector<double> coefficients = m_NoiseRecord.get_polynomialCoefficients(); + + // Initialize nebn value + double nebn = 0.; + + // For each degree + for(unsigned int degree = 0; degree <= polynomialDegree; ++degree) + { + // Cumulate polynomial + nebn += coefficients[degree] * vcl_pow(deltaTau,static_cast<double>(degree)); + } + + // Do not forget to multiply by the calibration factor + nebn*=m_CalibrationFactor; + + // Return the nebn value + return nebn; +} + + +template <class TInput, class TOutput> +TOutput +TerraSarCalibrationFunctor<TInput, TOutput> +::operator()(const TInput & inPix, IndexType index) +{ + // Formula: sigma = (Ks.|DN|²-NEBN) * sin Theta_local + + // First, compute the brightness using the brightness functor + double beta0 = m_Brightness( static_cast<double>(inPix) ); + + // Initialise sigma + double sigma = 0.; + + // If fast calibration is off, compute noise + if(m_UseFastCalibration) + { + sigma = beta0 * m_SinLocalIncidentAngle; + } + else + { + // Compute the range position for this noise record + double currentRange = this->ComputeRangePosition(index); + + // Compute the NEBN + double NEBN = this->ComputeNoiseEquivalentBetaNaught(currentRange); + + // Last, apply formula + sigma = (beta0 - NEBN) * m_SinLocalIncidentAngle; + + // Handle negative sigma case + if(sigma <=0) + { + sigma = m_DefaultValue; + } + } + + // If results are in dB + if(m_ResultsInDecibels) + { + sigma = 10 * vcl_log10(sigma); + } + + // Cast and return + return static_cast<TOutput>(sigma); +} + +template <class TInput, class TOutput> +std::complex<TOutput> +TerraSarCalibrationFunctor<TInput, TOutput> +::operator()(const std::complex<TInput> & inPix, IndexType index) +{ + // First, extract modulus and phase + double modulus = vcl_sqrt(inPix.real()*inPix.real() + inPix.imag()*inPix.imag()); + double phase = vcl_atan2(inPix.imag(),inPix.real()); + + // Then, calibrate the modulus + double sigma = this->operator()(modulus,index); + + // Last, put back the phase + std::complex<TOutput> out(std::polar(sigma,phase)); + + // And return the result + return out; +} + +}// namespace Functor + +} // namespace otb +#endif diff --git a/Code/Radiometry/otbTerraSarCalibrationImageFilter.h b/Code/Radiometry/otbTerraSarCalibrationImageFilter.h index b937ef80239335023d1f9b5a900a0252eec65811..4870e1dea8335d0d1b4f2114bf994dba38e87d7e 100644 --- a/Code/Radiometry/otbTerraSarCalibrationImageFilter.h +++ b/Code/Radiometry/otbTerraSarCalibrationImageFilter.h @@ -22,129 +22,211 @@ #ifndef __otbTerraSarCalibrationImageFilter_h #define __otbTerraSarCalibrationImageFilter_h - -#include "otbUnaryFunctorWithIndexImageFilter.h" -#include "otbTerraSarFunctors.h" +#include "itkImageToImageFilter.h" +#include "otbTerraSarCalibrationFunctor.h" #include "itkMetaDataDictionary.h" -//#include "itkUnaryFunctorImageFilter.h" -//#include "itkConstNeighborhoodIterator.h" -#include "otbMath.h" namespace otb { - - /** \class TerraSarCalibrationImageFilter * \brief Calculates the calibration of TerraSar sensor images. * - * For details, please refer to Infoterra documentation : "Radiometric Calibration of TerraSAR-X Data". - * Using FastCalibration boolean allows to compute the result considering the first noise polygone - * coeffcients for each line or to use every polygones coefficient given. - * The code was made considering that the first acquisition point is the lower left one. + * Implementation of the calibration algorithm has been made following + * Infoterra documentation "Radiometric Calibration of TerraSAR-X + * Data". + * + * This filter computes the sigma naught (\f$ \sigma^{0} \f$) using the following formula: + * \f[\sigma^{0} = ( k_{s} \cdot |DN|^{2} - NEBN) \cdot sin(\theta_{loc}\f] + * + * Where \f$ k_{s} \f$ is the calibration factor, \f$NEBN\f$ is the + * Noise Equivalent Beta Naugth and \f$ \theta_{loc} \f$ is the local + * incident angle. + * + * NEBN is interpolated for each range position according to the + * polynomial coefficients from the most recent noise record. + * + * \f$ \theta_{loc} \f$ is the mean incident angle over the scene. For + * now, this filter does not support more accurate behaviour like + * incident angle interpolation from metadata or the Geocoded + * Incidence Angle mask optional 1B product (GIM). * + * All parameters are imported from the input image metadata, even if + * one can set different values using the proper accessors. + * + * The UseFastCalibration flag alllows to derive a coarser yet faster + * calibration by neglecting the noise term. + * + * Results can be obtained either in linear or logarithmic scale + * (decibels), using the ResultsInDecibels flag. + * + * When signal value is too small with respect to the noise term, it + * may happen that \f$\sigma_{0} \f$ becomes negative. In that case + * the value is replaced by a default value, which can be tuned by the + * user. + * + * This filter works with either real or complex image. In the case of + * the complex images (SLC products for instance), modulus and phase + * are extracted, sigma naught is computed from the modulus and the + * phase is set back to the result. + * + * For implementation details, consider reading the code + * TerraSarCalibrationFunctor. + * + * \sa TerraSarCalibrationFunctor + * \sa TerraSarBrightnessImageFilter + * + * \ingroup Streamed + * \ingroup Multithreaded * \ingroup Radiometry */ template<class TInputImage, class TOutputImage > class ITK_EXPORT TerraSarCalibrationImageFilter : - public UnaryFunctorWithIndexImageFilter< - TInputImage, - TOutputImage, - ITK_TYPENAME Functor::TerraSarCalibrationImageFunctor< ITK_TYPENAME itk::NumericTraits<ITK_TYPENAME TInputImage::InternalPixelType>::ValueType, - ITK_TYPENAME itk::NumericTraits<ITK_TYPENAME TOutputImage::InternalPixelType>::ValueType > > + public itk::ImageToImageFilter<TInputImage,TOutputImage> { public: + /** "typedef" for standard classes. */ + typedef TerraSarCalibrationImageFilter Self; + typedef itk::ImageToImageFilter<TInputImage,TOutputImage> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + /** Extract input and output images dimensions.*/ - itkStaticConstMacro( InputImageDimension, unsigned int, TInputImage::ImageDimension); - itkStaticConstMacro( OutputImageDimension, unsigned int, TOutputImage::ImageDimension); - - /** "typedef" to simplify the variables definition and the declaration. */ - typedef TInputImage InputImageType; - typedef TOutputImage OutputImageType; - typedef typename InputImageType::InternalPixelType InputInternalPixelType; - typedef typename OutputImageType::InternalPixelType OutputInternalPixelType; - typedef typename itk::NumericTraits<InputInternalPixelType>::ValueType InputValueType; - typedef typename itk::NumericTraits<OutputInternalPixelType>::ValueType OutputValueType; - typedef typename Functor::TerraSarCalibrationImageFunctor< InputValueType, OutputValueType> FunctorType; + itkStaticConstMacro( InputImageDimension, unsigned int, + TInputImage::ImageDimension); + itkStaticConstMacro( OutputImageDimension, unsigned int, + TOutputImage::ImageDimension); + + /** "typedef" to simplify the variables definition + * and the declaration. */ + typedef TInputImage InputImageType; + typedef TOutputImage OutputImageType; + typedef typename InputImageType::RegionType InputImageRegionType; + typedef typename OutputImageType::RegionType OutputImageRegionType; + typedef typename InputImageType::InternalPixelType InputInternalPixelType; + typedef typename OutputImageType::InternalPixelType OutputInternalPixelType; + typedef typename itk::NumericTraits<InputInternalPixelType>::ValueType InputValueType; + typedef typename itk::NumericTraits<OutputInternalPixelType>::ValueType OutputValueType; + + /** Calibration functor typedef */ + typedef typename Functor::TerraSarCalibrationFunctor<InputValueType, + OutputValueType> CalibrationFunctorType; + + /** typedef to access metadata */ + typedef itk::MetaDataDictionary MetaDataDictionaryType; + typedef typename InputImageType::SizeType SizeType; + + /** Noise records typedefs */ + typedef ossimplugins::ImageNoise ImageNoiseType; + /** + * This is used to store the noise record along with its + * acquisition time + */ + typedef std::pair<double,ImageNoiseType> NoiseRecordType; + typedef std::vector<NoiseRecordType> NoiseRecordVectorType; - /** "typedef" for standard classes. */ - typedef TerraSarCalibrationImageFilter Self; - typedef UnaryFunctorWithIndexImageFilter< InputImageType, OutputImageType, FunctorType > Superclass; - typedef itk::SmartPointer<Self> Pointer; - typedef itk::SmartPointer<const Self> ConstPointer; - /** object factory method. */ itkNewMacro(Self); /** return class name. */ - // Use a with neighborhood to have access to the pixel coordinates - itkTypeMacro(TerraSarCalibrationImageFilter, UnaryFunctorWithIndexImageFilter); - - typedef itk::MetaDataDictionary MetaDataDictionaryType; - typedef typename FunctorType::DoubleVectorType DoubleVectorType; - typedef typename FunctorType::DoubleVectorVectorType DoubleVectorVectorType; - typedef typename InputImageType::SizeType SizeType; - -// typedef typename FunctorType::LIntVectorType LIntVectorType; + itkTypeMacro(TerraSarCalibrationImageFilter,ImageToImageFilter); /** Accessors */ /** Calibration Factor */ - void SetCalFactor( double val ); - double GetCalFactor() const; - /** Noise minimal range validity */ - void SetNoiseRangeValidityMin( double val ); - double GetNoiseRangeValidityMin() const; - - /** Noise maximal range validity */ - void SetNoiseRangeValidityMax( double val ); - double GetNoiseRangeValidityMax() const; - /** Noise reference range validity */ - void SetNoiseRangeValidityRef( double val ); - double GetNoiseRangeValidityRef() const; + itkSetMacro(CalibrationFactor,double); + itkGetMacro(CalibrationFactor,double); + /** Sensor local incident angle in degree */ - void SetLocalIncidentAngle( double val ); - double GetLocalIncidentAngle() const; - /** Sinus of the sensor local incident angle in degree */ - double GetSinLocalIncidentAngle() const; - /** Vector of vector that contain noise polinomial coefficient */ - void SetNoisePolynomialCoefficientsList( DoubleVectorVectorType vect ); - DoubleVectorVectorType GetNoisePolynomialCoefficientsList() const; - /** Image size (setter is protected)*/ - SizeType GetImageSize() const; + itkSetMacro(LocalIncidentAngle,double); + itkGetMacro(LocalIncidentAngle,double); - /** Fast Calibration Method. If set to trus, will consider only the first noise coefficient else, - * will use all of them and applied it according to its acquisition UTC time and the coordinates - * of the pixel in the image. */ - void SetUseFastCalibrationMethod( bool b ); - bool GetUseFastCalibrationMethod() const; - /** TimeUTC for each noise coefficient acquisition (in Julian day). */ - void SetTimeUTC( DoubleVectorType vect ); - DoubleVectorType GetTimeUTC() const; + /** If fast calibration is On, noise is ignored */ + itkSetMacro(UseFastCalibration,bool); + itkGetMacro(UseFastCalibration,bool); + itkBooleanMacro(UseFastCalibration); + + /** Activate if you wish results in decibels */ + itkSetMacro(ResultsInDecibels,bool); + itkGetMacro(ResultsInDecibels,bool); + itkBooleanMacro(ResultsInDecibels); + /** Pulse Repetition Frequency */ - void SetPRF( double val ); - double GetPRF() const; - /** Inverse Pulse Repetition Frequency */ - double GetInvPRF() const; + itkSetMacro(PRF,double); + itkGetMacro(PRF,double); + + /** Set the default value (replacing negative sigma */ + itkSetMacro(DefaultValue,double); + itkGetMacro(DefaultValue,double); + + /** The Calibration algorithm uses the original product size to + * compute the range and azimuth location. Hence, if the input image is + * an extract of the original product, this information must be set. + * If not set, the LargestPossibleRegion of the input image is + * used. Please note that this parameter has no influence on the output + * image regions. */ + itkSetMacro(OriginalProductSize,SizeType); + itkGetConstReferenceMacro(OriginalProductSize,SizeType); + + /** + * Add a new noise record for calibration. + * \param utcAcquisitionTime Noise record time + * \param record The noise record + */ + void AddNoiseRecord(double utcAcquisitionTime, const ImageNoiseType& record); + + /** + * Clear all noise records + */ + void ClearNoiseRecords(); protected: /** Constructor */ TerraSarCalibrationImageFilter(); /** Destructor */ - virtual ~TerraSarCalibrationImageFilter() {}; - /** Image Size setter*/ - void SetImageSize( SizeType size ); - + virtual ~TerraSarCalibrationImageFilter(); + /** Initialize the functor vector */ void BeforeThreadedGenerateData(); - + + /** Threaded generate Data */ + virtual void ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread,int threadId); + /** PrintSelf method */ void PrintSelf(std::ostream& os, itk::Indent indent) const; private: -bool m_ParamLoaded; -}; + TerraSarCalibrationImageFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + /** Method used to order noise records by increasing acquisition + * date */ + static bool CompareNoiseRecords(const NoiseRecordType& record1, const NoiseRecordType& record2); + + /** Calibration Factor */ + double m_CalibrationFactor; + /** Sensor local incident angle in degree */ + double m_LocalIncidentAngle; + + /** Pulse Repetition Frequency */ + double m_PRF; + + /** Original product size */ + SizeType m_OriginalProductSize; + + /** Use fast calibration ? */ + bool m_UseFastCalibration; + /** Results in decibels ? */ + bool m_ResultsInDecibels; + + /** Noise record vector */ + NoiseRecordVectorType m_NoiseRecords; + + /** Default value (for negative sigma) */ + bool m_DefaultValue; + +}; } // end namespace otb diff --git a/Code/Radiometry/otbTerraSarCalibrationImageFilter.txx b/Code/Radiometry/otbTerraSarCalibrationImageFilter.txx index ecc85896fe5b56e6e996939c38ea142820f20639..66e6258d464a2c3518cc3d3ee99cf40b30cd33fb 100644 --- a/Code/Radiometry/otbTerraSarCalibrationImageFilter.txx +++ b/Code/Radiometry/otbTerraSarCalibrationImageFilter.txx @@ -19,11 +19,14 @@ #define __otbTerraSarCalibrationImageFilter_txx #include <algorithm> + #include "otbTerraSarCalibrationImageFilter.h" -//#include "otbImageMetadataInterfaceFactory.h" -//#include "otbImageMetadataInterfaceBase.h" #include "otbTerraSarImageMetadataInterface.h" +#include "itkImageRegionConstIteratorWithIndex.h" +#include "itkImageRegionIterator.h" +#include "itkProgressReporter.h" + namespace otb { /** @@ -31,348 +34,236 @@ namespace otb */ template <class TInputImage, class TOutputImage> TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::TerraSarCalibrationImageFilter() +::TerraSarCalibrationImageFilter() : m_CalibrationFactor(itk::NumericTraits<double>::Zero), + m_LocalIncidentAngle(itk::NumericTraits<double>::Zero), + m_PRF(1.), + m_OriginalProductSize(), + m_UseFastCalibration(false), + m_ResultsInDecibels(true), + m_NoiseRecords(), + m_DefaultValue(0.00001) + +{} + +template <class TInputImage, class TOutputImage> +TerraSarCalibrationImageFilter<TInputImage,TOutputImage> +::~TerraSarCalibrationImageFilter() { - m_ParamLoaded = false; + // Clear any noise records + this->ClearNoiseRecords(); } template <class TInputImage, class TOutputImage> void TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::BeforeThreadedGenerateData() +::AddNoiseRecord(double utcAcquisitionTime, const ImageNoiseType& record) +{ + // Create the pair + NoiseRecordType newRecord(utcAcquisitionTime,record); + + // Add it to the list + m_NoiseRecords.push_back(newRecord); + } + +template <class TInputImage, class TOutputImage> +void +TerraSarCalibrationImageFilter<TInputImage,TOutputImage> +::ClearNoiseRecords() { - Superclass::BeforeThreadedGenerateData(); + m_NoiseRecords.clear(); +} - if(m_ParamLoaded) - return; - this->SetImageSize( this->GetInput()->GetLargestPossibleRegion().GetSize() ); +template <class TInputImage, class TOutputImage> +bool +TerraSarCalibrationImageFilter<TInputImage,TOutputImage> +::CompareNoiseRecords(const NoiseRecordType& record1, const NoiseRecordType& record2) +{ + return (record1.first > record2.first); +} + +template <class TInputImage, class TOutputImage> +void +TerraSarCalibrationImageFilter<TInputImage,TOutputImage> +::BeforeThreadedGenerateData() +{ + // Set the product original size + if (m_OriginalProductSize[0] == 0 && m_OriginalProductSize[1] == 0) + { + m_OriginalProductSize = this->GetInput()->GetLargestPossibleRegion().GetSize(); + } - // Load metadata + // Build the metadata interface TerraSarImageMetadataInterface::Pointer lImageMetadata = otb::TerraSarImageMetadataInterface::New(); + + // Check availability bool mdIsAvailable = lImageMetadata->CanRead(this->GetInput()->GetMetaDataDictionary()); - // If the user doesn't set the data AND the metadata is available, set the data + // If the user did not set the data AND the metadata is available, set the data - // CalFactor - if (this->GetCalFactor() == itk::NumericTraits<double>::min()) + // CalibrationFactor + if (m_CalibrationFactor == itk::NumericTraits<double>::Zero) { if (mdIsAvailable) { - this->SetCalFactor( lImageMetadata->GetCalibrationFactor(this->GetInput()->GetMetaDataDictionary()) ); + m_CalibrationFactor = lImageMetadata->GetCalibrationFactor(this->GetInput()->GetMetaDataDictionary()); } else { - itkExceptionMacro(<<"Invalid input image. Only TerraSar images are supproted"); + itkExceptionMacro(<<"Invalid input image. Only TerraSar images are supported"); } } - - // NoiseRangeValidityMin - if (this->GetNoiseRangeValidityMin() == itk::NumericTraits<double>::min()) - { - if (mdIsAvailable) - { - DoubleVectorType vecTmp = lImageMetadata->GetNoiseValidityRangeMinList(this->GetInput()->GetMetaDataDictionary()); - std::sort(vecTmp.begin(), vecTmp.end()); - this->SetNoiseRangeValidityMin(vecTmp[0]); - } - else - { - itkExceptionMacro(<<"Invalid input image. Only TerraSar images are supproted"); - } - } - - // NoiseRangeValidityMax - if (this->GetNoiseRangeValidityMax() == itk::NumericTraits<double>::max()) - { - if (mdIsAvailable) - { - DoubleVectorType vecTmp = lImageMetadata->GetNoiseValidityRangeMaxList(this->GetInput()->GetMetaDataDictionary()); - std::sort(vecTmp.begin(), vecTmp.end()); - this->SetNoiseRangeValidityMax(vecTmp[vecTmp.size()-1]); - } - else - { - itkExceptionMacro(<<"Invalid input image. Only TerraSar images are supproted"); - } - } - // NoiseRangeValidityRef - if (this->GetNoiseRangeValidityRef() == itk::NumericTraits<double>::Zero) - { - if (mdIsAvailable) + // Noise records + if(m_NoiseRecords.empty()) { - double sum = 0; - // Get vector - DoubleVectorType noiseRefList = lImageMetadata->GetNoiseReferencePointList(this->GetInput()->GetMetaDataDictionary()); - // Mean computation - for (unsigned int i=0; i<noiseRefList.size(); i++) + if (mdIsAvailable) { - sum += noiseRefList[i]; - } + // Retrieve the number of noise records + unsigned int nbNoiseRecords = lImageMetadata->GetNumberOfNoiseRecords(this->GetInput()->GetMetaDataDictionary()); - this->SetNoiseRangeValidityRef( sum / noiseRefList.size() ); - } - else - { - itkExceptionMacro(<<"Invalid input image. Only TerraSar images are supproted"); - } - } - - // NoisePolynomialCoefficient - if ( ((this->GetNoisePolynomialCoefficientsList())[0][0] == itk::NumericTraits<double>::Zero) - && (this->GetNoisePolynomialCoefficientsList().size() == 1) - && (this->GetNoisePolynomialCoefficientsList()[0].size() == 1) ) - { - if (mdIsAvailable) - { - this->SetNoisePolynomialCoefficientsList(lImageMetadata->GetNoisePolynomialCoefficientsList(this->GetInput()->GetMetaDataDictionary())); - } - else - { - itkExceptionMacro(<<"Invalid input image. Only TerraSar images are supproted"); - } - } - - // Time UTC - if ((this->GetTimeUTC()[0] == itk::NumericTraits<double>::Zero) && (this->GetTimeUTC()[1] == 1.) && (this->GetTimeUTC().size() == 2)) - { - if (mdIsAvailable) - { - this->SetTimeUTC(lImageMetadata->GetNoiseTimeUTCList(this->GetInput()->GetMetaDataDictionary())); - } + // Retrieve the noise records + ossimplugins::Noise * noiseRecords = lImageMetadata->GetNoise(this->GetInput()->GetMetaDataDictionary()); + + // Retrieve corresponding times + std::vector<double> noiseTimes = lImageMetadata->GetNoiseTimeUTCList(this->GetInput()->GetMetaDataDictionary()); + + if(!m_UseFastCalibration && ( noiseTimes.empty() || nbNoiseRecords == 0)) + { + itkExceptionMacro(<<"No noise records found. Consider using fast calibration."); + } + + // For each noise record, add it + for(unsigned int i = 0; i < nbNoiseRecords;++i) + { + this->AddNoiseRecord(noiseTimes[i],noiseRecords->get_imageNoise()[i]); + } + + // Free memory + delete noiseRecords; + } else - { - itkExceptionMacro(<<"Invalid input image. Only TerraSar images are supproted"); + { + itkExceptionMacro(<<"Invalid input image. Only TerraSar images are supported"); + } } - } // Radar frequency (PRF) if (this->GetPRF() == 1.) { if (mdIsAvailable) { - this->SetPRF(lImageMetadata->GetRadarFrequency(this->GetInput()->GetMetaDataDictionary())); + m_PRF = lImageMetadata->GetRadarFrequency(this->GetInput()->GetMetaDataDictionary()); } else { - itkExceptionMacro(<<"Invalid input image. Only TerraSar images are supproted"); + itkExceptionMacro(<<"Invalid input image. Only TerraSar images are supported"); } } - // Incidence Angle - if (this->GetLocalIncidentAngle() == itk::NumericTraits<double>::Zero) + // Incident Angle + if (m_LocalIncidentAngle == itk::NumericTraits<double>::Zero) { if (mdIsAvailable) { - double mean = lImageMetadata->GetMeanIncidenceAngles(this->GetInput()->GetMetaDataDictionary()); - this->SetLocalIncidentAngle(mean); + m_LocalIncidentAngle = lImageMetadata->GetMeanIncidenceAngles(this->GetInput()->GetMetaDataDictionary()); } else { - itkExceptionMacro(<<"Invalid input image. Only TerraSar images are supproted"); + itkExceptionMacro(<<"Invalid input image. Only TerraSar images are supported"); } } -} - - -/******************************* ACCESSORS ********************************/ - -template <class TInputImage, class TOutputImage> -void -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::SetCalFactor( double val ) -{ - this->GetFunctor().SetCalFactor( val ); - this->Modified(); -} - -template <class TInputImage, class TOutputImage> -double -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::GetCalFactor() const -{ - return this->GetFunctor().GetCalFactor(); + // Ensure that noise records are sorted by decreasing acquisition + // date + std::sort(m_NoiseRecords.begin(),m_NoiseRecords.end(), &Self::CompareNoiseRecords); } template <class TInputImage, class TOutputImage> void TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::SetNoiseRangeValidityMin( double val ) +::ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread, + int threadId) { - this->GetFunctor().SetNoiseRangeValidityMin( val ); - this->Modified(); -} + // Retrieve input and output pointer + typename InputImageType::ConstPointer inputPtr = this->GetInput(); + typename OutputImageType::Pointer outputPtr = this->GetOutput(0); -template <class TInputImage, class TOutputImage> -double -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::GetNoiseRangeValidityMin() const -{ - return this->GetFunctor().GetNoiseRangeValidityMin(); -} - -template <class TInputImage, class TOutputImage> -void -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::SetNoiseRangeValidityMax( double val ) -{ - this->GetFunctor().SetNoiseRangeValidityMax( val ); - this->Modified(); -} - -template <class TInputImage, class TOutputImage> -double -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::GetNoiseRangeValidityMax() const -{ - return this->GetFunctor().GetNoiseRangeValidityMax(); -} - -template <class TInputImage, class TOutputImage> -void -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::SetNoiseRangeValidityRef( double val ) -{ - this->GetFunctor().SetNoiseRangeValidityRef( val ); - this->Modified(); -} - - -template <class TInputImage, class TOutputImage> -double -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::GetNoiseRangeValidityRef() const -{ - return this->GetFunctor().GetNoiseRangeValidityRef(); -} - - -template <class TInputImage, class TOutputImage> -void -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::SetLocalIncidentAngle( double val ) -{ - this->GetFunctor().SetLocalIncidentAngle( val ); - this->Modified(); -} - -template <class TInputImage, class TOutputImage> -double -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::GetLocalIncidentAngle() const -{ - return this->GetFunctor().GetLocalIncidentAngle(); -} - -template <class TInputImage, class TOutputImage> -double -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::GetSinLocalIncidentAngle() const -{ - return this->GetFunctor().GetSinLocalIncidentAngle(); -} - -template <class TInputImage, class TOutputImage> -void -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::SetNoisePolynomialCoefficientsList( DoubleVectorVectorType vect ) -{ - this->GetFunctor().SetNoisePolynomialCoefficientsList( vect ); - this->Modified(); -} - - -template <class TInputImage, class TOutputImage> -typename TerraSarCalibrationImageFilter<TInputImage,TOutputImage>::DoubleVectorVectorType -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::GetNoisePolynomialCoefficientsList() const -{ - return this->GetFunctor().GetNoisePolynomialCoefficientsList(); -} - -template <class TInputImage, class TOutputImage> -void -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::SetImageSize( SizeType size ) -{ - this->GetFunctor().SetImageSize( size ); - this->Modified(); -} - - -template <class TInputImage, class TOutputImage> -typename TerraSarCalibrationImageFilter<TInputImage,TOutputImage>::SizeType -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::GetImageSize() const -{ - return this->GetFunctor().GetImageSize(); -} - -template <class TInputImage, class TOutputImage> -void -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::SetUseFastCalibrationMethod( bool b ) -{ - this->GetFunctor().SetUseFastCalibrationMethod( b ); - this->Modified(); -} - -template <class TInputImage, class TOutputImage> -bool -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::GetUseFastCalibrationMethod() const -{ - return this->GetFunctor().GetUseFastCalibrationMethod(); -} - - -template <class TInputImage, class TOutputImage> -void -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::SetTimeUTC( DoubleVectorType vect ) -{ - this->GetFunctor().SetTimeUTC( vect ); - this->Modified(); -} + // Define the portion of the input to walk for this thread, using + // the CallCopyOutputRegionToInputRegion method allows for the input + // and output images to be different dimensions + InputImageRegionType inputRegionForThread; + this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread); + + // Define the iterators + itk::ImageRegionConstIteratorWithIndex<TInputImage> inputIt(inputPtr, inputRegionForThread); + itk::ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread); + + // Initialize iterators + inputIt.GoToBegin(); + outputIt.GoToBegin(); - -template <class TInputImage, class TOutputImage> -typename TerraSarCalibrationImageFilter<TInputImage,TOutputImage>::DoubleVectorType -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::GetTimeUTC() const -{ - return this->GetFunctor().GetTimeUTC(); -} - - -template <class TInputImage, class TOutputImage> -void -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::SetPRF( double val ) -{ - this->GetFunctor().SetPRF( val ); - this->Modified(); -} - - -template <class TInputImage, class TOutputImage> -double -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::GetPRF() const -{ - return this->GetFunctor().GetPRF(); + // Set up the functor + CalibrationFunctorType calibrationFunctor; + calibrationFunctor.SetCalibrationFactor(m_CalibrationFactor); + calibrationFunctor.SetLocalIncidentAngle(m_LocalIncidentAngle); + calibrationFunctor.SetUseFastCalibration(m_UseFastCalibration); + calibrationFunctor.SetResultsInDecibels(m_ResultsInDecibels); + calibrationFunctor.SetOriginalProductSize(m_OriginalProductSize); + calibrationFunctor.SetDefaultValue(m_DefaultValue); + + // Set up progress reporting + itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels()); + + // The acquisition time of the first line of OutputRegionForThread. + double invPRF = 1/m_PRF; + double currentAzimuthPosition = m_NoiseRecords.back().first = invPRF + * (m_OriginalProductSize[1]- inputIt.GetIndex()[1] -1); + + // Local variable to store the current noise record + NoiseRecordType currentNoiseRecord; + + // Look for the first noise record to be used (remember we sorted + // m_NoiseRecords by decreasing time) + NoiseRecordVectorType::const_iterator currentNoiseRecordIt = m_NoiseRecords.begin(); + + // Iterate until we find it + while(currentNoiseRecordIt != m_NoiseRecords.end() && currentNoiseRecordIt->first > currentAzimuthPosition) + { + ++currentNoiseRecordIt; + } + + // Store current line index + typename OutputImageRegionType::IndexType::IndexValueType currentLine = inputIt.GetIndex()[1]; + + // Iterate on the input and output buffer + while( !inputIt.IsAtEnd() ) + { + // Check if we changed line + if(currentLine != inputIt.GetIndex()[1]) + { + // If so, update the current azimuth time + currentAzimuthPosition -= invPRF; + + // Update line counter + currentLine = inputIt.GetIndex()[1]; + + // And check if we changed of NoiseRecord + if(currentAzimuthPosition < currentNoiseRecordIt->first + && currentNoiseRecordIt != m_NoiseRecords.end()) + { + // If so, update the functor + ++currentNoiseRecordIt; + calibrationFunctor.SetNoiseRecord(currentNoiseRecordIt->second); + } + } + // Apply the calibration functor + outputIt.Set( calibrationFunctor( inputIt.Get(), inputIt.GetIndex() ) ); + ++inputIt; + ++outputIt; + progress.CompletedPixel(); // potential exception thrown here + } } -template <class TInputImage, class TOutputImage> -double -TerraSarCalibrationImageFilter<TInputImage,TOutputImage> -::GetInvPRF() const -{ - return this->GetFunctor().GetInvPRF(); -} - -/**PrintSelf method */ template <class TInputImage, class TOutputImage> void TerraSarCalibrationImageFilter<TInputImage,TOutputImage> @@ -380,37 +271,13 @@ TerraSarCalibrationImageFilter<TInputImage,TOutputImage> { Superclass::PrintSelf(os, indent); - os << "Calibration Factor : " << this->GetCalFactor() << std::endl; - os << "Sensor local incident angle : " << this->GetLocalIncidentAngle() << std::endl; - os << "Noise minimal range validity: " << this->GetNoiseRangeValidityMin() << std::endl; - os << "Noise maximal range validity: " << this->GetNoiseRangeValidityMax() << std::endl; - os << "Noise reference range : " << this->GetNoiseRangeValidityRef() << std::endl; - - if(this->GetUseFastCalibrationMethod()) - { - os << "Noise polinomial coefficient: [ "; - for (unsigned int i=0; i<this->GetNoisePolynomialCoefficientsList()[0].size(); ++i) - { - os << this->GetNoisePolynomialCoefficientsList()[0][i] << " "; - } - os << "]" << std::endl; - } - else - { - os << "Pulse Repetition Frequency : " << this->GetPRF() << std::endl; - os << "Noise acquisitions : " << this->GetNoisePolynomialCoefficientsList().size() << std::endl; - for (unsigned int i=0; i<this->GetNoisePolynomialCoefficientsList().size(); ++i) - { - os << "Noise acquisition "<< i << ":" << std::endl; - os << "Noise TimeUTC : " << this->GetTimeUTC()[i] << std::endl; - os << "Noise polinomial coefficient: [ "; - for (unsigned int j=0; j<this->GetNoisePolynomialCoefficientsList()[j].size(); ++j) - { - os << this->GetNoisePolynomialCoefficientsList()[i][j] << " "; - } - os << "]" << std::endl; - } - } + os << indent << "Calibration Factor: " << m_CalibrationFactor << std::endl; + os << indent << "PRF: "<<m_PRF <<std::endl; + os << indent << "Original product size: "<<m_OriginalProductSize << std::endl; + os << indent << "Sensor local incidence angle: " << m_LocalIncidentAngle << std::endl; + os << indent << "Fast calibration: " << (m_UseFastCalibration ? "On" : "Off")<<std::endl; + os << indent << "Results in decibels: " << (m_ResultsInDecibels ? "Yes" : "No") << std::endl; + os << indent << "Number of noise records: " << m_NoiseRecords.size() <<std::endl; } diff --git a/Code/Radiometry/otbTerraSarFunctors.h b/Code/Radiometry/otbTerraSarFunctors.h deleted file mode 100644 index 988d02f7de37d2df9a19a1d6cc9e6eb82688fb79..0000000000000000000000000000000000000000 --- a/Code/Radiometry/otbTerraSarFunctors.h +++ /dev/null @@ -1,168 +0,0 @@ -/*========================================================================= - - Program: ORFEO Toolbox - Language: C++ - Date: $Date$ - Version: $Revision$ - - - Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. - See OTBCopyright.txt for details. - - - Some parts of this code are derived from ITK. See ITKCopyright.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 __otbTerraSarFunctors_h -#define __otbTerraSarFunctors_h - - -#include "itkUnaryFunctorImageFilter.h" -#include "itkMetaDataDictionary.h" -#include "otbMath.h" - -namespace otb -{ -namespace Functor -{ - - -/** - * \class TerraSarBrightnessImageFunctor - * \brief Compute the radar brightness from an modulus image. - * - * \ingroup Functor - * \ingroup Radiometry - */ -template <class TInput, class TOutput> -class TerraSarBrightnessImageFunctor -{ -public: - TerraSarBrightnessImageFunctor(); - virtual ~TerraSarBrightnessImageFunctor() {}; - - typedef std::vector<double> DoubleVectorType; - typedef std::vector<DoubleVectorType> DoubleVectorVectorType; - typedef itk::Size<2> SizeType; - - /** Accessors */ - void SetCalFactor( double val ) { m_CalFactor = val; }; - double GetCalFactor() { return m_CalFactor; }; - - /** We assume that the input pixel is a scalar -> modulus image */ - inline TOutput operator() (const TInput & inPix); - /** We assume that the input pixel is a complex -> complex image */ - inline std::complex<TOutput> operator() (const std::complex<TInput> & inPix); - -private: - /** Calibration Factor */ - double m_CalFactor; -}; - - - - -/** - * \class TerraSarCalibrationImageFunctor - * \brief Compute sigma naught coefficient from a modulus image. - * - * \ingroup Functor - * \ingroup Radiometry - */ -template<class TInput, class TOutput> -class TerraSarCalibrationImageFunctor -{ -public: - TerraSarCalibrationImageFunctor(); - virtual ~TerraSarCalibrationImageFunctor() {}; - - typedef std::vector<double> DoubleVectorType; - typedef std::vector<DoubleVectorType> DoubleVectorVectorType; - typedef std::vector<long int> LIntVectorType; - typedef itk::Size<2> SizeType; - typedef itk::Index<2> IndexType; - typedef TerraSarBrightnessImageFunctor<double, double> BrightnessFunctorType; - - /** Accessors */ - void SetCalFactor( double val ) { m_CalFactor = val; m_Brightness.SetCalFactor(val); }; - double GetCalFactor() const { return m_CalFactor; }; - void SetNoiseRangeValidityMin( double val ) { m_NoiseRangeValidityMin = val; }; - double GetNoiseRangeValidityMin() const { return m_NoiseRangeValidityMin; }; - void SetNoiseRangeValidityMax( double val ) { m_NoiseRangeValidityMax = val; }; - double GetNoiseRangeValidityMax() const { return m_NoiseRangeValidityMax; }; - void SetNoiseRangeValidityRef( double val ) { m_NoiseRangeValidityRef = val; }; - double GetNoiseRangeValidityRef() const { return m_NoiseRangeValidityRef; }; - void SetLocalIncidentAngle( double val ) - { - m_LocalIncidentAngle = val; - m_SinLocalIncidentAngle = vcl_sin(m_LocalIncidentAngle*CONST_PI_180); - }; - double GetLocalIncidentAngle() const { return m_LocalIncidentAngle; }; - double GetSinLocalIncidentAngle() const { return m_SinLocalIncidentAngle; }; - void SetNoisePolynomialCoefficientsList( DoubleVectorVectorType vect ) { m_NoisePolynomialCoefficientsList = vect; }; - DoubleVectorVectorType GetNoisePolynomialCoefficientsList() const { return m_NoisePolynomialCoefficientsList; }; - void SetImageSize( SizeType size ) { m_ImageSize = size; }; - SizeType GetImageSize() const { return m_ImageSize; }; - void SetUseFastCalibrationMethod( bool b ) { m_UseFastCalibrationMethod = b; }; - bool GetUseFastCalibrationMethod() const { return m_UseFastCalibrationMethod; }; - void SetTimeUTC( DoubleVectorType vect ) { m_TimeUTC = vect; }; - DoubleVectorType GetTimeUTC() const { return m_TimeUTC; }; - void SetPRF( double val ) { m_PRF = val; m_InvPRF = 1./m_PRF; }; - double GetPRF() const { return m_PRF; }; - double GetInvPRF() const { return m_InvPRF; }; - BrightnessFunctorType GetBrightness() { return m_Brightness; }; - double ComputeCurrentNoise( unsigned int colId ); - DoubleVectorType ComputeCurrentCoeffs( unsigned int lineId ); - - /** We assume that the input pixel is a scalar -> modulus image */ - inline TOutput operator() (const TInput & inPix, IndexType index); - /** We assume that the input pixel is a complex -> complex image */ - inline std::complex<TOutput> operator() (const std::complex<TInput> & inPix, IndexType index); - -private: - /** Calibration Factor */ - double m_CalFactor; - /** Noise minimal range validity */ - double m_NoiseRangeValidityMin; - /** Noise maxinimal range validity */ - double m_NoiseRangeValidityMax; - /** Noise reference range */ - double m_NoiseRangeValidityRef; - /** Sensor local incident angle in degree */ - double m_LocalIncidentAngle; - /** sin of the LocalIncidentAngle */ - double m_SinLocalIncidentAngle; - /** Vector of vector that contain noise polinomial coefficient */ - DoubleVectorVectorType m_NoisePolynomialCoefficientsList; - /** Image Size */ - SizeType m_ImageSize; - /** Fast Calibration Method. If set to trus, will consider only the first noise coefficient else, - * will use all of them and applied it according to its acquisition UTC time and the coordinates - * of the pixel in the image. */ - bool m_UseFastCalibrationMethod; - /** TimeUTC for each noise coefficient acquisition (in Julian day). */ - DoubleVectorType m_TimeUTC; - /** Pulse Repetition Frequency */ - double m_PRF; - /** Inverse Pulse Repetition Frequency */ - double m_InvPRF; - /** Radar Brightness functor */ - BrightnessFunctorType m_Brightness; -}; - - - -}// end namespace functor -} // end namespace otb - -#ifndef OTB_MANUAL_INSTANTIATION -#include "otbTerraSarFunctors.txx" -#endif - -#endif diff --git a/Code/Radiometry/otbTerraSarFunctors.txx b/Code/Radiometry/otbTerraSarFunctors.txx deleted file mode 100644 index 82d6f4cc6a4daa633652bac5f815e3d836a3f06a..0000000000000000000000000000000000000000 --- a/Code/Radiometry/otbTerraSarFunctors.txx +++ /dev/null @@ -1,205 +0,0 @@ -/*========================================================================= - - 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 __otbTerraSarFunctors_txx -#define __otbTerraSarFunctors_txx - -#include "otbTerraSarFunctors.h" - - -namespace otb -{ -namespace Functor -{ - -/******************************************************************/ -/*********** TerraSarBrightnessImageFunctor *****************/ -/******************************************************************/ -template <class TInput, class TOutput> -TerraSarBrightnessImageFunctor<TInput, TOutput> -::TerraSarBrightnessImageFunctor() -{ - m_CalFactor = itk::NumericTraits<double>::min(); -} - - -template <class TInput, class TOutput> -TOutput -TerraSarBrightnessImageFunctor<TInput, TOutput> -::operator() (const TInput & inPix) -{ - double squareInPix = vcl_pow( static_cast<double>(inPix), 2.); - // Beta naught computation - double beta = m_CalFactor*squareInPix; - - return static_cast<TOutput>(beta); -} - - -template <class TInput, class TOutput> -std::complex<TOutput> -TerraSarBrightnessImageFunctor<TInput, TOutput> -::operator() (const std::complex<TInput> & inPix) -{ - // Beta naught computation, will be the Modulus of the result - - double beta = operator()(static_cast<double>(std::abs(inPix))); - // Phase - double phase = static_cast<double>(std::arg(inPix)); - - // We retrieve the complex value from the modulus and the phase. - std::complex<TOutput> res = std::complex<TOutput>(beta*vcl_cos(phase), beta*vcl_sin(phase) ); - - return res; -} - - -/******************************************************************/ -/*********** TerraSarCalibrationImageFunctor ****************/ -/******************************************************************/ -template <class TInput, class TOutput> -TerraSarCalibrationImageFunctor<TInput, TOutput> -::TerraSarCalibrationImageFunctor() -{ - m_CalFactor = itk::NumericTraits<double>::min(); - m_NoiseRangeValidityMin = itk::NumericTraits<double>::min(); - m_NoiseRangeValidityMax = itk::NumericTraits<double>::max(); - m_NoiseRangeValidityRef = itk::NumericTraits<double>::Zero; - m_LocalIncidentAngle = itk::NumericTraits<double>::Zero; - m_SinLocalIncidentAngle = itk::NumericTraits<double>::Zero; - m_NoisePolynomialCoefficientsList = DoubleVectorVectorType( 1, DoubleVectorType(1, itk::NumericTraits<double>::Zero) ); - m_ImageSize.Fill(0); - m_UseFastCalibrationMethod = true; - m_TimeUTC = DoubleVectorType(2, itk::NumericTraits<double>::Zero); - m_TimeUTC[1] = 1.; - m_PRF = 1.; -} - - -template <class TInput, class TOutput> -double -TerraSarCalibrationImageFunctor<TInput, TOutput> -::ComputeCurrentNoise( unsigned int colId ) -{ - double curRange = 0.; - double width_2 = static_cast<double>(m_ImageSize[0])/2.; - // Use +1 because image start index is 0 - if( colId < static_cast<unsigned int>(width_2) ) - { - curRange = m_NoiseRangeValidityMin + ( m_NoiseRangeValidityRef-m_NoiseRangeValidityMin )/width_2 * static_cast<double>(colId+1); - } - else - { - curRange = m_NoiseRangeValidityRef + ( m_NoiseRangeValidityMax-m_NoiseRangeValidityRef )/width_2 * (static_cast<double>(colId+1) - width_2 ); - } - return curRange; -} - - -template <class TInput, class TOutput> -typename TerraSarCalibrationImageFunctor<TInput, TOutput>::DoubleVectorType -TerraSarCalibrationImageFunctor<TInput, TOutput> -::ComputeCurrentCoeffs( unsigned int lineId ) -{ - DoubleVectorType curCoeffs; - if(m_UseFastCalibrationMethod) - { - curCoeffs = m_NoisePolynomialCoefficientsList[0]; - } - else - { - // (m_ImageSize[1]-1)-(lineId) because the first acquisition line is the last image one. - // (m_ImageSize[1]-1) because image starts to 0. - //double interval = static_cast<double>(m_ImageSize[1]) / static_cast<double>(m_NoisePolynomialCoefficientsList.size()); - // compute utc time of the line - double currTimeUTC = m_TimeUTC[0] + static_cast<double>((m_ImageSize[1]-1)-lineId)*m_InvPRF; - unsigned int id = 0; - bool go = true; - // deduct the corresponding noise acquisition index - - while( id<m_TimeUTC.size() && go) - { - if( currTimeUTC < m_TimeUTC[id] ) - go = false; - id++; - } - id--; - - double timeCoef = 1. / (m_TimeUTC[id]- m_TimeUTC[id-1]) * (currTimeUTC-m_TimeUTC[id-1]); - for(unsigned int j=0; j<m_NoisePolynomialCoefficientsList.size(); j++) - { - curCoeffs.push_back( m_NoisePolynomialCoefficientsList[id-1][j] + (m_NoisePolynomialCoefficientsList[id][j] - m_NoisePolynomialCoefficientsList[id-1][j]) * timeCoef ); - } - } - - return curCoeffs; -} - - - -template <class TInput, class TOutput> -TOutput -TerraSarCalibrationImageFunctor<TInput, TOutput> -::operator()(const TInput & inPix, IndexType index) -{ - double diffCurRange = ComputeCurrentNoise( static_cast<unsigned int>(index[0]) ) - this->GetNoiseRangeValidityRef(); - - DoubleVectorType curCoeff = this->ComputeCurrentCoeffs( static_cast<unsigned int>(index[1]) ); - - double outRadBr = this->GetBrightness()( static_cast<double>(inPix) ); - - double NEBN = 0.; - for(unsigned int i=0; i<curCoeff.size(); i++) - { - NEBN += curCoeff[i]*vcl_pow( diffCurRange, static_cast<double>(i)); - } - - double sigma = ( outRadBr - this->GetCalFactor()*NEBN ) * this->GetSinLocalIncidentAngle(); - - return static_cast<TOutput>(sigma); -} - - -template <class TInput, class TOutput> -std::complex<TOutput> -TerraSarCalibrationImageFunctor<TInput, TOutput> -::operator()(const std::complex<TInput> & inPix, IndexType index) -{ - double diffCurRange = this->ComputeCurrentNoise( static_cast<unsigned int>(index[0]) ) - this->GetNoiseRangeValidityRef(); - DoubleVectorType curCoeff = this->ComputeCurrentCoeffs( static_cast<unsigned int>(index[1]) ); - - double modulus = vcl_abs(inPix); - double outRadBr = static_cast<double>(this->GetBrightness()( modulus )); - - double NEBN = 0.; - for(unsigned int i=0; i<curCoeff.size(); i++) - { - NEBN += curCoeff[i]*vcl_pow( diffCurRange, static_cast<double>(i)); - } - double sigma = ( outRadBr - this->GetCalFactor()*NEBN ) * this->GetSinLocalIncidentAngle(); - double phase = std::arg(inPix); - - std::complex<TOutput> out(sigma*vcl_cos(phase), sigma*vcl_sin(phase)); - - return out; -} - - -}// namespace Functor - -} // namespace otb -#endif diff --git a/Testing/Code/Radiometry/CMakeLists.txt b/Testing/Code/Radiometry/CMakeLists.txt index 7944133e3f01dddb5a465c4aff05a8697b95e264..e9d945fa6a85716d09610b08f680305ae4f42e1e 100644 --- a/Testing/Code/Radiometry/CMakeLists.txt +++ b/Testing/Code/Radiometry/CMakeLists.txt @@ -1028,14 +1028,9 @@ ADD_TEST(raTvAeronet_ArcachonLevel10_ExtractData ${RADIOMETRY_TESTS8} # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbRADIOMETRY_TESTS9 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -# ------- TerraSarCalibrationImageFunctor ------------------------------ -ADD_TEST(raTvTerraSarCalibrationImageFunctor ${RADIOMETRY_TESTS9} -# --compare-image ${EPSILON} -# ${BASELINE}/raTvTerraSarCalibrationImageFunctor.tif -# ${TEMP}/raTvTerraSarCalibrationImageFunctor.tif - otbTerraSarCalibrationImageFunctor -# ${INPUTDATA}/ExtractIMAGE_HH_SRA_strip_012.tif -# ${TEMP}/raTvTerraSarCalibrationImageFunctor.tif +# ------- TerraSarCalibrationFunctor ------------------------------ +ADD_TEST(raTvTerraSarCalibrationFunctor ${RADIOMETRY_TESTS9} + otbTerraSarCalibrationFunctor ) # ------- TerraSarCalibrationImageFilter ------------------------------ @@ -1043,56 +1038,91 @@ ADD_TEST(raTuTerraSarCalibrationImageFilterNew ${RADIOMETRY_TESTS9} otbTerraSarCalibrationImageFilterNew ) -ADD_TEST(raTvTerraSarCalibrationImageFilterTest ${RADIOMETRY_TESTS9} +IF(OTB_DATA_USE_LARGEINPUT) + +ADD_TEST(raTvTerraSarCalibrationImageFilterTestUPSALACoarse ${RADIOMETRY_TESTS9} --compare-image ${EPSILON} - ${BASELINE}/raTvTerraSarCalibrationImageFilterTest.tif - ${TEMP}/raTvTerraSarCalibrationImageFilterTest.tif + ${BASELINE}/raTvTerraSarCalibrationImageFilterTest_UPSALACoarse.tif + ${TEMP}/raTvTerraSarCalibrationImageFilterTest_UPSALACoarse.tif otbTerraSarCalibrationImageFilterTest - ${INPUTDATA}/ExtractIMAGE_HH_SRA_strip_012.tif - ${TEMP}/raTvTerraSarCalibrationImageFilterTest.tif - 0 # don't use metadata + ${LARGEINPUT}/TERRASARX/UPSALA_GLACIER/TSX1_SAR__MGD/IMAGEDATA/IMAGE_HH_SRA_strip_012.tif + ${TEMP}/raTvTerraSarCalibrationImageFilterTest_UPSALACoarse.tif + 1 # Use fast calibration + 0 # Results in linear scale + 2000 2000 250 250 # Extract ) -ADD_TEST(raTvTerraSarCalibrationImageComplexFilterTest ${RADIOMETRY_TESTS9} +ADD_TEST(raTvTerraSarCalibrationImageComplexFilterTestTORONTOCoarse ${RADIOMETRY_TESTS9} --compare-image ${EPSILON} - ${BASELINE}/raTvTerraSarCalibrationComplexImageFilterTest.tif - ${TEMP}/raTvTerraSarCalibrationComplexImageFilterTest.tif + ${BASELINE}/raTvTerraSarCalibrationImageComplexFilterTest_TORONTOCoarse.tif + ${TEMP}/raTvTerraSarCalibrationImageComplexFilterTest_TORONTOCoarse.tif otbTerraSarCalibrationImageComplexFilterTest - ${INPUTDATA}/ExtractIMAGE_HH_SRA_spot_074.tif - ${TEMP}/raTvTerraSarCalibrationComplexImageFilterTest.tif - 0 # don't use metadata + ${LARGEINPUT}/TERRASARX/TORONTO/TSX1_SAR__SSC/IMAGEDATA/IMAGE_HH_SRA_spot_074.cos + ${TEMP}/raTvTerraSarCalibrationImageComplexFilterTest_TORONTOCoarse.tif + 1 # Use fast calibration + 0 # Results in linear scale + 2000 2000 250 250 # Extract ) -IF(OTB_DATA_USE_LARGEINPUT) ADD_TEST(raTvTerraSarCalibrationImageFilterTestUPSALA ${RADIOMETRY_TESTS9} --compare-image ${EPSILON} - ${BASELINE}/raTvTerraSarCalibrationImageFilterTest_UPSALA.tif - ${TEMP}/raTvTerraSarCalibrationImageFilterTest_UPSALA.tif + ${BASELINE}/raTvTerraSarCalibrationImageFilterTest_UPSALA.tif + ${TEMP}/raTvTerraSarCalibrationImageFilterTest_UPSALA.tif otbTerraSarCalibrationImageFilterTest ${LARGEINPUT}/TERRASARX/UPSALA_GLACIER/TSX1_SAR__MGD/IMAGEDATA/IMAGE_HH_SRA_strip_012.tif ${TEMP}/raTvTerraSarCalibrationImageFilterTest_UPSALA.tif - 1 # use metadata + 0 # No fast calibration + 0 # Results in linear scale + 2000 2000 250 250 # Extract ) ADD_TEST(raTvTerraSarCalibrationImageComplexFilterTestTORONTO ${RADIOMETRY_TESTS9} --compare-image ${EPSILON} - ${BASELINE}/raTvTerraSarCalibrationImageComplexFilterTest_TORONTO.tif - ${TEMP}/raTvTerraSarCalibrationImageComplexFilterTest_TORONTO.tif + ${BASELINE}/raTvTerraSarCalibrationImageComplexFilterTest_TORONTO.tif + ${TEMP}/raTvTerraSarCalibrationImageComplexFilterTest_TORONTO.tif otbTerraSarCalibrationImageComplexFilterTest ${LARGEINPUT}/TERRASARX/TORONTO/TSX1_SAR__SSC/IMAGEDATA/IMAGE_HH_SRA_spot_074.cos ${TEMP}/raTvTerraSarCalibrationImageComplexFilterTest_TORONTO.tif - 1 # use metadata + 0 # No fast calibration + 0 # Results in linear scale + 2000 2000 250 250 # Extract ) + + +ADD_TEST(raTvTerraSarCalibrationImageFilterTestUPSALADb ${RADIOMETRY_TESTS9} + --compare-image ${EPSILON} + ${BASELINE}/raTvTerraSarCalibrationImageFilterTest_UPSALADb.tif + ${TEMP}/raTvTerraSarCalibrationImageFilterTest_UPSALADb.tif + otbTerraSarCalibrationImageFilterTest + ${LARGEINPUT}/TERRASARX/UPSALA_GLACIER/TSX1_SAR__MGD/IMAGEDATA/IMAGE_HH_SRA_strip_012.tif + ${TEMP}/raTvTerraSarCalibrationImageFilterTest_UPSALADb.tif + 0 # No fast calibration + 1 # Results in logarithmic + 2000 2000 250 250 # Extract +) + +ADD_TEST(raTvTerraSarCalibrationImageComplexFilterTestTORONTODb ${RADIOMETRY_TESTS9} + --compare-image ${EPSILON} + ${BASELINE}/raTvTerraSarCalibrationImageComplexFilterTest_TORONTODb.tif + ${TEMP}/raTvTerraSarCalibrationImageComplexFilterTest_TORONTODb.tif + otbTerraSarCalibrationImageComplexFilterTest + ${LARGEINPUT}/TERRASARX/TORONTO/TSX1_SAR__SSC/IMAGEDATA/IMAGE_HH_SRA_spot_074.cos + ${TEMP}/raTvTerraSarCalibrationImageComplexFilterTest_TORONTODb.tif + 0 # No fast calibration + 1 # Results in logarithmic scale + 2000 2000 250 250 # Extract +) + ENDIF(OTB_DATA_USE_LARGEINPUT) -# ------- TerraSarBrightnessImageFunctor ------------------------------ -ADD_TEST(raTvTerraSarBrightnessImageFunctor ${RADIOMETRY_TESTS9} +# ------- TerraSarBrightnessFunctor ------------------------------ +ADD_TEST(raTvTerraSarBrightnessFunctor ${RADIOMETRY_TESTS9} --compare-ascii ${EPSILON} ${BASELINE_FILES}/raTvTerraSarBrightnessImageFunctor.txt ${TEMP}/raTvTerraSarBrightnessImageFunctor.txt - otbTerraSarBrightnessImageFunctor + otbTerraSarBrightnessFunctor 12 # real pixel 12 # complex real part pixel 0 # complex imaginary part pixel @@ -1112,7 +1142,8 @@ ADD_TEST(raTvTerraSarBrightnessImageFilterTest ${RADIOMETRY_TESTS9} otbTerraSarBrightnessImageFilterTest ${INPUTDATA}/ExtractIMAGE_HH_SRA_strip_012.tif ${TEMP}/raTvTerraSarBrightnessImageFilterTest.tif - 0 # don't use metadata + 0 # don't use metadata + 0 # results in linear scale ) ADD_TEST(raTvTerraSarBrightnessImageComplexFilterTest ${RADIOMETRY_TESTS9} @@ -1122,7 +1153,8 @@ ADD_TEST(raTvTerraSarBrightnessImageComplexFilterTest ${RADIOMETRY_TESTS9} otbTerraSarBrightnessImageComplexFilterTest ${INPUTDATA}/ExtractIMAGE_HH_SRA_spot_074.tif ${TEMP}/raTvTerraSarBrightnessImageComplexFilterTest.tif - 0 # don't use metadata + 0 # don't use metadata + 0 # results in linear scale ) IF(OTB_DATA_USE_LARGEINPUT) @@ -1134,6 +1166,8 @@ ADD_TEST(raTvTerraSarBrightnessImageFilterUPSALA ${RADIOMETRY_TESTS9} ${LARGEINPUT}/TERRASARX/UPSALA_GLACIER/TSX1_SAR__MGD/IMAGEDATA/IMAGE_HH_SRA_strip_012.tif ${TEMP}/raTvTerraSarBrightnessImageFilter_UPSALA.tif 1 # use metadata + 0 # results in linear scale + 2000 2000 250 250 # Extract ) ADD_TEST(raTvTerraSarBrightnessImageComplexFilterTORONTO ${RADIOMETRY_TESTS9} @@ -1144,6 +1178,8 @@ ADD_TEST(raTvTerraSarBrightnessImageComplexFilterTORONTO ${RADIOMETRY_TESTS9} ${LARGEINPUT}/TERRASARX/TORONTO/TSX1_SAR__SSC/IMAGEDATA/IMAGE_HH_SRA_spot_074.cos ${TEMP}/raTvTerraSarBrightnessImageComplexFilter_TORONTO.tif 1 # use metadata + 0 # results in linear scale + 2000 2000 250 250 # Extract ) ENDIF(OTB_DATA_USE_LARGEINPUT) @@ -1240,11 +1276,11 @@ otbAeronetExtractDataBadData.cxx SET(Radiometry_SRCS9 otbRadiometryTests9.cxx -otbTerraSarCalibrationImageFunctor.cxx +otbTerraSarCalibrationFunctor.cxx otbTerraSarCalibrationImageFilterNew.cxx otbTerraSarCalibrationImageFilterTest.cxx otbTerraSarCalibrationImageComplexFilterTest.cxx -otbTerraSarBrightnessImageFunctor.cxx +otbTerraSarBrightnessFunctor.cxx otbTerraSarBrightnessImageFilterNew.cxx otbTerraSarBrightnessImageFilterTest.cxx otbTerraSarBrightnessImageComplexFilterTest.cxx diff --git a/Testing/Code/Radiometry/otbRadiometryTests9.cxx b/Testing/Code/Radiometry/otbRadiometryTests9.cxx index 189323a7dfe3263d2fe11143fdd13f2903732a7a..1ad2aba14b585547859ed1c1fbcf3cd278415289 100644 --- a/Testing/Code/Radiometry/otbRadiometryTests9.cxx +++ b/Testing/Code/Radiometry/otbRadiometryTests9.cxx @@ -27,8 +27,8 @@ void RegisterTests() { -REGISTER_TEST(otbTerraSarBrightnessImageFunctor); -REGISTER_TEST(otbTerraSarCalibrationImageFunctor); +REGISTER_TEST(otbTerraSarBrightnessFunctor); +REGISTER_TEST(otbTerraSarCalibrationFunctor); REGISTER_TEST(otbTerraSarCalibrationImageFilterNew); REGISTER_TEST(otbTerraSarCalibrationImageFilterTest); REGISTER_TEST(otbTerraSarCalibrationImageComplexFilterTest); diff --git a/Testing/Code/Radiometry/otbTerraSarBrightnessImageFunctor.cxx b/Testing/Code/Radiometry/otbTerraSarBrightnessFunctor.cxx similarity index 83% rename from Testing/Code/Radiometry/otbTerraSarBrightnessImageFunctor.cxx rename to Testing/Code/Radiometry/otbTerraSarBrightnessFunctor.cxx index ce6817684b782a1356c589a86df0d7439903b625..5cb9cafd4ab53df8b944ee288c92078d43b3a522 100644 --- a/Testing/Code/Radiometry/otbTerraSarBrightnessImageFunctor.cxx +++ b/Testing/Code/Radiometry/otbTerraSarBrightnessFunctor.cxx @@ -19,9 +19,9 @@ #include <iomanip> #include "itkExceptionObject.h" -#include "otbTerraSarFunctors.h" +#include "otbTerraSarBrightnessFunctor.h" -int otbTerraSarBrightnessImageFunctor(int argc, char * argv[]) +int otbTerraSarBrightnessFunctor(int argc, char * argv[]) { char *outFilename = argv[5]; double calFact = atof(argv[4]); @@ -29,10 +29,11 @@ int otbTerraSarBrightnessImageFunctor(int argc, char * argv[]) typedef double ScalarType; typedef std::complex<ScalarType> ComplexType; - typedef otb::Functor::TerraSarBrightnessImageFunctor<ScalarType, ScalarType> FunctorType; + typedef otb::Functor::TerraSarBrightnessFunctor<ScalarType, ScalarType> FunctorType; FunctorType funct; - funct.SetCalFactor(calFact); + funct.SetCalibrationFactor(calFact); + funct.SetResultsInDecibels(false); ScalarType inPix = static_cast<ScalarType>(atof(argv[1])); ComplexType inCplxPix(static_cast<ScalarType>(atof(argv[2])), static_cast<ScalarType>(atof(argv[3]))); diff --git a/Testing/Code/Radiometry/otbTerraSarBrightnessImageComplexFilterTest.cxx b/Testing/Code/Radiometry/otbTerraSarBrightnessImageComplexFilterTest.cxx index 30a89a62ae15bbab90dc2b81089c8452931ea5d1..e7c0f93e5a01fd30a6af4715eccde82ca1f158e4 100644 --- a/Testing/Code/Radiometry/otbTerraSarBrightnessImageComplexFilterTest.cxx +++ b/Testing/Code/Radiometry/otbTerraSarBrightnessImageComplexFilterTest.cxx @@ -28,12 +28,11 @@ int otbTerraSarBrightnessImageComplexFilterTest(int argc, char * argv[]) { const char * inputFileName = argv[1]; const char * outputFileName = argv[2]; - bool useMetadata = false; - if(atoi(argv[3]) != 0) - useMetadata = true; + const bool useMetadata = atoi(argv[3]); + const bool resultsInDb = atoi(argv[4]); - typedef std::complex<double> ComplexType; - typedef otb::Image<ComplexType, 2> ImageType; + typedef std::complex<double> ComplexType; + typedef otb::Image<ComplexType, 2> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; typedef otb::TerraSarBrightnessImageFilter<ImageType, ImageType> FilterType; @@ -49,15 +48,16 @@ int otbTerraSarBrightnessImageComplexFilterTest(int argc, char * argv[]) writer->SetFileName(outputFileName); reader->UpdateOutputInformation(); filter->SetInput(reader->GetOutput()); + filter->SetResultsInDecibels(resultsInDb); if( useMetadata ) { // Generate an extract from the large input ImageType::RegionType region; ImageType::IndexType id; - id[0] = 50; id[1] = 100; + id[0] = atoi(argv[5]); id[1] = atoi(argv[6]); ImageType::SizeType size; - size[0] = 150; size[1] = 100; + size[0] = atoi(argv[7]); size[1] = atoi(argv[8]); region.SetIndex(id); region.SetSize(size); extractor->SetExtractionRegion(region); @@ -67,7 +67,7 @@ int otbTerraSarBrightnessImageComplexFilterTest(int argc, char * argv[]) } else { - filter->SetCalFactor( 10 ); + filter->SetCalibrationFactor( 10 ); writer->SetInput(filter->GetOutput()); } diff --git a/Testing/Code/Radiometry/otbTerraSarBrightnessImageFilterTest.cxx b/Testing/Code/Radiometry/otbTerraSarBrightnessImageFilterTest.cxx index 25a729be39b1e67371db8cb469d1fdcaf0a72fcc..21eb60521795b63d4241556d1c1084bbb6414036 100644 --- a/Testing/Code/Radiometry/otbTerraSarBrightnessImageFilterTest.cxx +++ b/Testing/Code/Radiometry/otbTerraSarBrightnessImageFilterTest.cxx @@ -28,9 +28,8 @@ int otbTerraSarBrightnessImageFilterTest(int argc, char * argv[]) { const char * inputFileName = argv[1]; const char * outputFileName = argv[2]; - bool useMetadata = false; - if(atoi(argv[3]) != 0) - useMetadata = true; + const bool useMetadata = atoi(argv[3]); + const bool resultsInDb = atoi(argv[4]); typedef otb::Image<double, 2> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; @@ -48,15 +47,16 @@ int otbTerraSarBrightnessImageFilterTest(int argc, char * argv[]) writer->SetFileName(outputFileName); reader->UpdateOutputInformation(); filter->SetInput(reader->GetOutput()); + filter->SetResultsInDecibels(resultsInDb); if( useMetadata ) { // Generate an extract from the large input ImageType::RegionType region; ImageType::IndexType id; - id[0] = 50; id[1] = 100; + id[0] = atoi(argv[5]); id[1] = atoi(argv[6]); ImageType::SizeType size; - size[0] = 150; size[1] = 100; + size[0] = atoi(argv[7]); size[1] = atoi(argv[8]); region.SetIndex(id); region.SetSize(size); extractor->SetExtractionRegion(region); @@ -66,7 +66,7 @@ int otbTerraSarBrightnessImageFilterTest(int argc, char * argv[]) } else { - filter->SetCalFactor( 10 ); + filter->SetCalibrationFactor( 10 ); writer->SetInput(filter->GetOutput()); } diff --git a/Testing/Code/Radiometry/otbTerraSarCalibrationImageFunctor.cxx b/Testing/Code/Radiometry/otbTerraSarCalibrationFunctor.cxx similarity index 84% rename from Testing/Code/Radiometry/otbTerraSarCalibrationImageFunctor.cxx rename to Testing/Code/Radiometry/otbTerraSarCalibrationFunctor.cxx index 3ef5b1122eab41c03b58da17aadb4651e0e3a4bf..a81652d684322245495bd7f1b25c632c55d89d0b 100644 --- a/Testing/Code/Radiometry/otbTerraSarCalibrationImageFunctor.cxx +++ b/Testing/Code/Radiometry/otbTerraSarCalibrationFunctor.cxx @@ -17,16 +17,16 @@ =========================================================================*/ #include "itkExceptionObject.h" -#include "otbTerraSarFunctors.h" +#include "otbTerraSarCalibrationFunctor.h" #include "itkIndex.h" -int otbTerraSarCalibrationImageFunctor(int argc, char * argv[]) +int otbTerraSarCalibrationFunctor(int argc, char * argv[]) { typedef double ScalarType; typedef std::complex<ScalarType> ComplexType; typedef itk::Index<> IndexType; - typedef otb::Functor::TerraSarCalibrationImageFunctor<ScalarType, ScalarType> FunctorType; + typedef otb::Functor::TerraSarCalibrationFunctor<ScalarType, ScalarType> FunctorType; FunctorType funct; diff --git a/Testing/Code/Radiometry/otbTerraSarCalibrationImageComplexFilterTest.cxx b/Testing/Code/Radiometry/otbTerraSarCalibrationImageComplexFilterTest.cxx index 4850bbdd7700ab6ef660042700adcaf9a754ee94..6743cf10b46e461c913db5ecfda6d6b07af852f6 100644 --- a/Testing/Code/Radiometry/otbTerraSarCalibrationImageComplexFilterTest.cxx +++ b/Testing/Code/Radiometry/otbTerraSarCalibrationImageComplexFilterTest.cxx @@ -28,17 +28,14 @@ int otbTerraSarCalibrationImageComplexFilterTest(int argc, char * argv[]) { const char * inputFileName = argv[1]; const char * outputFileName = argv[2]; - bool useMetadata = true; - if(atoi(argv[3]) == 0) - useMetadata = false; + const bool useFastCalibration = atoi(argv[3]); + const bool resultsInDbs = atoi(argv[4]); - typedef std::complex<double> ComplexType; + typedef std::complex<double> ComplexType; typedef otb::Image<ComplexType, 2> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; typedef otb::TerraSarCalibrationImageFilter<ImageType, ImageType> FilterType; - typedef FilterType::DoubleVectorType DoubleVectorType; - typedef FilterType::DoubleVectorVectorType DoubleVectorVectorType; typedef itk::ExtractImageFilter<ImageType, ImageType> ExtractorType; ReaderType::Pointer reader = ReaderType::New(); @@ -52,68 +49,30 @@ int otbTerraSarCalibrationImageComplexFilterTest(int argc, char * argv[]) reader->UpdateOutputInformation(); filter->SetInput(reader->GetOutput()); - - if( !useMetadata ) - { - DoubleVectorType coefs; - coefs.push_back(1.); - coefs.push_back(0.5); - coefs.push_back(1.); - coefs.push_back(0.1); - DoubleVectorVectorType coefVect(1, coefs); - - coefs.clear(); - coefs.push_back(10.); - coefs.push_back(5); - coefs.push_back(10); - coefs.push_back(1); - coefVect.push_back( coefs ); - - coefs.clear(); - coefs.push_back(100); - coefs.push_back(50); - coefs.push_back(100); - coefs.push_back(10); - coefVect.push_back( coefs ); - - filter->SetNoisePolynomialCoefficientsList(coefVect); - - filter->SetCalFactor( 10 ); - filter->SetNoiseRangeValidityMin( 0 ); - filter->SetNoiseRangeValidityMax( 1 ); - filter->SetNoiseRangeValidityRef( 0.5 ); - filter->SetLocalIncidentAngle( 15 ); - - std::vector<double> timeUtc; - timeUtc.push_back(1.); - timeUtc.push_back(2.); - timeUtc.push_back(3.); - filter->SetTimeUTC(timeUtc); - filter->SetPRF(50); - + filter->SetUseFastCalibration(useFastCalibration); + filter->SetResultsInDecibels(resultsInDbs); - writer->SetInput(filter->GetOutput()); - - } - else - { - // Generate an extract from the large input + if(argc == 9) + { ImageType::RegionType region; ImageType::IndexType id; - id[0] = 50; id[1] = 100; + id[0] =atoi(argv[5]); + id[1] = atoi(argv[6]); ImageType::SizeType size; - size[0] = 150; size[1] = 100; + size[0] = atoi(argv[7]); + size[1] = atoi(argv[8]); region.SetIndex(id); region.SetSize(size); extractor->SetExtractionRegion(region); - extractor->SetInput(filter->GetOutput()); writer->SetInput(extractor->GetOutput()); - } + } + else + { + writer->SetInput(filter->GetOutput()); + } - filter->SetUseFastCalibrationMethod( false ); writer->Update(); - return EXIT_SUCCESS; } diff --git a/Testing/Code/Radiometry/otbTerraSarCalibrationImageFilterTest.cxx b/Testing/Code/Radiometry/otbTerraSarCalibrationImageFilterTest.cxx index 58cd1a1aafe420e8aae386b6c8f395ed23a6cbd3..025821de2382e419308c63815216986c56c0c711 100644 --- a/Testing/Code/Radiometry/otbTerraSarCalibrationImageFilterTest.cxx +++ b/Testing/Code/Radiometry/otbTerraSarCalibrationImageFilterTest.cxx @@ -28,16 +28,14 @@ int otbTerraSarCalibrationImageFilterTest(int argc, char * argv[]) { const char * inputFileName = argv[1]; const char * outputFileName = argv[2]; - bool useMetadata = true; - if(atoi(argv[3]) == 0) - useMetadata = false; + const bool useFastCalibration = atoi(argv[3]); + const bool resultsInDbs = atoi(argv[4]); - typedef otb::Image<double, 2> ImageType; + typedef double PixelType; + typedef otb::Image<PixelType, 2> ImageType; typedef otb::ImageFileReader<ImageType> ReaderType; typedef otb::ImageFileWriter<ImageType> WriterType; typedef otb::TerraSarCalibrationImageFilter<ImageType, ImageType> FilterType; - typedef FilterType::DoubleVectorType DoubleVectorType; - typedef FilterType::DoubleVectorVectorType DoubleVectorVectorType; typedef itk::ExtractImageFilter<ImageType, ImageType> ExtractorType; ReaderType::Pointer reader = ReaderType::New(); @@ -51,68 +49,30 @@ int otbTerraSarCalibrationImageFilterTest(int argc, char * argv[]) reader->UpdateOutputInformation(); filter->SetInput(reader->GetOutput()); - - if( !useMetadata ) - { - DoubleVectorType coefs; - coefs.push_back(1.); - coefs.push_back(0.5); - coefs.push_back(1.); - coefs.push_back(0.1); - DoubleVectorVectorType coefVect(1, coefs); - - coefs.clear(); - coefs.push_back(10.); - coefs.push_back(5); - coefs.push_back(10); - coefs.push_back(1); - coefVect.push_back( coefs ); - - coefs.clear(); - coefs.push_back(100); - coefs.push_back(50); - coefs.push_back(100); - coefs.push_back(10); - coefVect.push_back( coefs ); - - filter->SetNoisePolynomialCoefficientsList(coefVect); - - filter->SetCalFactor( 10 ); - filter->SetNoiseRangeValidityMin( 0 ); - filter->SetNoiseRangeValidityMax( 1 ); - filter->SetNoiseRangeValidityRef( 0.5 ); - filter->SetLocalIncidentAngle( 15 ); - - std::vector<double> timeUtc; - timeUtc.push_back(1.); - timeUtc.push_back(2.); - timeUtc.push_back(3.); - filter->SetTimeUTC(timeUtc); - filter->SetPRF(50); - - - writer->SetInput(filter->GetOutput()); - - } - else - { - // Generate an extract from the large input + filter->SetUseFastCalibration(useFastCalibration); + filter->SetResultsInDecibels(resultsInDbs); + + if(argc == 9) + { ImageType::RegionType region; ImageType::IndexType id; - id[0] = 50; id[1] = 100; + id[0] =atoi(argv[5]); + id[1] = atoi(argv[6]); ImageType::SizeType size; - size[0] = 150; size[1] = 100; + size[0] = atoi(argv[7]); + size[1] = atoi(argv[8]); region.SetIndex(id); region.SetSize(size); extractor->SetExtractionRegion(region); - extractor->SetInput(filter->GetOutput()); writer->SetInput(extractor->GetOutput()); - } + } + else + { + writer->SetInput(filter->GetOutput()); + } - filter->SetUseFastCalibrationMethod( false ); writer->Update(); - return EXIT_SUCCESS; } diff --git a/Utilities/otbossimplugins/ossim/ossimTerraSarProductDoc.cpp b/Utilities/otbossimplugins/ossim/ossimTerraSarProductDoc.cpp index 0ad78abebfa117036215f4e39388d8836901bab7..872f9cc578fd142f7d8af6989dd02215f0494330 100644 --- a/Utilities/otbossimplugins/ossim/ossimTerraSarProductDoc.cpp +++ b/Utilities/otbossimplugins/ossim/ossimTerraSarProductDoc.cpp @@ -1203,6 +1203,7 @@ bool ossimplugins::ossimTerraSarProductDoc::initIncidenceAngles( return result; } + bool ossimplugins::ossimTerraSarProductDoc::initNoise( const ossimXmlDocument* xdoc, ossimplugins::Noise* noise) const { diff --git a/Utilities/otbossimplugins/ossim/otb/ImageNoise.h b/Utilities/otbossimplugins/ossim/otb/ImageNoise.h index 29729a8c89b42de7b381f24203ffa24bd90165d0..abdbe339da930e25ee1c60c0668f9422f1e6b098 100644 --- a/Utilities/otbossimplugins/ossim/otb/ImageNoise.h +++ b/Utilities/otbossimplugins/ossim/otb/ImageNoise.h @@ -67,27 +67,63 @@ public: { _timeUTC = value; } + + const ossimString & get_timeUTC(void) const + { + return _timeUTC; + } + void set_validityRangeMin(double value) { _validityRangeMin = value; } + + double get_validityRangeMin(void) const + { + return _validityRangeMin; + } + void set_validityRangeMax(double value) { _validityRangeMax = value; } + + double get_validityRangeMax(void) const + { + return _validityRangeMax; + } + void set_referencePoint(double value) { _referencePoint = value; } + + double get_referencePoint(void) const + { + return _referencePoint; + } + void set_polynomialDegree(unsigned int value) { _polynomialDegree = value; } + + unsigned int get_polynomialDegree() const + { + return _polynomialDegree; + } + + void set_polynomialCoefficients(const std::vector<double>& value) { _polynomialCoefficients = value; } + const std::vector<double> & get_polynomialCoefficients(void) const + { + return _polynomialCoefficients; + } + protected: /** diff --git a/Utilities/otbossimplugins/ossim/otb/Noise.h b/Utilities/otbossimplugins/ossim/otb/Noise.h index ddedea5c06adfc45f031977da2af9c9b81f8a69b..f6d6ff303b74e55b65e393a7102c37ea5f214eef 100644 --- a/Utilities/otbossimplugins/ossim/otb/Noise.h +++ b/Utilities/otbossimplugins/ossim/otb/Noise.h @@ -76,6 +76,11 @@ public: { _tabImageNoise = image_noise; } + + const std::vector<ImageNoise> & get_imageNoise() const + { + return _tabImageNoise; + } protected: