diff --git a/Code/BasicFilters/otbMatrixTransposeMatrixImageFilter.txx b/Code/BasicFilters/otbMatrixTransposeMatrixImageFilter.txx index b6b5e8ee0d60fab49a990703e96e70133822a8da..50cf409e669de43c2dcd7992098880203a855e48 100644 --- a/Code/BasicFilters/otbMatrixTransposeMatrixImageFilter.txx +++ b/Code/BasicFilters/otbMatrixTransposeMatrixImageFilter.txx @@ -220,7 +220,7 @@ MatrixTransposeMatrixImageFilter<TInputImage, TInputImage2> for( unsigned int thread = 0; thread < numberOfThreads; thread++) { /** TODO - * A modifier en utilisant l'opérateur + de la méthode. Pour le moment probleme avec exceptionmacro (pas de GetClassName...) + * To modify using + method operator. If we use it now -> exceptionmacro (no GetClassName...) * resultMatrix += m_ThreadSum[thread]; **/ for (unsigned int i=0; i<resultMatrix.Rows(); i++) @@ -274,14 +274,6 @@ MatrixTransposeMatrixImageFilter<TInputImage, TInputImage2> } otbMsgDebugMacro(<<"ThreadedGenerateData() - thread "<<threadId <<" - nb of divisions: "<<numDivisions); - /* - unsigned int numberOfComponents1 = this->GetFirstInput()->GetNumberOfComponentsPerPixel(); - unsigned int numberOfComponents2 = this->GetSecondInput()->GetNumberOfComponentsPerPixel(); - - MatrixType result; - result.SetSize(numberOfComponents1, numberOfComponents2); - result.Fill(itk::NumericTraits<RealType>::Zero); - */ /** * Loop over the number of pieces, execute the upstream pipeline on each diff --git a/Code/BasicFilters/otbStreamingStatisticsVectorImageFilter.txx b/Code/BasicFilters/otbStreamingStatisticsVectorImageFilter.txx index aef0e7f995b9b653bdf2441133e4c9017751a566..43b0be4ba7b876be90489d98cae7c24800378218 100644 --- a/Code/BasicFilters/otbStreamingStatisticsVectorImageFilter.txx +++ b/Code/BasicFilters/otbStreamingStatisticsVectorImageFilter.txx @@ -325,7 +325,7 @@ StreamingStatisticsVectorImageFilter<TInputImage> { count += m_Count[i]; /** TODO - * A modifier en utilisant l'opérateur + de la méthode. Pour le moment probleme avec exceptionmacro (pas de GetClassName...) + * To modify using + method operator. If we use it now -> exceptionmacro (no GetClassName...) * crossedMatrix += m_XX[i]; **/ if( (m_XX[i].Rows() != crossedMatrix.Rows()) || (m_XX[i].Cols() != crossedMatrix.Cols())) diff --git a/Code/Fusion/otbBayesianFusionFilter.txx b/Code/Fusion/otbBayesianFusionFilter.txx index 60f991d370efad82d60c9166f8ad36251dc723f0..668d6ef798f07f83e3d15edac2b2f7ed3e2fd01d 100755 --- a/Code/Fusion/otbBayesianFusionFilter.txx +++ b/Code/Fusion/otbBayesianFusionFilter.txx @@ -135,7 +135,7 @@ namespace otb tempS = tempS*m_Beta; /** TODO - * A modifier en utilisant l'opérateur - de la méthode. Pour le moment probleme avec exceptionmacro (pas de GetClassName...) + * To modify using - method operator. If we use it now -> exceptionmacro (no GetClassName...) * S = S-tempS; **/ if( (S.Rows() != tempS.Rows()) || (S.Cols() != tempS.Cols())) @@ -157,8 +157,8 @@ namespace otb tempS2 = msTransposePan->GetResultOutput()->Get(); tempS = tempS*tempS2; /** TODO - * A modifier en utilisant l'opérateur + de la méthode. Pour le moment probleme avec exceptionmacro (pas de GetClassName...) - * S = S-tempS; + * To modify using - method operator. If we use it now -> exceptionmacro (no GetClassName...) + * S = S-tempS; **/ if( (S.Rows() != tempS.Rows()) || (S.Cols() != tempS.Cols()) ) { @@ -184,7 +184,7 @@ namespace otb xxTbT = xxTb.GetTranspose(); xxTbTb = xxTbT*m_Beta; /** TODO - * A modifier en utilisant l'opérateur + de la méthode. Pour le moment probleme avec exceptionmacro (pas de GetClassName...) + * To modify using - method operator. If we use it now -> exceptionmacro (no GetClassName...) * S = S-xxTbTb; **/ if( (S.Cols() != xxTbTb.Cols()) || (S.Cols() != xxTbTb.Cols()) ) @@ -240,8 +240,8 @@ namespace otb } /** TODO - * A modifier en utilisant l'opérateur + de la méthode. Pour le moment probleme avec exceptionmacro (pas de GetClassName...) - * m_Vcondopt = 2 *m_Lambda*varPan+2*m_CovarianceInvMatrix*(1-m_Lambda)+eye; + * To modify using + method operator. If we use it now -> exceptionmacro (no GetClassName...) + * m_Vcondopt = 2 *m_Lambda*varPan+2*m_CovarianceInvMatrix*(1-m_Lambda)+eye; **/ if( (m_Vcondopt.Cols() != varPan.Cols()) || (m_Vcondopt.Cols() != varPan.Cols()) || (m_Vcondopt.Cols() != m_CovarianceInvMatrix.Cols()) || (m_Vcondopt.Cols() != m_CovarianceInvMatrix.Cols())) diff --git a/Code/Radiometry/otbVegetationIndex.h b/Code/Radiometry/otbVegetationIndex.h index 581ec461128e8c17849ad8b9b0fcdb7f689e7cd7..2d9b4e71f3efca07bb091d9e467ba0c755f95830 100644 --- a/Code/Radiometry/otbVegetationIndex.h +++ b/Code/Radiometry/otbVegetationIndex.h @@ -78,7 +78,7 @@ namespace Functor * * [Richardson et Wiegand, 1977] * - * \ingroup Functor + * \ingroup Functor2 */ template <class TInput1, class TInput2, class TOutput> class PVI diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt index 4e527e486a3a787b54eea5eefadfb33a64af3bba..6f3f3cd3a91bcf4b3a28416e5cad81b1862902f4 100644 --- a/Examples/CMakeLists.txt +++ b/Examples/CMakeLists.txt @@ -20,6 +20,8 @@ SUBDIRS( DisparityMap Projections Registration + Radiometry + Fusion Tutorials ) @@ -73,6 +75,8 @@ ELSE(OTB_BINARY_DIR) MultiScale DisparityMap Registration + Radiometry + Fusion Tutorials ) diff --git a/Examples/Data/NDVI_2 b/Examples/Data/NDVI_2 new file mode 100644 index 0000000000000000000000000000000000000000..31f456a29b84fc33437c62d55305139e91697ffc Binary files /dev/null and b/Examples/Data/NDVI_2 differ diff --git a/Examples/Data/NDVI_2.hdr b/Examples/Data/NDVI_2.hdr new file mode 100644 index 0000000000000000000000000000000000000000..7afe5deaeb6eca9a44c9922bed44c699db0de6bd --- /dev/null +++ b/Examples/Data/NDVI_2.hdr @@ -0,0 +1,9 @@ +ENVI +samples = 1200 +lines = 1200 +bands = 1 +header offset = 0 +file type = ENVI Standard +data type = 5 +interleave = bsq +byte order = 0 diff --git a/Examples/Data/NDVI_3 b/Examples/Data/NDVI_3 new file mode 100644 index 0000000000000000000000000000000000000000..da44c16f1e4ad415f547553d6cf6211498fefb74 Binary files /dev/null and b/Examples/Data/NDVI_3 differ diff --git a/Examples/Data/NDVI_3.hdr b/Examples/Data/NDVI_3.hdr new file mode 100644 index 0000000000000000000000000000000000000000..7afe5deaeb6eca9a44c9922bed44c699db0de6bd --- /dev/null +++ b/Examples/Data/NDVI_3.hdr @@ -0,0 +1,9 @@ +ENVI +samples = 1200 +lines = 1200 +bands = 1 +header offset = 0 +file type = ENVI Standard +data type = 5 +interleave = bsq +byte order = 0 diff --git a/Examples/Data/VegetationIndex.c1 b/Examples/Data/VegetationIndex.c1 new file mode 100644 index 0000000000000000000000000000000000000000..31f456a29b84fc33437c62d55305139e91697ffc Binary files /dev/null and b/Examples/Data/VegetationIndex.c1 differ diff --git a/Examples/Data/VegetationIndex.c2 b/Examples/Data/VegetationIndex.c2 new file mode 100644 index 0000000000000000000000000000000000000000..da44c16f1e4ad415f547553d6cf6211498fefb74 Binary files /dev/null and b/Examples/Data/VegetationIndex.c2 differ diff --git a/Examples/Data/VegetationIndex.c3 b/Examples/Data/VegetationIndex.c3 new file mode 100644 index 0000000000000000000000000000000000000000..dd4200f02813d596f9424627d0120451ef64e745 Binary files /dev/null and b/Examples/Data/VegetationIndex.c3 differ diff --git a/Examples/Data/VegetationIndex.hd b/Examples/Data/VegetationIndex.hd new file mode 100644 index 0000000000000000000000000000000000000000..051a522d47436674a5d15814b7b5e141d76b30b0 --- /dev/null +++ b/Examples/Data/VegetationIndex.hd @@ -0,0 +1,14 @@ +TYPE +R8 +LABEL +R8 - This BSQ image file was producted by OTB software. +CHANNELS +3 +LINES +1200 +COLUMNS +1200 +BITS PER PIXEL +64 +SENSCODAGE +INTEL diff --git a/Examples/Data/multiSpect.tif b/Examples/Data/multiSpect.tif new file mode 100755 index 0000000000000000000000000000000000000000..7f4a7244ae20a79d2c12e9e3474db628e35d3609 Binary files /dev/null and b/Examples/Data/multiSpect.tif differ diff --git a/Examples/Data/multiSpectInterp.tif b/Examples/Data/multiSpectInterp.tif new file mode 100755 index 0000000000000000000000000000000000000000..fa7308a02beb0a84a06d5ed9d87fe42b25a33064 Binary files /dev/null and b/Examples/Data/multiSpectInterp.tif differ diff --git a/Examples/Data/panchro.tif b/Examples/Data/panchro.tif new file mode 100755 index 0000000000000000000000000000000000000000..f7253316b3a1b5e4e68d71e5ef78b8c126081302 Binary files /dev/null and b/Examples/Data/panchro.tif differ diff --git a/Examples/Data/poupees_sub.png b/Examples/Data/poupees_sub.png new file mode 100755 index 0000000000000000000000000000000000000000..106dd3804c132afd360a8596199ad75e0aa98f73 Binary files /dev/null and b/Examples/Data/poupees_sub.png differ diff --git a/Examples/Data/poupees_sub_c1.png b/Examples/Data/poupees_sub_c1.png new file mode 100755 index 0000000000000000000000000000000000000000..b3b37782f581672b455f946c2c0bfaf8bd3b2f4b Binary files /dev/null and b/Examples/Data/poupees_sub_c1.png differ diff --git a/Examples/Data/poupees_sub_c2.png b/Examples/Data/poupees_sub_c2.png new file mode 100755 index 0000000000000000000000000000000000000000..9f439ffaf922df23883436e25e40968f66527154 Binary files /dev/null and b/Examples/Data/poupees_sub_c2.png differ diff --git a/Examples/Fusion/BayesianFusionImageFilter.cxx b/Examples/Fusion/BayesianFusionImageFilter.cxx new file mode 100755 index 0000000000000000000000000000000000000000..95faa3be5190f623b55a44c87b6f3a4a77c914c2 --- /dev/null +++ b/Examples/Fusion/BayesianFusionImageFilter.cxx @@ -0,0 +1,364 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#ifdef __BORLANDC__ +#define ITK_LEAN_AND_MEAN +#endif + + +// Software Guide : BeginCommandLineArgs +// INPUTS: {multiSpect.tif} , {multiSpectInterp.tif}, {panchro.tif} +// OUTPUTS: {BayesianFusion_0.9999.tif} , {pretty_BayesianFusion_0.9999.png} , {pretty_multiSpect_0.9999.png} , {pretty_multiSpectInterp_0.9999.png} , {pretty_panchro_0.9999.png} +// 0.9999 +// Software Guide : EndCommandLineArgs + +// Software Guide : BeginCommandLineArgs +// INPUTS: {multiSpect.tif} , {multiSpectInterp.tif}, {panchro.tif} +// OUTPUTS: {BayesianFusion_0.5.tif} , {pretty_BayesianFusion_0.5.png} , {pretty_multiSpect_0.5.png} , {pretty_multiSpectInterp_0.5.png} , {pretty_panchro_0.5.png} +// 0.5 +// Software Guide : EndCommandLineArgs + + +// Software Guide : BeginLatex +// +// \index{otb::BayesianFusionFilter} +// \index{otb::BayesianFusionFilter!header} +// +// The following example illustrates the use of the +// \doxygen{otb}{BayesianFusionFilter}. The Bayesian data fusion +// relies on the idea that variables of interest, denoted as vector $\mathbf{Z}$, +// cannot be directly observed. They are linked to the observable variables +// $\mathbf{Y}$ through the following error-like model. +// +// \begin{equation} +// \mathbf{Y} = \mathbf{Z} + \mathbf{E} +// \end{equation} +// +// where g($\mathbf{Z}$) is a set of functionals and $\mathbf{E}$ is a +// vector of random errors that are stochastically independent from $\mathbf{Z}$. +// This algorithm uses elementary probability calculus, and several assumptions to compute +// the data fusion. For more explication see Fasbender, Radoux and Bogaert's +// publication \cite{JRadoux}. +// Three images are used : +// \begin{itemize} +// \item a panchromatic image, +// \item a multispectral image resampled at the panchromatic image spatial resolution, +// \item a multispectral image resampled at the panchromatic image spatial resolution, +// using a cubic interpolator. +// \item a float : $\lambda$, the meaning of the weight to be given to the panchromatic +// image compared to the multispectral one. +// \end{itemize} +// +// Let's look at the minimal code required to use this algorithm. First, the following header +// defining the otb::BayesianFusionFilter class must be included. +// Software Guide : EndLatex + +// Software Guide : BeginCodeSnippet +#include "otbBayesianFusionFilter.h" +// Software Guide : EndCodeSnippet + + +#include "otbImage.h" +#include "otbVectorImage.h" +#include "itkCastImageFilter.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "otbMultiChannelExtractROI.h" +#include "otbVectorRescaleIntensityImageFilter.h" +#include "itkRescaleIntensityImageFilter.h" +#include "otbImageToVectorImageCastFilter.h" + +int main( int argc, char *argv[] ) +{ + if( argc < 10 ) + { + std::cerr << "Missing Parameters " << std::endl; + std::cerr << "Usage: " << argv[0]; + std::cerr << " inputMultiSpectralImage inputMultiSpectralInterpolatedImage inputPanchromatiqueImage outputImage outputImagePrinted msPrinted msiPrinted panchroPrinted lambda" << std::endl; + return 1; + } + + // Software Guide : BeginLatex + // + // The image types are now defined using pixel types and particular + // dimension. The panchromatic image is defined as an \doxygen{otb}{Image} + // and the multispectral one as \doxygen{otb}{VectorImage}. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + typedef double InternalPixelType; + const unsigned int Dimension = 2; + typedef otb::Image< InternalPixelType, Dimension > PanchroImageType; + typedef otb::VectorImage< InternalPixelType, Dimension > MultiSpecImageType; + // Software Guide : EndCodeSnippet + + typedef double OutputPixelType; + typedef otb::VectorImage< OutputPixelType, Dimension > OutputImageType; + + + // We instantiate reader and writer types + // + typedef otb::ImageFileReader< MultiSpecImageType > ReaderVectorType; + typedef otb::ImageFileReader< PanchroImageType > ReaderType; + typedef otb::ImageFileWriter< OutputImageType > WriterType; + + ReaderVectorType::Pointer multiSpectReader = ReaderVectorType::New(); + ReaderVectorType::Pointer multiSpectInterpReader = ReaderVectorType::New(); + ReaderType::Pointer panchroReader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + + multiSpectReader->SetFileName( argv[1] ); + multiSpectInterpReader->SetFileName( argv[2] ); + panchroReader->SetFileName( argv[3] ); + writer->SetFileName( argv[4] ); + + + // Software Guide : BeginLatex + // + // The Bayesian data fusion filter type is instantiated using the images types as + // a template parameters. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + typedef otb::BayesianFusionFilter< MultiSpecImageType, + MultiSpecImageType, + PanchroImageType, + OutputImageType > BayesianFusionFilterType; + // Software Guide : EndCodeSnippet + + + // Software Guide : BeginLatex + // + // Next the filter is created by invoking the \code{New()} method and + // assigning the result to a \doxygen{itk}{SmartPointer}. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + BayesianFusionFilterType::Pointer bayesianFilter = BayesianFusionFilterType::New(); + // Software Guide : EndCodeSnippet + + + // Software Guide : BeginLatex + // + // Now the multi spectral image, the interpolated multi spectral image and + // the panchromatic image are given as inputs to the filter. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + bayesianFilter->SetMultiSpect( multiSpectReader->GetOutput() ); + bayesianFilter->SetMultiSpectInterp( multiSpectInterpReader->GetOutput() ); + bayesianFilter->SetPanchro( panchroReader->GetOutput() ); + + writer->SetInput( bayesianFilter->GetOutput() ); + // Software Guide : EndCodeSnippet + + + // Software Guide : BeginLatex + // The BayesianFusionFilter requires defining one parameter : $\lambda$. + // The $\lambda$ parameter can be used to tune the fusion toward either a high color + // consistency or sharp details. Possible $\lambda$ value range in $[0.5, 1[$, where higher + // values yield sharper details. by default $\lambda$ is set at 0.9999. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + bayesianFilter->SetLambda( atof(argv[9]) ); + // Software Guide : EndCodeSnippet + + + // Software Guide : BeginLatex + // + // The invocation of the \code{Update()} method on the writer triggers the + // execution of the pipeline. It is recommended to place update calls in a + // \code{try/catch} block in case errors occur and exceptions are thrown. + // + // Software Guide : EndLatex + + + + // Software Guide : BeginCodeSnippet + try + { + writer->Update(); + } + catch( itk::ExceptionObject & excep ) + { + std::cerr << "Exception caught !" << std::endl; + std::cerr << excep << std::endl; + } + // Software Guide : EndCodeSnippet + + + // Create an 3 band images for the software guide + typedef unsigned char OutputPixelType2; + typedef otb::VectorImage<OutputPixelType2, Dimension> OutputVectorImageType; + typedef otb::ImageFileWriter<OutputVectorImageType> VectorWriterType; + typedef otb::VectorRescaleIntensityImageFilter<MultiSpecImageType, + OutputVectorImageType> VectorRescalerType; + typedef otb::VectorRescaleIntensityImageFilter<OutputImageType, + OutputVectorImageType> VectorRescalerBayesianType; + typedef otb::Image< OutputPixelType2, Dimension > PanchroOutputImageType; + typedef otb::ImageToVectorImageCastFilter<PanchroImageType, MultiSpecImageType> CasterType; + typedef otb::MultiChannelExtractROI<OutputPixelType2,OutputPixelType2> ChannelExtractorType; + typedef otb::ImageFileWriter<PanchroOutputImageType> WriterType2; + + multiSpectReader->GenerateOutputInformation(); + multiSpectInterpReader->GenerateOutputInformation(); + + CasterType::Pointer cast = CasterType::New(); + cast->SetInput(panchroReader->GetOutput()); + + OutputVectorImageType::PixelType minimum,maximum; + minimum.SetSize(multiSpectReader->GetOutput()->GetNumberOfComponentsPerPixel()); + maximum.SetSize(multiSpectReader->GetOutput()->GetNumberOfComponentsPerPixel()); + minimum.Fill(0); + maximum.Fill(255); + + VectorRescalerType::Pointer vrms = VectorRescalerType::New(); + VectorRescalerType::Pointer vrmsi = VectorRescalerType::New(); + VectorRescalerBayesianType::Pointer vrb = VectorRescalerBayesianType::New(); + + vrms->SetInput(multiSpectReader->GetOutput()); + vrms->SetOutputMinimum(minimum); + vrms->SetOutputMaximum(maximum); + vrms->SetClampThreshold(0.01); + + vrmsi->SetInput(multiSpectInterpReader->GetOutput()); + vrmsi->SetOutputMinimum(minimum); + vrmsi->SetOutputMaximum(maximum); + vrmsi->SetClampThreshold(0.01); + + vrb->SetInput(bayesianFilter->GetOutput()); + vrb->SetOutputMinimum(minimum); + vrb->SetOutputMaximum(maximum); + vrb->SetClampThreshold(0.01); + + VectorRescalerType::Pointer rp = VectorRescalerType::New(); + rp->SetInput(cast->GetOutput()); + minimum.SetSize(1); + maximum.SetSize(1); + minimum.Fill(0); + maximum.Fill(255); + rp->SetOutputMinimum(minimum); + rp->SetOutputMaximum(maximum); + rp->SetClampThreshold(0.01); + + ChannelExtractorType::Pointer selecterms = ChannelExtractorType::New(); + ChannelExtractorType::Pointer selectermsi = ChannelExtractorType::New(); + ChannelExtractorType::Pointer selecterf = ChannelExtractorType::New(); + + selecterms->SetInput(vrms->GetOutput()); + // selecterms->SetExtractionRegion(multiSpectReader->GetOutput()->GetLargestPossibleRegion()); + selecterms->SetChannel(2); + selecterms->SetChannel(3); + selecterms->SetChannel(4); + + selectermsi->SetInput(vrmsi->GetOutput()); + // selectermsi->SetExtractionRegion(multiSpectInterpReader->GetOutput()->GetLargestPossibleRegion()); + selectermsi->SetChannel(2); + selectermsi->SetChannel(3); + selectermsi->SetChannel(4); + + selecterf->SetInput(vrb->GetOutput()); + //selecterf->SetExtractionRegion(bayesianFilter->GetOutput()->GetLargestPossibleRegion()); + selecterf->SetChannel(2); + selecterf->SetChannel(3); + selecterf->SetChannel(4); + + + VectorWriterType::Pointer vectWriterms = VectorWriterType::New(); + VectorWriterType::Pointer vectWritermsi = VectorWriterType::New(); + VectorWriterType::Pointer vectWriterf = VectorWriterType::New(); + VectorWriterType::Pointer vectWriterp = VectorWriterType::New(); + + vectWriterf->SetFileName(argv[5]); + vectWriterf->SetInput(selecterf->GetOutput()); + vectWriterms->SetFileName(argv[6]); + vectWriterms->SetInput(selecterms->GetOutput()); + vectWritermsi->SetFileName(argv[7]); + vectWritermsi->SetInput(selectermsi->GetOutput()); + vectWriterp->SetFileName(argv[8]); + vectWriterp->SetInput(rp->GetOutput()); + + + + try + { + vectWriterms->Update(); + vectWritermsi->Update(); + vectWriterf->Update(); + vectWriterp->Update(); + } + catch( itk::ExceptionObject & excep ) + { + std::cerr << "Exception caught !" << std::endl; + std::cerr << excep << std::endl; + } + catch( ... ) + { + std::cout << "Unknown exception !" << std::endl; + return EXIT_FAILURE; + } + + + + + // Software Guide : BeginLatex + // + // Let's now run this example using as input the images + // \code{multiSpect.tif} , \code{multiSpectInterp.tif} and \code{panchro.tif} + // provided in the directory \code{Examples/Data}. And with different values for $\lambda$. + // + // + // \begin{figure} \center + // \includegraphics[width=0.24\textwidth]{pretty_multiSpect_0.5.eps} + // \includegraphics[width=0.24\textwidth]{pretty_multiSpectInterp_0.5.eps} + // \includegraphics[width=0.24\textwidth]{pretty_panchro_0.5.eps} + // \itkcaption[Bayesian Data Fusion Example inputs]{Input + // images used for this example.} + // \label{fig:BayesianImageFusionFilterInput} + // \end{figure} + + // \begin{figure} \center + // \includegraphics[width=0.24\textwidth]{pretty_BayesianFusion_0.5.eps} + // \includegraphics[width=0.24\textwidth]{pretty_BayesianFusion_0.9999.eps} + // \itkcaption[Bayesian Data Fusion results]{Fusion results + // for the Bayesian Data Fusion filter for $\lambda = 0.5$ on the left and $\lambda = 0.9999$ on the right.} + // \label{fig:BayesianImageFusionFilterOutput} + // \end{figure} + // + // + // Software Guide : EndLatex + + + return 0; +} + + + + diff --git a/Examples/Fusion/CMakeLists.txt b/Examples/Fusion/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..162950095ec6c5dd62863ab3cd856f0260b79074 --- /dev/null +++ b/Examples/Fusion/CMakeLists.txt @@ -0,0 +1,46 @@ +PROJECT(ImageFusionExamples) +INCLUDE_REGULAR_EXPRESSION("^.*$") + +SET(FUSION_EXAMPLES ${CXX_TEST_PATH}/otbFusionExamplesTests) + + +ADD_EXECUTABLE(BayesianFusionImageFilter BayesianFusionImageFilter.cxx ) +TARGET_LINK_LIBRARIES(BayesianFusionImageFilter OTBFusion OTBCommon OTBIO ITKNumerics ITKIO) + + +IF( NOT OTB_DISABLE_CXX_TESTING AND NOT OTB_DISABLE_CXX_EXAMPLES_TESTING ) + +SET(BASELINE ${OTB_DATA_ROOT}/Baseline/Examples/Fusion) + +SET(INPUTDATA ${OTB_SOURCE_DIR}/Examples/Data) +SET(TEMP ${OTB_BINARY_DIR}/Examples/Fusion/Testing/Temporary) + +SET(EXE_TESTS ${CXX_TEST_PATH}/otbFusionExamplesTests) + +SET(TOL 0.0) + +ADD_TEST(BayesianFusionImageFilterTest ${EXE_TESTS} + --compare-image ${TOL} + ${BASELINE}/ImageBayesianFusion.tif + ${TEMP}/ImageBayesianFusion.tif + BayesianFusionImageFilterTest + ${INPUTDATA}/multiSpect.tif + ${INPUTDATA}/multiSpectInterp.tif + ${INPUTDATA}/panchro.tif + ${TEMP}/ImageBayesianFusion.tif + ${TEMP}/ImageBayesianFusion1.png + ${TEMP}/ImageBayesianFusion2.png + ${TEMP}/ImageBayesianFusion3.png + ${TEMP}/ImageBayesianFusion4.png + 0.5 +) + + + +INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}") + +ADD_EXECUTABLE(otbFusionExamplesTests otbFusionExamplesTests.cxx) +TARGET_LINK_LIBRARIES(otbFusionExamplesTests gdal ITKIO ITKAlgorithms ITKStatistics ITKNumerics ITKCommon OTBBasicFilters OTBCommon OTBDisparityMap OTBIO OTBSpatialReasoning OTBChangeDetection OTBFeatureExtraction OTBLearning OTBMultiScale OTBFusion) + +ENDIF( NOT OTB_DISABLE_CXX_TESTING AND NOT OTB_DISABLE_CXX_EXAMPLES_TESTING ) + diff --git a/Examples/Fusion/otbFusionExamplesTests.cxx b/Examples/Fusion/otbFusionExamplesTests.cxx new file mode 100755 index 0000000000000000000000000000000000000000..c80c482c785b40251b981934055d3891c86e26a1 --- /dev/null +++ b/Examples/Fusion/otbFusionExamplesTests.cxx @@ -0,0 +1,33 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +// this file defines the otbMultiScaleTest for the test driver +// and all it expects is that you have a function called RegisterTests +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif +#include <iostream> +#include "otbTestMain.h" + +void RegisterTests() +{ +REGISTER_TEST(BayesianFusionImageFilterTest); +} + +#undef main +#define main BayesianFusionImageFilterTest +#include "BayesianFusionImageFilter.cxx" diff --git a/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx b/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx new file mode 100755 index 0000000000000000000000000000000000000000..f6f2e7d738e7527a6643d353082da6410b8913b9 --- /dev/null +++ b/Examples/Radiometry/ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx @@ -0,0 +1,326 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#ifdef __BORLANDC__ +#define ITK_LEAN_AND_MEAN +#endif + + +// Software Guide : BeginCommandLineArgs +// INPUTS: {VegetationIndex.hd} +// OUTPUTS: {ARVIMultiChannelRAndBAndNIRVegetationIndex.tif} , {pretty_VegetationIndex.png} , {pretty_ARVIMultiChannelRAndBAndNIRVegetationIndex.png} +// 1 3 2 0.6 +// Software Guide : EndCommandLineArgs + + + +// Software Guide : BeginLatexpretty_NDVI_1 +// +// \index{otb::MultiChannelRAndBAndNIRVegetationIndexImageFilter} +// \index{otb::MultiChannelRAndBAndNIRVegetationIndexImageFilter!header} +// \index{otb::VegetationIndex} +// \index{otb::VegetationIndex!header} +// +// +// The following example illustrates the use of the otb::MultiChannelRAndBAndNIR +// VegetationIndexImageFilter with the use of the Atmospherically Resistant Vegetation Index (ARVI). +// ARVI is an improved version of the NDVI that is more resistent to the atmospheric effect. +// In addition to the red and NIR channels (used in the NRVI), the ARVI takes advantage of +// the presence of the blue channel to accomplish a self-correction process for the +// atmospheric effect on the red channel. For this, it uses the difference in the radiance +// between the blue and the red channels to correct the radiance in the red channel. +// Let's define $\rho_{NIR}^{*}$, $\rho_{r}^{*}$, $\rho_{b}^{*}$ the normalized radiance (that is to say +// the radiance normalized to reflectance units) of red, blue and NIR channels. +// $\rho_{rb}^{*}$ is defined as +// +// \begin{equation} +// \rho_{rb}^{*} = \rho_{r}^{*} - \gamma*(\rho_{b}^{*} - \rho_{r}^{*}) +// \end{equation} +// +// The ARVI expression is +// +// \begin{equation} +// \mathbf{ARVI} = \frac{\rho_{NIR}^{*}-\rho_{rb}^{*}}{\rho_{NIR}^{*}+\rho_{rb}^{*}} +// \end{equation} +// +// +// This formula can be simplified with : +// +// \begin{equation} +// \mathbf{ARVI} = \frac{ L_{NIR}-L_{rb} }{ L_{NIR}+L_{rb} } +// \end{equation} +// +// For more details, refer to Faufman and Tanré work \cite{ARVI}. +// +// With the \doxygen{otb}{MultiChannelRAndBAndNIRVegetationIndexImageFilter} class the +// input has to be a multi channels image and the user has to specify index channel +// of the red, blue and NIR channel. +// +// Let's look at the minimal code required to use this algorithm. First, the following header +// defining the \doxygen{otb}{MultiChannelRAndBAndNIRVegetationIndexImageFilter} +// and the \doxygen{otb}{VegetationIndex} (that contains the ARVI) classes must be included. +// Software Guide : EndLatex + +// Software Guide : BeginCodeSnippet +#include "otbMultiChannelRAndBAndNIRVegetationIndexImageFilter.h" +#include "otbVegetationIndex.h" +// Software Guide : EndCodeSnippet + + +#include "itkExceptionObject.h" +#include "otbImage.h" +#include "otbVectorImage.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "itkRescaleIntensityImageFilter.h" +#include "otbVectorRescaleIntensityImageFilter.h" +#include "otbMultiChannelExtractROI.h" + +int main( int argc, char *argv[] ) +{ + if( argc < 8 ) + { + std::cerr << "Missing Parameters " << std::endl; + std::cerr << "Usage: " << argv[0]; + std::cerr << " inputImage , outputImage , prettyInput , prettyOutput , redChannel , blueChannel , nirChannel , gama" << std::endl; + return 1; + } + + // Software Guide : BeginLatex + // + // The image types are now defined using pixel types and particular + // dimension. The input image is defined as an \doxygen{otb}{VectorImage}, + // the output is a \doxygen{otb}{Image}. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + const unsigned int Dimension = 2; + typedef double InputPixelType; + typedef float OutputPixelType; + typedef otb::VectorImage<InputPixelType ,Dimension> InputImageType; + typedef otb::Image<OutputPixelType,Dimension> OutputImageType; + // Software Guide : EndCodeSnippet + + // We instantiate reader and writer types + typedef otb::ImageFileReader<InputImageType> ReaderType; + typedef otb::ImageFileWriter<OutputImageType> WriterType; + + // Software Guide : BeginLatex + // + // The ARVI (Atmospherically Resistant Vegetation Index) is instantiated using + // the images pixel type types as template parameters. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + typedef otb::Functor::ARVI< InputPixelType, + InputPixelType, + InputPixelType, + OutputPixelType > FunctorType; + // Software Guide : EndCodeSnippet + + + // Software Guide : BeginLatex + // + // The \doxygen{otb}{MultiChannelRAndBAndNIRVegetationIndexImageFilter} type is instantiated using the images + // types and the ARVI functor as template parameters. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + typedef otb::MultiChannelRAndBAndNIRVegetationIndexImageFilter + <InputImageType, + OutputImageType, + FunctorType > + MultiChannelRAndBAndNIRVegetationIndexImageFilterType; + // Software Guide : EndCodeSnippet + + // Instantiating object + + // Software Guide : BeginLatex + // + // Next the filter is created by invoking the \code{New()} method and + // assigning the result to a \doxygen{itk}{SmartPointer}. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + MultiChannelRAndBAndNIRVegetationIndexImageFilterType::Pointer + filter = MultiChannelRAndBAndNIRVegetationIndexImageFilterType::New(); + // Software Guide : EndCodeSnippet + + ReaderType::Pointer reader = ReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + + // Software Guide : BeginLatex + // + // Now the input image is set and a name is given to the output image. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + reader->SetFileName( argv[1] ); + writer->SetFileName( argv[2] ); + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex + // + // The three used index bands (red, blue and NIR) are declared. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + filter->SetRedIndex(::atoi(argv[5])); + filter->SetBlueIndex(::atoi(argv[6])); + filter->SetNIRIndex(::atoi(argv[7])); + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex + // + // The $\gamma$ parameter is set. The \doxygen{otb}{MultiChannelRAndBAndNIRVegetationIndexImageFilter} + // class set the default value of $\gamma$ at 0.5. + // This parameter is used to reduce the atmospheric effect on a global scale. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + filter->GetFunctor().SetGamma(::atof(argv[8])); + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex + // + // The filter input is linked to the reader output and + // the filter outout is linked to the writer input. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + filter->SetInput( reader->GetOutput() ); + + writer->SetInput( filter->GetOutput() ); + // Software Guide : EndCodeSnippet + +// Software Guide : BeginLatex + // + // The invocation of the \code{Update()} method on the writer triggers the + // execution of the pipeline. It is recommended to place update calls in a + // \code{try/catch} block in case errors occur and exceptions are thrown. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + try + { + writer->Update(); + } + catch( itk::ExceptionObject & excep ) + { + std::cerr << "Exception caught !" << std::endl; + std::cerr << excep << std::endl; + } + // Software Guide : EndCodeSnippet + catch( ... ) + { + std::cout << "Unknown exception !" << std::endl; + return EXIT_FAILURE; + } + + + // Pretty image creation for the printing + typedef otb::Image<unsigned char, Dimension> OutputPrettyImageType; + typedef otb::VectorImage<unsigned char, Dimension> OutputVectorPrettyImageType; + typedef otb::ImageFileWriter<OutputVectorPrettyImageType> WriterVectorPrettyType; + typedef otb::ImageFileWriter<OutputPrettyImageType> WriterPrettyType; + typedef itk::RescaleIntensityImageFilter< OutputImageType, OutputPrettyImageType> RescalerType; + typedef otb::VectorRescaleIntensityImageFilter< InputImageType ,OutputVectorPrettyImageType > VectorRescalerType; + typedef otb::MultiChannelExtractROI<unsigned char , unsigned char> ChannelExtractorType; + + + VectorRescalerType::Pointer vectRescaler = VectorRescalerType::New(); + ChannelExtractorType::Pointer selecter = ChannelExtractorType::New(); + WriterVectorPrettyType::Pointer vectPrettyWriter = WriterVectorPrettyType::New(); + + OutputVectorPrettyImageType::PixelType minimum,maximum; + minimum.SetSize(reader->GetOutput()->GetNumberOfComponentsPerPixel()); + maximum.SetSize(reader->GetOutput()->GetNumberOfComponentsPerPixel()); + minimum.Fill(0); + maximum.Fill(255); + vectRescaler->SetOutputMinimum(minimum); + vectRescaler->SetOutputMaximum(maximum); + vectRescaler->SetClampThreshold(0.01); + vectRescaler->SetInput( reader->GetOutput() ); + + selecter->SetInput(vectRescaler->GetOutput()); + selecter->SetChannel(1); + selecter->SetChannel(2); + selecter->SetChannel(3); + + vectPrettyWriter->SetFileName( argv[3] ); + vectPrettyWriter->SetInput( selecter->GetOutput() ); + + + + RescalerType::Pointer rescaler = RescalerType::New(); + WriterPrettyType::Pointer prettyWriter = WriterPrettyType::New(); + rescaler->SetInput( filter->GetOutput() ); + rescaler->SetOutputMinimum(0); + rescaler->SetOutputMaximum(255); + prettyWriter->SetFileName( argv[4] ); + prettyWriter->SetInput( rescaler->GetOutput() ); + + try + { + prettyWriter->Update(); + vectPrettyWriter->Update(); + std::cout<<filter->GetFunctor().GetGamma()<<std::endl; + } + catch( itk::ExceptionObject & excep ) + { + std::cerr << "Exception caught !" << std::endl; + std::cerr << excep << std::endl; + } + catch( ... ) + { + std::cout << "Unknown exception !" << std::endl; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; + + // Software Guide : BeginLatex + // + // Let's now run this example using as input the image + // \code{IndexVegetation.jpg} (image kindly and free of charge given by the SISA and the CNES) + // and $\gamma$=0.6 provided in the directory \code{Examples/Data}. + // + // + // \begin{figure} \center + // \includegraphics[width=0.24\textwidth]{pretty_VegetationIndex.eps} + // \includegraphics[width=0.24\textwidth]{pretty_ARVIMultiChannelRAndBAndNIRVegetationIndex.eps} + // \itkcaption[ARVI Example]{ARVI result on the right with the left image in input.} + // \label{fig:ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter} + // \end{figure} + // + // Software Guide : EndLatex + +} + diff --git a/Examples/Radiometry/CMakeLists.txt b/Examples/Radiometry/CMakeLists.txt new file mode 100755 index 0000000000000000000000000000000000000000..771c1e90f1c4a999788eaa7b1950e7ead231678e --- /dev/null +++ b/Examples/Radiometry/CMakeLists.txt @@ -0,0 +1,68 @@ +PROJECT(ImageRadiometryExamples) +INCLUDE_REGULAR_EXPRESSION("^.*$") + +SET(FUSION_EXAMPLES ${CXX_TEST_PATH}/RadiometryExamplesTests) + + +ADD_EXECUTABLE(ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx ) +TARGET_LINK_LIBRARIES(ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter OTBRadiometry OTBCommon OTBIO ITKNumerics ITKIO) + +ADD_EXECUTABLE(NDVIRAndNIRVegetationIndexImageFilter NDVIRAndNIRVegetationIndexImageFilter.cxx ) +TARGET_LINK_LIBRARIES(NDVIRAndNIRVegetationIndexImageFilter OTBRadiometry OTBCommon OTBIO ITKNumerics ITKIO) + +IF( NOT OTB_DISABLE_CXX_TESTING AND NOT OTB_DISABLE_CXX_EXAMPLES_TESTING ) + +SET(BASELINE ${OTB_DATA_ROOT}/Baseline/Examples/Radiometry) + +SET(INPUTDATA ${OTB_SOURCE_DIR}/Examples/Data) +SET(TEMP ${OTB_BINARY_DIR}/Examples/Radiometry/Testing/Temporary) + +SET(EXE_TESTS ${CXX_TEST_PATH}/otbRadiometryExamplesTests) + +#Tolerance sur diff pixel image +SET(TOL 0.0) +SET(EPSILON 0.000000000001) + + +# ------- ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter ------------------------------ + +ADD_TEST(ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilterTest ${EXE_TESTS} + --compare-image ${EPSILON} + ${BASELINE}/ARVIRAndBAndNIRVegetationIndex.tif + ${TEMP}/ARVIMultiChannelRAndBAndNIRVegetationIndex.tif + ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilterTest + ${INPUTDATA}/poupees_sub.png + ${TEMP}/ARVIMultiChannelRAndBAndNIRVegetationIndex.tif + ${TEMP}/ARVIMultiChannelRAndBAndNIRVegetationIndex3.tif + ${TEMP}/ARVIMultiChannelRAndBAndNIRVegetationIndex2.tif + 1 + 2 + 3 + 0.6 # Gamma parameter + ) + + + +# ------- NDVIRAndNIRVegetationIndexImageFilter ------------------------------ + +ADD_TEST(NDVIRAndNIRVegetationIndexImageFilterTest ${EXE_TESTS} + --compare-image ${TOL} + ${BASELINE}/NDVIRAndNIRVegetationIndex.tif + ${TEMP}/NDVIRAndNIRVegetationIndex.tif + NDVIRAndNIRVegetationIndexImageFilterTest + ${INPUTDATA}/poupees_sub_c1.png + ${INPUTDATA}/poupees_sub_c2.png + ${TEMP}/NDVIRAndNIRVegetationIndex.tif + ${TEMP}/NDVIRAndNIRVegetationIndex2.tif + ${TEMP}/NDVIRAndNIRVegetationIndex3.tif + ) + + + +INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}") + +ADD_EXECUTABLE(otbRadiometryExamplesTests otbRadiometryExamplesTests.cxx) +TARGET_LINK_LIBRARIES(otbRadiometryExamplesTests gdal ITKIO ITKAlgorithms ITKStatistics ITKNumerics ITKCommon OTBBasicFilters OTBCommon OTBDisparityMap OTBIO OTBSpatialReasoning OTBChangeDetection OTBFeatureExtraction OTBLearning OTBMultiScale OTBFusion) + +ENDIF( NOT OTB_DISABLE_CXX_TESTING AND NOT OTB_DISABLE_CXX_EXAMPLES_TESTING ) + diff --git a/Examples/Radiometry/NDVIRAndNIRVegetationIndexImageFilter.cxx b/Examples/Radiometry/NDVIRAndNIRVegetationIndexImageFilter.cxx new file mode 100755 index 0000000000000000000000000000000000000000..48b52efda1b706ad83ebf068afe920de6eb40ed2 --- /dev/null +++ b/Examples/Radiometry/NDVIRAndNIRVegetationIndexImageFilter.cxx @@ -0,0 +1,258 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#ifdef __BORLANDC__ +#define ITK_LEAN_AND_MEAN +#endif + + +// Software Guide : BeginCommandLineArgs +// INPUTS: {NDVI_2.hdr} , {NDVI_3.hdr} +// OUTPUTS: {NDVIRAndNIRVegetationIndex.tif} , {pretty_Red.png} , {pretty_NIR.png} , {pretty_NDVIRAndNIRVegetationIndex.png} +// Software Guide : EndCommandLineArgs + + +// Software Guide : BeginLatex +// +// \index{otb::RAndNIRVegetationIndexImageFilter} +// \index{otb::VegetationIndex} +// \index{otb::VegetationIndex!header} +// +// The following example illustrates the use of the +// \doxygen{otb}{RAndNIRVegetationIndexImageFilter} with the use of the Normalized +// Difference Vegatation Index (NDVI). +// NDVI computes the difference between the NIR channel, noted $L_{NIR}$, and the red channel, +// noted $L_{r}$ radiances reflected from the surface and transmitted through the atmosphere : +// +// \begin{equation} +// \mathbf{NDVI} = \frac{L_{NIR}-L_{r}}{L_{NIR}+L_{r}} +// \end{equation} +// +// With the \doxygen{otb}{RAndNIRVegetationIndexImageFilter} class the filter +// inputs are one channel images : one inmage represents the NIR channel, the +// the other the NIR channel. +// +// Let's look at the minimal code required to use this algorithm. First, the following header +// defining the \doxygen{otb}{RAndNIRVegetationIndexImageFilter} +// and the \doxygen{otb}{VegetationIndex} (that contains the ARVI) classes must be included. +// Software Guide : EndLatex + +// Software Guide : BeginCodeSnippet +#include "otbRAndNIRVegetationIndexImageFilter.h" +#include "otbVegetationIndex.h" +// Software Guide : EndCodeSnippet + + +#include "itkExceptionObject.h" +#include "otbImage.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "itkRescaleIntensityImageFilter.h" + + +int main( int argc, char *argv[] ) +{ + if( argc < 6 ) + { + std::cerr << "Missing Parameters " << std::endl; + std::cerr << "Usage: " << argv[0]; + std::cerr << " inputImage1 , inputImage2 , outputImage , prettyinputImage1 , prettyinputImage2 , prettyOutput" << std::endl; + return 1; + } + + // Software Guide : BeginLatex + // + // The image types are now defined using pixel types and particular + // dimension. Input and output images are defined as \doxygen{otb}{Image}. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + const unsigned int Dimension = 2; + typedef double InputPixelType; + typedef float OutputPixelType; + typedef otb::Image<InputPixelType,Dimension> InputRImageType; + typedef otb::Image<InputPixelType,Dimension> InputNIRImageType; + typedef otb::Image<OutputPixelType,Dimension> OutputImageType; + // Software Guide : EndCodeSnippet + + // We instantiate reader and writer types + typedef otb::ImageFileReader<InputRImageType> RReaderType; + typedef otb::ImageFileReader<InputNIRImageType> NIRReaderType; + typedef otb::ImageFileWriter<OutputImageType> WriterType; + + // Software Guide : BeginLatex + // + // The NDVI (Normalized Difference Vegetation Index) is instantiated using + // the images pixel type types as template parameters. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + typedef otb::Functor::NDVI< InputPixelType, + InputPixelType, + OutputPixelType> FunctorType; + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex + // + // The \doxygen{otb}{RAndNIRVegetationIndexImageFilter} type is instantiated using the images + // types and the NDVI functor as template parameters. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + typedef otb::RAndNIRVegetationIndexImageFilter<InputRImageType, + InputNIRImageType, + OutputImageType, + FunctorType> RAndNIRVegetationIndexImageFilterType; + // Software Guide : EndCodeSnippet + + + // Instantiating object + RAndNIRVegetationIndexImageFilterType::Pointer filter = RAndNIRVegetationIndexImageFilterType::New(); + RReaderType::Pointer readerR = RReaderType::New(); + NIRReaderType::Pointer readerNIR = NIRReaderType::New(); + WriterType::Pointer writer = WriterType::New(); + + // Software Guide : BeginLatex + // + // Now the input images is set and a name is given to the output image. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + readerR->SetFileName( argv[1] ); + readerNIR->SetFileName( argv[2] ); + writer->SetFileName( argv[3] ); + + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex + // + // The filter inputs are linked to readers output and + // the filter output is linked to the writer input. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + filter->SetInputR( readerR->GetOutput() ); + filter->SetInputNIR( readerNIR->GetOutput() ); + + writer->SetInput( filter->GetOutput() ); + // Software Guide : EndCodeSnippet + + + // Software Guide : BeginLatex + // + // The invocation of the \code{Update()} method on the writer triggers the + // execution of the pipeline. It is recommended to place update calls in a + // \code{try/catch} block in case errors occur and exceptions are thrown. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + try + { + writer->Update(); + } + catch( itk::ExceptionObject & excep ) + { + std::cerr << "Exception caught !" << std::endl; + std::cerr << excep << std::endl; + } + // Software Guide : EndCodeSnippet + catch( ... ) + { + std::cout << "Unknown exception !" << std::endl; + return EXIT_FAILURE; + } + + // Pretty image creation for the printing + typedef otb::Image<unsigned char, Dimension> OutputPrettyImageType; + typedef otb::ImageFileWriter<OutputPrettyImageType> WriterPrettyType; + typedef itk::RescaleIntensityImageFilter< OutputImageType, OutputPrettyImageType> RescalerType; + typedef itk::RescaleIntensityImageFilter< InputRImageType, OutputPrettyImageType> RescalerRType; + typedef itk::RescaleIntensityImageFilter< InputNIRImageType, OutputPrettyImageType> RescalerNIRType; + + + RescalerType::Pointer rescaler = RescalerType::New(); + WriterPrettyType::Pointer prettyWriter = WriterPrettyType::New(); + rescaler->SetInput( filter->GetOutput() ); + rescaler->SetOutputMinimum(0); + rescaler->SetOutputMaximum(255); + prettyWriter->SetFileName( argv[6] ); + prettyWriter->SetInput( rescaler->GetOutput() ); + + RescalerRType::Pointer rescalerR = RescalerRType::New(); + RescalerNIRType::Pointer rescalerNIR = RescalerNIRType::New(); + WriterPrettyType::Pointer prettyWriterR = WriterPrettyType::New(); + WriterPrettyType::Pointer prettyWriterNIR = WriterPrettyType::New(); + rescalerR->SetInput( readerR->GetOutput() ); + rescalerR->SetOutputMinimum(0); + rescalerR->SetOutputMaximum(255); + prettyWriterR->SetFileName( argv[4] ); + prettyWriterR->SetInput( rescalerR->GetOutput() ); + + rescalerNIR->SetInput( readerNIR->GetOutput() ); + rescalerNIR->SetOutputMinimum(0); + rescalerNIR->SetOutputMaximum(255); + prettyWriterNIR->SetFileName( argv[5] ); + prettyWriterNIR->SetInput( rescalerNIR->GetOutput() ); + + try + { + prettyWriter->Update(); + prettyWriterNIR->Update(); + prettyWriterR->Update(); + } + catch( itk::ExceptionObject & excep ) + { + std::cerr << "Exception caught !" << std::endl; + std::cerr << excep << std::endl; + } + catch( ... ) + { + std::cout << "Unknown exception !" << std::endl; + return EXIT_FAILURE; + } + + + // Software Guide : BeginLatex + // + // Let's now run this example using as input the images + // \code{NDVI\_3.hdr} and \code{NDVI\_4.hdr} (images kindly and free of charge given by the SISA and the CNES) + // and $\gamma=0.6$ provided in the directory \code{Examples/Data}. + // + // + // \begin{figure} \center + // \includegraphics[width=0.24\textwidth]{pretty_Red.eps} + // \includegraphics[width=0.24\textwidth]{pretty_NIR.eps} + // \includegraphics[width=0.24\textwidth]{pretty_NDVIRAndNIRVegetationIndex.eps} + // \itkcaption[ARVI Example]{NDVI input images on the right (Red channel and NIR channel), on the left the result of the algorithm.} + // \label{fig:NDVIRAndNIRVegetationIndex} + // \end{figure} + // + // Software Guide : EndLatex + + return EXIT_SUCCESS; +} + diff --git a/Examples/Radiometry/otbRadiometryExamplesTests.cxx b/Examples/Radiometry/otbRadiometryExamplesTests.cxx new file mode 100755 index 0000000000000000000000000000000000000000..6be8bee2653afa785711e90b245c72e8aa301552 --- /dev/null +++ b/Examples/Radiometry/otbRadiometryExamplesTests.cxx @@ -0,0 +1,38 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +// this file defines the otbMultiScaleTest for the test driver +// and all it expects is that you have a function called RegisterTests +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif +#include <iostream> +#include "otbTestMain.h" + +void RegisterTests() +{ +REGISTER_TEST(ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilterTest); +REGISTER_TEST(NDVIRAndNIRVegetationIndexImageFilterTest); +} + +#undef main +#define main ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilterTest +#include "ARVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx" + +#undef main +#define main NDVIRAndNIRVegetationIndexImageFilterTest +#include "NDVIRAndNIRVegetationIndexImageFilter.cxx"