diff --git a/Code/Radiometry/otbSarBrightnessFunction.h b/Code/Radiometry/otbSarBrightnessFunction.h new file mode 100644 index 0000000000000000000000000000000000000000..c7aa67e54f42a73cf1be5894b8c61b68ff66921b --- /dev/null +++ b/Code/Radiometry/otbSarBrightnessFunction.h @@ -0,0 +1,156 @@ +/*========================================================================= + + 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 __otbSarBrightnessFunction_h +#define __otbSarBrightnessFunction_h + +#include "itkNumericTraits.h" +#include "itkImageFunction.h" +#include "otbSarBrightnessFunctor.h" +#include "otbSarParametricMapFunction.h" + + +namespace otb +{ + +/** + * \class SarBrightnessFunction + * \brief Calculate the backscatter for the given pixel + * + * Calculate the brigthness value for the given pixel + * + * If called with a ContinuousIndex or Point, the calculation is performed + * at the nearest neighbor. + * + * This class is templated over the input image type and the + * coordinate representation type (e.g. float or double ). + * + * \ingroup ImageFunctions + */ + +template <class TInputImage, class TCoordRep = float> +class ITK_EXPORT SarBrightnessFunction : + public itk::ImageFunction<TInputImage, typename itk::NumericTraits<typename TInputImage::PixelType>::AbsType, + TCoordRep> +{ +public: + /** Standard class typedefs. */ + typedef SarBrightnessFunction Self; + typedef itk::ImageFunction<TInputImage, typename itk::NumericTraits<typename TInputImage::PixelType>::AbsType, + TCoordRep> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(SarBrightnessFunction, itk::ImageFunction); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** InputImageType typedef support. */ + typedef TInputImage InputImageType; + typedef typename InputImageType::PixelType InputPixelType; + typedef typename Superclass::OutputType OutputType; + typedef typename Superclass::IndexType IndexType; + typedef typename Superclass::ContinuousIndexType ContinuousIndexType; + typedef typename Superclass::PointType PointType; + + itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension); + + + /** Datatype used for the evaluation */ + typedef double RealType; + typedef otb::Functor::SarBrightnessFunctor<RealType,RealType> FunctorType; + typedef typename FunctorType::RealType FunctorRealType; + + typedef otb::SarParametricMapFunction<InputImageType> ParametricFunctionType; + typedef typename ParametricFunctionType::Pointer ParametricFunctionPointer; + typedef typename ParametricFunctionType::ConstPointer ParametricFunctionConstPointer; + + /** Evalulate the function at specified index */ + virtual OutputType EvaluateAtIndex(const IndexType& index) const; + + /** Evaluate the function at non-integer positions */ + virtual OutputType Evaluate(const PointType& point) const + { + IndexType index; + this->ConvertPointToNearestIndex(point, index); + return this->EvaluateAtIndex(index); + } + virtual OutputType EvaluateAtContinuousIndex( + const ContinuousIndexType& cindex) const + { + IndexType index; + this->ConvertContinuousIndexToNearestIndex(cindex, index); + return this->EvaluateAtIndex(index); + } + + /** Set the input image. + * \warning this method caches BufferedRegion information. + * If the BufferedRegion has changed, user must call + * SetInputImage again to update cached values. */ + virtual void SetInputImage( const InputImageType * ptr ); + + + /** Get/Set the Scale value */ + itkSetMacro(Scale, FunctorRealType); + itkGetMacro(Scale, FunctorRealType); + + /** Get/Set the Offset value */ + itkSetObjectMacro(Noise, ParametricFunctionType); + itkGetConstObjectMacro(Noise, ParametricFunctionType); + itkGetObjectMacro(Noise, ParametricFunctionType); + + /** Get/Set the AntennaPatternNewGain value */ + itkSetObjectMacro(AntennaPatternNewGain, ParametricFunctionType); + itkGetConstObjectMacro(AntennaPatternNewGain, ParametricFunctionType); + itkGetObjectMacro(AntennaPatternNewGain, ParametricFunctionType); + + /** Get/Set the AntennaPatternOldGain value */ + itkSetObjectMacro(AntennaPatternOldGain, ParametricFunctionType); + itkGetObjectMacro(AntennaPatternOldGain, ParametricFunctionType); + itkGetConstObjectMacro(AntennaPatternOldGain, ParametricFunctionType); + + /** Get/Set the RangeSpreadLoss value */ + itkSetObjectMacro(RangeSpreadLoss, ParametricFunctionType); + itkGetConstObjectMacro(RangeSpreadLoss, ParametricFunctionType); + itkGetObjectMacro(RangeSpreadLoss, ParametricFunctionType); + + +protected: + SarBrightnessFunction(); + virtual ~SarBrightnessFunction(){} + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + SarBrightnessFunction(const Self &); //purposely not implemented + void operator =(const Self&); //purposely not implemented + + FunctorRealType m_Scale; + ParametricFunctionPointer m_Noise; + ParametricFunctionPointer m_AntennaPatternNewGain; + ParametricFunctionPointer m_AntennaPatternOldGain; + ParametricFunctionPointer m_RangeSpreadLoss; +}; + +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +# include "otbSarBrightnessFunction.txx" +#endif + +#endif diff --git a/Code/Radiometry/otbSarBrightnessFunction.txx b/Code/Radiometry/otbSarBrightnessFunction.txx new file mode 100644 index 0000000000000000000000000000000000000000..ace8a2f810a8fe66ebc5ef3800b928dffcbad952 --- /dev/null +++ b/Code/Radiometry/otbSarBrightnessFunction.txx @@ -0,0 +1,123 @@ +/*========================================================================= + + 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 __otbSarBrightnessFunction_txx +#define __otbSarBrightnessFunction_txx + +#include "otbSarBrightnessFunction.h" +#include "otbSarParametricMapFunction.h" +#include "itkNumericTraits.h" + +namespace otb +{ + +/** + * Constructor + */ +template <class TInputImage, class TCoordRep> +SarBrightnessFunction<TInputImage, TCoordRep> +::SarBrightnessFunction(): + m_Scale(1.0) +{ + m_Noise = ParametricFunctionType::New(); + m_AntennaPatternNewGain = ParametricFunctionType::New(); + m_AntennaPatternOldGain = ParametricFunctionType::New(); + m_RangeSpreadLoss = ParametricFunctionType::New(); + + m_Noise->SetConstantValue(0.0); + m_AntennaPatternNewGain->SetConstantValue(1.0); + m_AntennaPatternOldGain->SetConstantValue(1.0); + m_RangeSpreadLoss->SetConstantValue(1.0); +} + +/** + * Initialize by setting the input image + */ +template <class TInputImage, class TCoordRep> +void +SarBrightnessFunction<TInputImage, TCoordRep> +::SetInputImage( + const InputImageType * ptr ) +{ + Superclass::SetInputImage(ptr); + m_Noise->SetInputImage(ptr); + m_AntennaPatternNewGain->SetInputImage(ptr); + m_AntennaPatternOldGain->SetInputImage(ptr); + m_RangeSpreadLoss->SetInputImage(ptr); +} + +/** + * + */ +template <class TInputImage, class TCoordRep> +void +SarBrightnessFunction<TInputImage, TCoordRep> +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + this->Superclass::PrintSelf(os, indent); +} + +/** + * + */ +template <class TInputImage, class TCoordRep> +typename SarBrightnessFunction<TInputImage, TCoordRep> +::OutputType +SarBrightnessFunction<TInputImage, TCoordRep> +::EvaluateAtIndex(const IndexType& index) const +{ + RealType result; + result = itk::NumericTraits<RealType>::Zero; + + if (!this->GetInputImage()) + { + return (itk::NumericTraits<OutputType>::max()); + } + + if (!this->IsInsideBuffer(index)) + { + return (itk::NumericTraits<OutputType>::max()); + } + + + FunctorRealType noise; + FunctorRealType antennaPatternNewGain; + FunctorRealType antennaPatternOldGain; + FunctorRealType rangeSpreadLoss; + + noise = static_cast<FunctorRealType>(m_Noise->EvaluateAtIndex(index)); + antennaPatternNewGain = static_cast<FunctorRealType>(m_AntennaPatternNewGain->EvaluateAtIndex(index)); + antennaPatternOldGain = static_cast<FunctorRealType>(m_AntennaPatternOldGain->EvaluateAtIndex(index)); + rangeSpreadLoss = static_cast<FunctorRealType>(m_RangeSpreadLoss->EvaluateAtIndex(index)); + + FunctorType functor; + functor.SetNoise(noise); + functor.SetScale(m_Scale); + functor.SetAntennaPatternNewGain(antennaPatternNewGain); + functor.SetAntennaPatternOldGain(antennaPatternOldGain); + functor.SetRangeSpreadLoss(rangeSpreadLoss); + + const RealType value = static_cast<RealType>(vcl_abs(this->GetInputImage()->GetPixel(index))); + result = functor(value); + + return static_cast<OutputType>(result); +} + +} // end namespace otb + +#endif diff --git a/Code/Radiometry/otbSarBrightnessFunctor.h b/Code/Radiometry/otbSarBrightnessFunctor.h new file mode 100644 index 0000000000000000000000000000000000000000..c62eec3bc7208fdf3d856d24f4cfb1ae46e57a6a --- /dev/null +++ b/Code/Radiometry/otbSarBrightnessFunctor.h @@ -0,0 +1,144 @@ +/*========================================================================= + + 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 __otbSarBrightnessFunctor_h +#define __otbSarBrightnessFunctor_h + +#include "otbMath.h" +#include "itkNumericTraits.h" + +namespace otb +{ + +namespace Functor +{ +/** + * \class SarBrightnessFunctor + * \brief Compute the brightness value. + * \f$ \beta^{0} = (scale * DN^{2} + offset) * OldGain / NewGain * RangeSpreadLoss \f$ + * + */ +template<class TInput, class TOutput> +class ITK_EXPORT SarBrightnessFunctor +{ +public: + typedef TInput InputType; + typedef TOutput OutputType; + typedef typename itk::NumericTraits<InputType>::AbsType RealType; + + SarBrightnessFunctor() + { + m_Noise = 0.0; + m_Scale = 1.0; + m_AntennaPatternOldGain = 1.0; + m_AntennaPatternNewGain = 1.0; + m_RangeSpreadLoss = 1.0; + }; + + ~SarBrightnessFunctor(){}; + + inline TOutput operator ()(const TInput& value) const + { + RealType digitalNumber = static_cast<RealType> (vcl_abs(value)); + RealType beta; + + beta = m_Scale * (digitalNumber * digitalNumber - m_Noise); + beta *= m_AntennaPatternOldGain; + beta /= m_AntennaPatternNewGain; + beta *= m_RangeSpreadLoss; + + if(beta < 0.0) + { + beta = 0.0; + } + + return static_cast<OutputType>(beta); + } + + /** Set offset method */ + void SetNoise(RealType value) + { + m_Noise = value; + } + + /** Get offset method */ + RealType GetNoise() const + { + return m_Noise; + } + + /** Set scale method */ + void SetScale(RealType value) + { + m_Scale = value; + } + + /** Get scale method */ + RealType GetScale() const + { + return m_Scale; + } + + /** Set antennaPatternNewGain method */ + void SetAntennaPatternNewGain(RealType value) + { + m_AntennaPatternNewGain = value; + } + + /** Get antennaPatternNewGain method */ + RealType GetAntennaPatternNewGain() const + { + return m_AntennaPatternNewGain; + } + + /** Set antennaPatternOldGain method */ + void SetAntennaPatternOldGain(RealType value) + { + m_AntennaPatternOldGain = value; + } + + /** Get antennaPatternOldGain method */ + RealType GetAntennaPatternOldGain() const + { + return m_AntennaPatternOldGain; + } + + /** Set rangeSpreadLoss method */ + void SetRangeSpreadLoss(RealType value) + { + m_RangeSpreadLoss = value; + } + + /** Get scale method */ + RealType GetRangeSpreadLoss() const + { + return m_RangeSpreadLoss; + } + +private: + RealType m_Noise; + RealType m_Scale; + RealType m_AntennaPatternNewGain; + RealType m_AntennaPatternOldGain; + RealType m_RangeSpreadLoss; +}; +} + +} + +#endif diff --git a/Code/Radiometry/otbSarBrightnessToImageFilter.h b/Code/Radiometry/otbSarBrightnessToImageFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..7ee3b2d35857b6bca1295397883fce818cd11c38 --- /dev/null +++ b/Code/Radiometry/otbSarBrightnessToImageFilter.h @@ -0,0 +1,95 @@ +/*========================================================================= + + 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 __otbSarBrightnessToImageFilter_h +#define __otbSarBrightnessToImageFilter_h + +#include "otbSarBrightnessFunction.h" +#include "otbFunctionToImageFilter.h" + +namespace otb +{ + +/** \class SarBrightnessToImageFilter + * \brief Evaluates the SarBrightnessFunction onto a source image + * + * The function has to inherit from itkImageFunction + * + * \ingroup ImageFilters + */ + +template <class TInputImage, class TOutputImage> +class ITK_EXPORT SarBrightnessToImageFilter : + public FunctionToImageFilter<TInputImage, TOutputImage, + SarBrightnessFunction<TInputImage> > +{ +public: + /** Standard class typedefs. */ + typedef SarBrightnessToImageFilter Self; + typedef FunctionToImageFilter<TInputImage, TOutputImage, + SarBrightnessFunction<TInputImage> > Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(SarBrightnessToImageFilter, FunctionToImageFilter); + + /** Some typedefs. */ + /** Image size typedef. */ + typedef typename Superclass::InputImageType InputImageType; + typedef typename Superclass::InputImagePointer InputImagePointer; + typedef typename Superclass::InputImageRegionType InputImageRegionType; + typedef typename Superclass::InputImagePixelType InputImagePixelType; + typedef typename Superclass::OutputImageType OutputImageType; + typedef typename Superclass::OutputImagePointer OutputImagePointer; + typedef typename Superclass::OutputImageRegionType OutputImageRegionType; + typedef typename Superclass::OutputImagePixelType OutputImagePixelType; + /** Type of function. */ + + typedef typename Superclass::FunctionType FunctionType; + typedef typename Superclass::FunctionPointer FunctionPointer; + typedef typename Superclass::FunctionValueType FunctionValueType; + typedef typename Superclass::FunctionPositionType FunctionPositionType; + typedef typename FunctionType::ParametricFunctionPointer ParametricFunctionPointer; + typedef typename FunctionType::ParametricFunctionConstPointer ParametricFunctionConstPointer; + typedef typename FunctionType::ParametricFunctionType ParametricFunctionType; + +protected: + SarBrightnessToImageFilter(); + virtual ~SarBrightnessToImageFilter() {} + + /** Update the function list and input parameters*/ + virtual void BeforeThreadedGenerateData(); +private: + SarBrightnessToImageFilter(const Self &); //purposely not implemented + void operator =(const Self&); //purposely not implemented + +}; + +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbSarBrightnessToImageFilter.txx" +#endif + +#endif diff --git a/Code/Radiometry/otbSarBrightnessToImageFilter.txx b/Code/Radiometry/otbSarBrightnessToImageFilter.txx new file mode 100644 index 0000000000000000000000000000000000000000..a97f7fea3181d5c5b2c8c4f34c750c9c2dd78892 --- /dev/null +++ b/Code/Radiometry/otbSarBrightnessToImageFilter.txx @@ -0,0 +1,85 @@ +/*========================================================================= + + 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 __otbSarBrightnessToImageFilter_txx +#define __otbSarBrightnessToImageFilter_txx + +#include "otbSarBrightnessToImageFilter.h" + +#include "otbSarImageMetadataInterface.h" +#include "otbSarImageMetadataInterfaceFactory.h" + +namespace otb +{ + +/** + * Constructor + */ +template<class TInputImage, class TOutputImage> +SarBrightnessToImageFilter<TInputImage, TOutputImage> +::SarBrightnessToImageFilter() +{ +} + +template<class TInputImage, class TOutputImage> +void +SarBrightnessToImageFilter<TInputImage, TOutputImage> +::BeforeThreadedGenerateData() +{ + // will SetInputImage on the function + Superclass::BeforeThreadedGenerateData(); + + SarImageMetadataInterface::Pointer imageMetadataInterface = SarImageMetadataInterfaceFactory::CreateIMI( + this->GetInput()->GetMetaDataDictionary()); + + FunctionPointer function = this->GetFunction(); + + function->SetScale(imageMetadataInterface->GetRadiometricCalibrationScale()); + + ParametricFunctionPointer noise; + ParametricFunctionPointer antennaPatternNewGain; + ParametricFunctionPointer antennaPatternOldGain; + ParametricFunctionPointer rangeSpreadLoss; + + noise = function->GetNoise(); + noise->SetPointSet(imageMetadataInterface->GetRadiometricCalibrationNoise()); + noise->SetPolynomalSize(imageMetadataInterface->GetRadiometricCalibrationNoisePolynomialDegree()); + noise->EvaluateParametricCoefficient(); + + antennaPatternNewGain = function->GetAntennaPatternNewGain(); + antennaPatternNewGain->SetPointSet(imageMetadataInterface->GetRadiometricCalibrationAntennaPatternNewGain()); + antennaPatternNewGain->SetPolynomalSize(imageMetadataInterface->GetRadiometricCalibrationAntennaPatternNewGainPolynomialDegree()); + antennaPatternNewGain->EvaluateParametricCoefficient(); + + antennaPatternOldGain = function->GetAntennaPatternOldGain(); + antennaPatternOldGain->SetPointSet(imageMetadataInterface->GetRadiometricCalibrationAntennaPatternOldGain()); + antennaPatternOldGain->SetPolynomalSize(imageMetadataInterface->GetRadiometricCalibrationAntennaPatternOldGainPolynomialDegree()); + antennaPatternOldGain->EvaluateParametricCoefficient(); + + rangeSpreadLoss = function->GetRangeSpreadLoss(); + rangeSpreadLoss->SetPointSet(imageMetadataInterface->GetRadiometricCalibrationRangeSpreadLoss()); + rangeSpreadLoss->SetPolynomalSize(imageMetadataInterface->GetRadiometricCalibrationRangeSpreadLossPolynomialDegree()); + rangeSpreadLoss->EvaluateParametricCoefficient(); +} + + +} // end namespace otb + +#endif diff --git a/Testing/Code/Radiometry/CMakeLists.txt b/Testing/Code/Radiometry/CMakeLists.txt index ca69e7980dd84c11e907b4a1c089d48c781dc511..709247c0279410a6a01070f9f3497fb6801520a0 100644 --- a/Testing/Code/Radiometry/CMakeLists.txt +++ b/Testing/Code/Radiometry/CMakeLists.txt @@ -1438,25 +1438,11 @@ ADD_TEST(raTvTerraSarBrightnessImageComplexFilterTORONTO ${RADIOMETRY_TESTS9} ) ENDIF(OTB_DATA_USE_LARGEINPUT) -# ------- SarRadiometricCalibrationFunctor ------------------------------ -ADD_TEST(raTuSarRadiometricCalibrationFunctor ${RADIOMETRY_TESTS9} - otbSarRadiometricCalibrationFunctor -) -# ------- SarRadiometricCalibrationFunction ------------------------------ -ADD_TEST(raTvSarRadiometricCalibrationFunction ${RADIOMETRY_TESTS9} -#--compare-ascii ${NOTOL} -# ${BASELINE_FILES}/bfTvBinaryImageDensityFunctionOutputAscii.txt -# ${TEMP}/bfTvBinaryImageDensityFunctionOutputAscii.txt - otbSarRadiometricCalibrationFunction - ${INPUTDATA}/scene.png - ${TEMP}/raTvSarRadiometricCalibrationFunctionOutputAscii.txt -) - # ------- SarRadiometricCalibrationFunction ------------------------------ ADD_TEST(raTuSarParametricMapFunction ${RADIOMETRY_TESTS9} -#--compare-ascii ${NOTOL} -# ${BASELINE_FILES}/bfTvBinaryImageDensityFunctionOutputAscii.txt -# ${TEMP}/bfTvBinaryImageDensityFunctionOutputAscii.txt +# --compare-ascii ${NOTOL} +# ${BASELINE_FILES}/raTvSarParametricMapFunctionOutputAscii.txt +# ${TEMP}/raTvSarParametricMapFunctionOutputAscii.txt otbSarParametricMapFunctionTest ${INPUTDATA}/scene.png ${TEMP}/raTvSarParametricMapFunctionOutputAscii.txt @@ -1470,21 +1456,70 @@ ADD_TEST(raTvSarParametricMapFunctionToImageFilter ${RADIOMETRY_TESTS9} ${TEMP}/raTvSarParametricMapFunctionToImageFilter.tif ) -IF(OTB_DATA_USE_LARGEINPUT) +# ------- SarRadiometricCalibrationFunctor ------------------------------ +ADD_TEST(raTuSarRadiometricCalibrationFunctor ${RADIOMETRY_TESTS9} + otbSarRadiometricCalibrationFunctor +) +# ------- SarRadiometricCalibrationFunction ------------------------------ +ADD_TEST(raTvSarRadiometricCalibrationFunction ${RADIOMETRY_TESTS9} + --compare-ascii ${NOTOL} + ${BASELINE_FILES}/raTvSarRadiometricCalibrationFunctionOutputAscii.txt + ${TEMP}/raTvSarRadiometricCalibrationFunctionOutputAscii.txt + otbSarRadiometricCalibrationFunction + ${INPUTDATA}/scene.png + ${TEMP}/raTvSarRadiometricCalibrationFunctionOutputAscii.txt +) + +# ------- SarRadiometricCalibrationToImageFilter ------------------------------ + +IF(OTB_DATA_USE_LARGEINPUT) ADD_TEST(raTvSarRadiometricCalibrationToImageFilter ${RADIOMETRY_TESTS9} -# --compare-image ${EPSILON_7} -# ${BASELINE}/bfTvFunctionToImageFilterTest.tif -# ${TEMP}/bfTvFunctionToImageFilterTest.tif + --compare-image ${EPSILON} + ${BASELINE}/raTvSarRadiometricCalibrationToImageFilter_TSX_PANGKALANBUUN_HH.tif + ${TEMP}/raTvSarRadiometricCalibrationToImageFilter_TSX_PANGKALANBUUN_HH.tif otbSarRadiometricCalibrationToImageFilterTest ${LARGEINPUT}/TERRASARX/PANGKALANBUUN/IMAGEDATA/IMAGE_HH_SRA_stripFar_008.cos ${TEMP}/raTvSarRadiometricCalibrationToImageFilter_TSX_PANGKALANBUUN_HH.tif 1000 1000 250 250 # Extract ) +ENDIF(OTB_DATA_USE_LARGEINPUT) + +# ------- SarBrightnessFunctor ------------------------------ +ADD_TEST(raTuSarBrightnessFunctor ${RADIOMETRY_TESTS9} + otbSarBrightnessFunctor +) + +# ------- SarBrightnessFunction ------------------------------ +ADD_TEST(raTvSarBrightnessFunction ${RADIOMETRY_TESTS9} + --compare-ascii ${NOTOL} + ${BASELINE_FILES}/raTvSarBrightnessFunctionOutputAscii.txt + ${TEMP}/raTvSarBrightnessFunctionOutputAscii.txt + otbSarBrightnessFunction + ${INPUTDATA}/scene.png + ${TEMP}/raTvSarBrightnessFunctionOutputAscii.txt +) +# ------- SarBrightnessToImageFilter ------------------------------ +IF(OTB_DATA_USE_LARGEINPUT) +ADD_TEST(raTvSarBrightnessToImageFilter ${RADIOMETRY_TESTS9} + --compare-image ${EPSILON} + ${BASELINE}/raTvSarBrightnessToImageFilter_TSX_PANGKALANBUUN_HH.tif + ${TEMP}/raTvSarBrightnessToImageFilter_TSX_PANGKALANBUUN_HH.tif + otbSarBrightnessToImageFilterTest + ${LARGEINPUT}/TERRASARX/PANGKALANBUUN/IMAGEDATA/IMAGE_HH_SRA_stripFar_008.cos + ${TEMP}/raTvSarBrightnessToImageFilter_TSX_PANGKALANBUUN_HH.tif + 1000 1000 250 250 # Extract +) ENDIF(OTB_DATA_USE_LARGEINPUT) + + + + + + # A enrichir SET(Radiometry_SRCS1 otbRadiometryTests1.cxx @@ -1586,11 +1621,14 @@ otbTerraSarBrightnessFunctor.cxx otbTerraSarBrightnessImageFilterNew.cxx otbTerraSarBrightnessImageFilterTest.cxx otbTerraSarBrightnessImageComplexFilterTest.cxx -otbSarRadiometricCalibrationFunctor.cxx -otbSarRadiometricCalibrationFunction.cxx otbSarParametricMapFunctionTest.cxx otbSarParametricMapFunctionToImageFilter.cxx +otbSarRadiometricCalibrationFunctor.cxx +otbSarRadiometricCalibrationFunction.cxx otbSarRadiometricCalibrationToImageFilterTest.cxx +otbSarBrightnessFunctor.cxx +otbSarBrightnessFunction.cxx +otbSarBrightnessToImageFilterTest.cxx ) diff --git a/Testing/Code/Radiometry/otbRadiometryTests9.cxx b/Testing/Code/Radiometry/otbRadiometryTests9.cxx index bba418d1c3f6df17be0a9371d1c3f3f64b09cf87..2ffab8e64c390898d7303f02f02f0e8d14482f49 100644 --- a/Testing/Code/Radiometry/otbRadiometryTests9.cxx +++ b/Testing/Code/Radiometry/otbRadiometryTests9.cxx @@ -34,9 +34,12 @@ void RegisterTests() REGISTER_TEST(otbTerraSarBrightnessImageFilterNew); REGISTER_TEST(otbTerraSarBrightnessImageFilterTest); REGISTER_TEST(otbTerraSarBrightnessImageComplexFilterTest); - REGISTER_TEST(otbSarRadiometricCalibrationFunctor); - REGISTER_TEST(otbSarRadiometricCalibrationFunction); REGISTER_TEST(otbSarParametricMapFunctionTest); REGISTER_TEST(otbSarParametricMapFunctionToImageFilter); + REGISTER_TEST(otbSarRadiometricCalibrationFunctor); + REGISTER_TEST(otbSarRadiometricCalibrationFunction); REGISTER_TEST(otbSarRadiometricCalibrationToImageFilterTest); + REGISTER_TEST(otbSarBrightnessFunctor); + REGISTER_TEST(otbSarBrightnessFunction); + REGISTER_TEST(otbSarBrightnessToImageFilterTest); } diff --git a/Testing/Code/Radiometry/otbSarBrightnessFunction.cxx b/Testing/Code/Radiometry/otbSarBrightnessFunction.cxx new file mode 100644 index 0000000000000000000000000000000000000000..8fc2007a13abab22ca83e26bfc033b763a988b8d --- /dev/null +++ b/Testing/Code/Radiometry/otbSarBrightnessFunction.cxx @@ -0,0 +1,71 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#include "otbSarBrightnessFunction.h" + +#include "otbImage.h" +#include "otbImageFileReader.h" +#include <iostream> + +int otbSarBrightnessFunction(int argc, char* argv[]) +{ + + const char * infname = argv[1]; + const char * outfname = argv[2]; + + const unsigned int Dimension = 2; + typedef float PixelType; + + typedef otb::Image<PixelType, Dimension> InputImageType; + typedef InputImageType::IndexType IndexType; + typedef otb::ImageFileReader<InputImageType> ReaderType; + typedef otb::SarBrightnessFunction<InputImageType> FunctionType; + + /**Instantiation ofa Smart Pointer*/ + FunctionType::Pointer filter = FunctionType::New(); + ReaderType::Pointer reader = ReaderType::New(); + + std::ofstream outfile(outfname); + + /** Input Image*/ + reader->SetFileName(infname); + reader->Update(); + + /** Computing the density around a pixel */ + filter->SetInputImage(reader->GetOutput()); + + /** Test on some indexes and some physical coordinates*/ + InputImageType::SizeType size = reader->GetOutput()->GetRequestedRegion().GetSize(); + FunctionType::PointType pDst; + IndexType index; + + index[0] = 0; + index[1] = 0; + outfile << "Sar Brightness value computed for the point : " << index << " is " << filter->EvaluateAtIndex(index) << std::endl; + + index[0] = static_cast<unsigned int>(size[0] / 2.); + index[1] = static_cast<unsigned int>(size[1] / 4.); + outfile << "Sar Radiometric Calibration computed for the point : " << index << " is " << filter->EvaluateAtIndex(index) << std::endl; + + pDst[0] = static_cast<unsigned int>(size[0] / 4.); + pDst[1] = static_cast<unsigned int>(size[1] / 8.); + outfile << "Sar Brightness computed for the point : " << pDst << " is " << filter->Evaluate(pDst) << std::endl; + + outfile.close(); + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/Radiometry/otbSarBrightnessFunctor.cxx b/Testing/Code/Radiometry/otbSarBrightnessFunctor.cxx new file mode 100644 index 0000000000000000000000000000000000000000..00dd7a50054b746663659a0950139032dc0e3f3b --- /dev/null +++ b/Testing/Code/Radiometry/otbSarBrightnessFunctor.cxx @@ -0,0 +1,61 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#include "itkExceptionObject.h" + +#include "otbSarBrightnessFunctor.h" + +int otbSarBrightnessFunctor(int argc, char * argv[]) +{ + typedef double ScalarType; + + typedef otb::Functor::SarBrightnessFunctor<ScalarType, ScalarType> FunctorType; + + FunctorType funct; + + funct.SetNoise( 10.0); + if( abs(funct.GetNoise() -10.0) > 0.0) + { + return false; + } + funct.SetScale( 10.0); + if( abs(funct.GetScale() -10.0) > 0.0) + { + return false; + } + funct.SetAntennaPatternNewGain( 10.0); + if( abs(funct.GetAntennaPatternNewGain() -10.0) > 0.0) + { + return false; + } + funct.SetAntennaPatternOldGain( 10.0); + if( abs(funct.GetAntennaPatternOldGain() -10.0) > 0.0) + { + return false; + } + + funct.SetRangeSpreadLoss( 10.0); + if( abs(funct.GetRangeSpreadLoss() -10.0) > 0.0) + { + return false; + } + std::cout << "First BetaNaught : " << funct.operator ()( 0.) << std::endl; + std::cout << "Second BetaNaught : " << funct.operator ()( 1.) << std::endl; + + + return EXIT_SUCCESS; +} diff --git a/Testing/Code/Radiometry/otbSarBrightnessToImageFilterTest.cxx b/Testing/Code/Radiometry/otbSarBrightnessToImageFilterTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..ec0d55423d2652194b65d5f1374310b98074cf11 --- /dev/null +++ b/Testing/Code/Radiometry/otbSarBrightnessToImageFilterTest.cxx @@ -0,0 +1,71 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +#include "otbImage.h" +#include "otbSarBrightnessToImageFilter.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "itkExtractImageFilter.h" + +int otbSarBrightnessToImageFilterTest(int argc, char * argv[]) +{ + const unsigned int Dimension = 2; + typedef float RealType; + //typedef std::complex<RealType> PixelType; + typedef RealType PixelType; + typedef otb::Image<PixelType, Dimension> InputImageType; + typedef otb::Image<RealType, Dimension> OutputImageType; + typedef otb::ImageFileReader<InputImageType> ReaderType; + typedef otb::ImageFileWriter<OutputImageType> WriterType; + typedef otb::SarBrightnessToImageFilter<InputImageType, OutputImageType> FilterType; + typedef itk::ExtractImageFilter<OutputImageType, OutputImageType> ExtractorType; + + // Instantiating object + FilterType::Pointer filter = FilterType::New(); + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + ExtractorType::Pointer extractor = ExtractorType::New(); + + reader->SetFileName(argv[1]); + writer->SetFileName(argv[2]); + filter->SetInput(reader->GetOutput()); + + if (argc > 3) + { + // Generate an extract from the large input + OutputImageType::RegionType region; + OutputImageType::IndexType id; + id[0] = atoi(argv[3]); id[1] = atoi(argv[4]); + OutputImageType::SizeType size; + size[0] = atoi(argv[5]); size[1] = atoi(argv[6]); + region.SetIndex(id); + region.SetSize(size); + extractor->SetExtractionRegion(region); + + extractor->SetInput(filter->GetOutput()); + writer->SetInput(extractor->GetOutput()); + } + else + { + // Calibrate the whole image + writer->SetInput(filter->GetOutput()); + } + writer->Update(); + + return EXIT_SUCCESS; +}