diff --git a/Code/FeatureExtraction/otbCloudDetectionFunctor.h b/Code/FeatureExtraction/otbCloudDetectionFunctor.h index b6aa79eab5c708449fbd3ad7509f31f87ef94926..a21786358f8eb4bf49b4a3710c80df44a9d5311c 100644 --- a/Code/FeatureExtraction/otbCloudDetectionFunctor.h +++ b/Code/FeatureExtraction/otbCloudDetectionFunctor.h @@ -44,7 +44,7 @@ public: ~CloudDetectionFunctor() {}; inline TOutputValue operator()(const TInput& inPix) { - if ( (m_CloudEstimatorFunctor(inPix)>m_MinThreshold) && (m_CloudEstimatorFunctor(inPix)<m_MaxThreshold) ) + if ( (m_CloudEstimatorFunctor(inPix)>m_MinThreshold) && (m_CloudEstimatorFunctor(inPix)<=m_MaxThreshold) ) { return 1; } diff --git a/Code/FeatureExtraction/otbSpectralAngleFunctor.h b/Code/FeatureExtraction/otbSpectralAngleFunctor.h index 38c36ef1b63fc268026835641f88f11f51ccbeb9..85d81cf8042c68b2362556bc5f44a6c63734078e 100644 --- a/Code/FeatureExtraction/otbSpectralAngleFunctor.h +++ b/Code/FeatureExtraction/otbSpectralAngleFunctor.h @@ -19,6 +19,7 @@ #define __otbSpectralAngleFunctor_h #include "otbMath.h" +#include <algorithm> namespace otb { diff --git a/Code/Radiometry/otbVegetationIndex.h b/Code/Radiometry/otbVegetationIndex.h index 9304da4f3a9db43063f2c0484fbed068bd609175..ead5d02719e3f2b4fb1dd1a097fef76e0327d16d 100644 --- a/Code/Radiometry/otbVegetationIndex.h +++ b/Code/Radiometry/otbVegetationIndex.h @@ -321,6 +321,7 @@ public: return static_cast<TOutput>(0.); } return ( static_cast<TOutput>( m_G * (dnir - dr)/denominator ) ); +//return ( static_cast<TOutput>( dnir ) ); } /** Set/Get G parameter */ void SetG(const double g) diff --git a/Examples/FeatureExtraction/CMakeLists.txt b/Examples/FeatureExtraction/CMakeLists.txt index e0301c735f7442d2710fde08d17f615450087e90..f85666ebcdd3cd9e31304073c3037765546042e1 100644 --- a/Examples/FeatureExtraction/CMakeLists.txt +++ b/Examples/FeatureExtraction/CMakeLists.txt @@ -82,6 +82,9 @@ ADD_EXECUTABLE(ParallelLineDetectionExample ParallelLineDetectionExample.cxx) TARGET_LINK_LIBRARIES(ParallelLineDetectionExample OTBIO OTBCommon OTBFeatureExtraction ITKCommon ITKBasicFilters) +ADD_EXECUTABLE(CloudDetectionExample CloudDetectionExample.cxx) +TARGET_LINK_LIBRARIES(CloudDetectionExample OTBIO OTBCommon OTBFeatureExtraction +ITKCommon ITKBasicFilters) IF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING ) @@ -293,6 +296,18 @@ ADD_TEST(ScaleInvariantFeatureImageFilterTest ${EXE_TESTS2} 1 10 0.5 0 ) +# ------- CloudDetectionExampleTest---------- + +ADD_TEST(CloudDetectionExampleTest ${EXE_TESTS2} + --compare-image ${TOL} + ${BASELINE}/CloudDetectionOutput.png + ${TEMP}/CloudDetectionOutput.png + CloudDetectionExampleTest + ${INPUTDATA}/CloudsOnReunion.tif + ${TEMP}/CloudDetectionOutput.png + 553 467 734 581 0.4 0.6 1.0 +) + ADD_EXECUTABLE(otbFeatureExtractionExamplesTests1 otbFeatureExtractionExamplesTests1.cxx) TARGET_LINK_LIBRARIES(otbFeatureExtractionExamplesTests1 gdal ITKIO ITKAlgorithms ITKStatistics ITKCommon OTBBasicFilters OTBCommon OTBDisparityMap OTBIO OTBSpatialReasoning OTBChangeDetection OTBFeatureExtraction OTBLearning OTBMultiScale) diff --git a/Examples/FeatureExtraction/CloudDetectionExample.cxx b/Examples/FeatureExtraction/CloudDetectionExample.cxx new file mode 100644 index 0000000000000000000000000000000000000000..80826f00097a036b1769b74a525df5be47314df6 --- /dev/null +++ b/Examples/FeatureExtraction/CloudDetectionExample.cxx @@ -0,0 +1,252 @@ +/*========================================================================= + + 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: {CloudsOnReunion.tif} +// OUTPUTS: {CloudDetectionOutput.png} +// 553 467 734 581 0.25 0.8 1.0 +// Software Guide : EndCommandLineArgs + + +// Software Guide : BeginLatex +// +// The easiest way to use the road extraction filter provided by OTB is to use the composite +// filter. If a modification in the pipeline is required to adapt to a particular situation, +// the step by step example, described in the next section can be adapted. +// +// This example demonstrates the use of the \doxygen{otb}{RoadExtractionFilter}. +// This filter is a composite filter achieving road extraction according to the algorithm +// adapted by E. Christophe and J. Inglada \cite{Christophe2007} from an original method +// proposed in \cite{Lacroix1998}. +// +// The first step toward the use of this filter is the inclusion of the proper header files. +// +// Software Guide : EndLatex + +// Software Guide : BeginCodeSnippet + +#include "otbCloudDetectionFunctor.h" +#include "otbCloudDetectionFilter.h" + +// Software Guide : EndCodeSnippet + +#include "otbImage.h" +#include "otbVectorImage.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" +#include "itkExceptionObject.h" + +int main( int argc, char * argv[] ) +{ + + if (argc != 10) + { + std::cerr << "Usage: "<< argv[0]; + std::cerr << "inputFileName outputFileName "; + std::cerr << "firstPixelComponent secondPixelComponent thirdPixelComponent fourthPixelComponent "; + std::cerr << "variance "; + std::cerr << "minThreshold maxThreshold "<<std::endl; + return EXIT_FAILURE; + } + + const unsigned int Dimension = 2; + // Software Guide : BeginLatex + // + // Then we must decide what pixel type to use for the image. We choose to do + // all the computation in floating point precision and rescale the results + // between 0 and 255 in order to export PNG images. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + + typedef double InputPixelType; + typedef unsigned short OutputPixelType; + + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex + // + // The images are defined using the pixel type and the dimension. Please note that + // the \doxygen{otb}{RoadExtractionFilter} needs an \doxygen{otb}{VectorImage} as input + // to handle multispectral images. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + typedef otb::VectorImage<InputPixelType,Dimension> VectorImageType; + typedef VectorImageType::PixelType VectorPixelType; + typedef otb::Image<OutputPixelType,Dimension> OutputImageType; + + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex + // + // We define the type of the polyline that the filter produces. We use the + // \doxygen{otb}{PolyLineParametricPathWithValue}, which allows the filter to produce + // a likehood value along with each polyline. The filter is able to produce + // \doxygen{itk}{PolyLineParametricPath} as well. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + + typedef otb::Functor::CloudDetectionFunctor<VectorPixelType,InputPixelType > FunctorType; + + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex + // + // Now we can define the \doxygen{otb}{RoadExtractionFilter} that takes a multi-spectral + // image as input and produces a list of polylines. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + + typedef otb::CloudDetectionFilter<VectorImageType,OutputImageType,FunctorType > CloudDetectionFilterType; + + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex + // + // We also define an \doxygen{otb}{DrawPathListFilter} to draw the output + // polylines on an image, taking their likehood values into account. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + + typedef otb::ImageFileReader<VectorImageType> ReaderType; + typedef otb::ImageFileWriter<OutputImageType> WriterType; + + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex + // + // The different filters composing our pipeline are created by invoking their + // \code{New()} methods, assigning the results to smart pointers. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + + ReaderType::Pointer reader = ReaderType::New(); + CloudDetectionFilterType::Pointer cloudDetection = CloudDetectionFilterType::New(); + WriterType::Pointer writer = WriterType::New(); + + // Software Guide : EndCodeSnippet + + reader->SetFileName(argv[1]); + cloudDetection->SetInput(reader->GetOutput()); + + // Software Guide : BeginLatex + // + // The \doxygen{otb}{RoadExtractionFilter} needs to have a reference pixel + // corresponding to the spectral content likely to represent a road. This is done + // by passing a pixel to the filter. Here we suppose that the input image + // has four spectral bands. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + + VectorPixelType referencePixel; + referencePixel.SetSize(4); + referencePixel.Fill(0.); + referencePixel[0] = (atof(argv[3])); + referencePixel[1] = (atof(argv[4])); + referencePixel[2] = (atof(argv[5])); + referencePixel[3] = (atof(argv[6])); + cloudDetection->SetReferencePixel(referencePixel); + + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex + // + // We must also set the alpha parameter of the filter which allows us to tune the width of the roads + // we want to extract. Typical value is $1.0$ and should be working in most situations. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + + cloudDetection->SetVariance(atof(argv[7])); + + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex + // + // All other parameter should not influence the results too much in most situation and can + // be kept at the default value. + // + // The amplitude threshold parameter tunes the sensitivity of the vectorization step. A typical + // value is $5 \cdot 10^{-5}$. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + + cloudDetection->SetMinThreshold(atof(argv[8])); + cloudDetection->SetMaxThreshold(atof(argv[9])); + + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex + // + // The tolerance threshold tunes the sensitivity of the path simplification step. + // Typical value is $1.0$. + // + // Software Guide : EndLatex + + // Software Guide : BeginCodeSnippet + + writer->SetFileName(argv[2]); + writer->SetInput(cloudDetection->GetOutput()); + writer->Update(); + + // Software Guide : EndCodeSnippet + + // Software Guide : BeginLatex + // + // Figure~\ref{fig:ROADEXTRACTION_FILTER} shows the result of applying + // the road extraction filter to a fusionned Quickbird image. + // \begin{figure} + // \center + // \includegraphics[width=0.44\textwidth]{qb_ExtractRoad_pretty.eps} + // \includegraphics[width=0.44\textwidth]{ExtractRoadOutput.eps} + // \itkcaption[Road extraction filter application]{Result of applying + // the \doxygen{otb}{RoadExtractionFilter} to a fusionned Quickbird + // image. From left to right : original image, extracted road with their + // likehood values (color are inverted for display).} + // \label{fig:ROADEXTRACTION_FILTER} + // \end{figure} + // + // Software Guide : EndLatex + + + return EXIT_SUCCESS; +} + diff --git a/Examples/FeatureExtraction/otbFeatureExtractionExamplesTests2.cxx b/Examples/FeatureExtraction/otbFeatureExtractionExamplesTests2.cxx index 1e6a74294c45a4e645682a37b33d976359dde5df..dec218af753b8e7f491d495ead88ab46a4899ce7 100644 --- a/Examples/FeatureExtraction/otbFeatureExtractionExamplesTests2.cxx +++ b/Examples/FeatureExtraction/otbFeatureExtractionExamplesTests2.cxx @@ -31,6 +31,7 @@ void RegisterTests() REGISTER_TEST(SeamCarvingOtherExampleTest); //REGISTER_TEST(ImageToSIFTKeyPointSetFilterTest); REGISTER_TEST(ScaleInvariantFeatureImageFilterTest); + REGISTER_TEST(CloudDetectionExampleTest); } #undef main @@ -56,3 +57,8 @@ void RegisterTests() #undef main #define main ScaleInvariantFeatureImageFilterTest #include "ScaleInvariantFeatureImageFilter.cxx" + +#undef main +#define main CloudDetectionExampleTest +#include "CloudDetectionExample.cxx" + diff --git a/Testing/Code/Radiometry/CMakeLists.txt b/Testing/Code/Radiometry/CMakeLists.txt index b49d17bd43ca3ba338b71f3ec09ace193297a47c..d6943c4f5971e0536d16d5769ea2249e47bb41d2 100644 --- a/Testing/Code/Radiometry/CMakeLists.txt +++ b/Testing/Code/Radiometry/CMakeLists.txt @@ -520,7 +520,43 @@ ADD_TEST(raTvEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter ${RADIOMETRY_T 1.0 # canopy background adjustment ) +# ------- otb::MultiChannelRAndBAndNIRVegetationIndexImageFilter ------------------------------ + +ADD_TEST(raTvNewARVI_MultiChannelRAndBAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS2} + #--compare-image ${EPSILON} ${BASELINE}/raRAndBAndNIRVegetationIndex_ARVI_poupees_subc1c2c3.tif + # ${TEMP}/raMultiChannelRAndBAndNIRVegetationIndex_ARVI_poupees_subc1c2c3.tif + otbMultiChannelRAndBAndNIRVegetationIndexImageFilter + ARVI + ${OTB_DATA_ROOT}/Examples/VegetationIndex.hd + ${TEMP}/raRAndBAndNIRVegetationIndex_ARVI_qb_RoadExtract.tif + 1 3 2 # red blue nir + 0.6 # Gamma parameter +) + +ADD_TEST(raTvTotoARVI_MultiChannelRAndBAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS2} + #--compare-image ${EPSILON} ${BASELINE}/raRAndBAndNIRVegetationIndex_ARVI_poupees_subc1c2c3.tif + # ${TEMP}/raMultiChannelRAndBAndNIRVegetationIndex_ARVI_poupees_subc1c2c3.tif + otbMultiChannelRAndBAndNIRVegetationIndexImageFilter + ARVI + ${INPUTDATA}/qb_RoadExtract.img.hdr + ${TEMP}/raRAndBAndNIRVegetationIndex_ARVI_qb_RoadExtract.tif + 3 1 4 # red blue nir + 0.6 # Gamma parameter +) +ADD_TEST(raTvNewEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter ${RADIOMETRY_TESTS4} + #--compare-image ${EPSILON} ${BASELINE}/raRAndBAndNIRVegetationIndex_EVI_poupees_subc1c2c3.tif + # ${TEMP}/raRAndBAndNIRVegetationIndex_EVI_poupees_subc1c2c3.tif + otbEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter + EVI + ${OTB_DATA_ROOT}/Examples/VegetationIndex.hd + ${TEMP}/raRAndBAndNIRVegetationIndex_EVI_qb_RoadExtract.tif + 1 2 3 # red blue nir + 2.5 # gain factor + 6.0 # coefficient of the aerosol resistance term + 7.5 # coefficient of the aerosol resistance term + 1.0 # canopy background adjustment +) # A enrichir SET(Radiometry_SRCS1 diff --git a/Testing/Code/Radiometry/otbEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx b/Testing/Code/Radiometry/otbEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx index bd3d6503c45b9fa0d68c939a7d0857ce6c5593f9..c8d18acff476275c6591a14acb1d44c01aa6de67 100644 --- a/Testing/Code/Radiometry/otbEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx +++ b/Testing/Code/Radiometry/otbEVIMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx @@ -45,6 +45,7 @@ int generic_EVIMultiChannelRAndBAndNIRVegetationIndexImageFilter(int argc, char unsigned int redChannel(::atoi(argv[3])); unsigned int blueChannel(::atoi(argv[4])); unsigned int nirChannel(::atoi(argv[5])); +std::cout << "ORDER : "<<redChannel<<" "<<blueChannel<<" "<<nirChannel<<std::endl; double g(::atof(argv[6])); double c1(::atof(argv[7])); diff --git a/Testing/Code/Radiometry/otbMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx b/Testing/Code/Radiometry/otbMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx index a2e8f87ed377dc7429b390914d1b6ba876de0262..9966707b51a99b338714cdcdb2a8bfc532155c0d 100644 --- a/Testing/Code/Radiometry/otbMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx +++ b/Testing/Code/Radiometry/otbMultiChannelRAndBAndNIRVegetationIndexImageFilter.cxx @@ -61,7 +61,7 @@ int generic_MultiChannelRAndBAndNIRVegetationIndexImageFilter(int argc, char * a int otbMultiChannelRAndBAndNIRVegetationIndexImageFilter(int argc, char * argv[]) { const unsigned int Dimension = 2; - typedef otb::VectorImage<unsigned char ,Dimension> InputImageType; + typedef otb::VectorImage<double ,Dimension> InputImageType; typedef otb::Image<float,Dimension> OutputImageType; std::string strArgv(argv[1]);