Commit 405246de authored by Julien Michel's avatar Julien Michel

REFAC: Fix examples

parent ea33f4b5
Pipeline #856 passed with stage
in 20 minutes and 42 seconds
......@@ -107,7 +107,7 @@ int main(int argc, char* argv[])
typedef otb::BandsStatisticsAttributesLabelMapFilter<LabelMapType, VectorImageType> RadiometricLabelMapFilterType;
typedef otb::AttributesMapOpeningLabelMapFilter<LabelMapType> OpeningLabelMapFilterType;
typedef itk::LabelMapToBinaryImageFilter<LabelMapType, MaskImageType> LabelMapToBinaryImageFilterType;
typedef itk::UnaryFunctorImageFilter<VectorImageType, ImageType,otb::Functor::NDVI<PixelType,PixelType,PixelType> > NDVIImageFilterType;
typedef itk::UnaryFunctorImageFilter<VectorImageType, ImageType,otb::Functor::NDVI<PixelType,PixelType> > NDVIImageFilterType;
typedef otb::ImageToVectorImageCastFilter<ImageType, VectorImageType> ImageToVectorImageCastFilterType;
ReaderType::Pointer reader = ReaderType::New();
......@@ -166,8 +166,8 @@ int main(int argc, char* argv[])
// In our case, statistics are computed on the NDVI coefficient on each label object.
NDVIImageFilterType::Pointer ndviImageFilter = NDVIImageFilterType::New();
ndviImageFilter->GetFunctor().SetRedIndex(3);
ndviImageFilter->GetFunctor().SetNIRIndex(4);
ndviImageFilter->GetFunctor().SetBandIndex(otb::Functor::Band::RED,3);
ndviImageFilter->GetFunctor().SetBandIndex(otb::Functor::Band::NIR,4);
ndviImageFilter->SetInput(vreader->GetOutput());
ImageToVectorImageCastFilterType::Pointer ndviVectorImageFilter = ImageToVectorImageCastFilterType::New();
......
......@@ -26,8 +26,7 @@
Output/pretty_ARVIMultiChannelRAndBAndNIRVegetationIndex.png \
1 \
3 \
2 \
0.6
2
*/
......@@ -87,11 +86,11 @@
int main(int argc, char* argv[])
{
if (argc < 8)
if (argc < 7)
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage , outputImage , prettyInput , prettyOutput , redChannel , blueChannel , nirChannel , gama" << std::endl;
std::cerr << " inputImage , outputImage , prettyInput , prettyOutput , redChannel , blueChannel , nirChannel" << std::endl;
return 1;
}
......@@ -114,7 +113,7 @@ int main(int argc, char* argv[])
// Note that we also can use other functors which operate with the
// Red, Blue and Nir channels such as EVI, ARVI and TSARVI.
typedef otb::Functor::ARVI<InputPixelType, InputPixelType, InputPixelType, OutputPixelType> FunctorType;
typedef otb::Functor::ARVI<InputPixelType, OutputPixelType> FunctorType;
// The
// \doxygen{itk}{UnaryFunctorImageFilter}
......@@ -134,17 +133,9 @@ int main(int argc, char* argv[])
writer->SetFileName(argv[2]);
// The three used index bands (red, blue and NIR) are declared.
filter->GetFunctor().SetRedIndex(::atoi(argv[5]));
filter->GetFunctor().SetBlueIndex(::atoi(argv[6]));
filter->GetFunctor().SetNIRIndex(::atoi(argv[7]));
// The $\gamma$ parameter is set. The
// \doxygen{otb::Functor}{ARVI}
// class sets the default value of $\gamma$ to $0.5$. This parameter
// is used to reduce the atmospheric effect on a global scale.
filter->GetFunctor().SetGamma(::atof(argv[8]));
filter->GetFunctor().SetBandIndex(otb::Functor::Band::RED,::atoi(argv[5]));
filter->GetFunctor().SetBandIndex(otb::Functor::Band::GREEN,::atoi(argv[6]));
filter->GetFunctor().SetBandIndex(otb::Functor::Band::NIR,::atoi(argv[7]));
// The filter input is linked to the reader output and
// the filter output is linked to the writer input.
......
......@@ -26,10 +26,7 @@
Output/pretty_AVIMultiChannelRAndGAndNIRVegetationIndex.png \
3 \
2 \
4 \
660 \
560 \
830
4
*/
......@@ -76,12 +73,11 @@
int main(int argc, char* argv[])
{
if (argc < 11)
if (argc < 8)
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage , outputImage , prettyInput , prettyOutput , redChannel , greenChannel , nirChannel ,";
std::cerr << " lambdaR, lambdaG, lambdaNIR " << std::endl;
std::cerr << " inputImage , outputImage , prettyInput , prettyOutput , redChannel , greenChannel , nirChannel ,"<<std::endl;
return 1;
}
......@@ -102,7 +98,7 @@ int main(int argc, char* argv[])
// The AVI (Angular Vegetation Index) is
// instantiated using the image pixel types as template parameters.
typedef otb::Functor::AVI<InputPixelType, InputPixelType, InputPixelType, OutputPixelType> FunctorType;
typedef otb::Functor::AVI<InputPixelType, OutputPixelType> FunctorType;
// The
// \doxygen{itk}{UnaryFunctorImageFilter}
......@@ -123,18 +119,9 @@ int main(int argc, char* argv[])
// The three used index bands (red, green and NIR) are declared.
filter->GetFunctor().SetRedIndex(::atoi(argv[5]));
filter->GetFunctor().SetGreenIndex(::atoi(argv[6]));
filter->GetFunctor().SetNIRIndex(::atoi(argv[7]));
// The $\lambda$ R, G and NIR parameters are set. The
// \doxygen{otb::Functor}{AVI}
// class sets the default values of $\lambda$ to $660$, $560$ and
// $830$.
filter->GetFunctor().SetLambdaR(::atof(argv[8]));
filter->GetFunctor().SetLambdaG(::atof(argv[9]));
filter->GetFunctor().SetLambdaNir(::atof(argv[10]));
filter->GetFunctor().SetBandIndex(otb::Functor::Band::RED,::atoi(argv[5]));
filter->GetFunctor().SetBandIndex(otb::Functor::Band::GREEN,::atoi(argv[6]));
filter->GetFunctor().SetBandIndex(otb::Functor::Band::NIR,::atoi(argv[7]));
// The filter input is linked to the reader output and
// the filter output is linked to the writer input.
......
......@@ -32,10 +32,6 @@ endif()
add_executable(AVIMultiChannelRAndGAndNIRVegetationIndexImageFilter AVIMultiChannelRAndGAndNIRVegetationIndexImageFilter.cxx)
target_link_libraries(AVIMultiChannelRAndGAndNIRVegetationIndexImageFilter ${OTB_LIBRARIES})
add_executable(NDVIRAndNIRVegetationIndexImageFilter NDVIRAndNIRVegetationIndexImageFilter.cxx)
target_link_libraries(NDVIRAndNIRVegetationIndexImageFilter ${OTB_LIBRARIES})
if(BUILD_TESTING)
add_subdirectory(test)
endif()
/*
* Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* Example usage:
./NDVIRAndNIRVegetationIndexImageFilter Input/NDVI_2.hdr \
Input/NDVI_3.hdr \
Output/NDVIRAndNIRVegetationIndex.tif \
Output/pretty_Red.png \
Output/pretty_NIR.png \
Output/pretty_NDVIRAndNIRVegetationIndex.png
*/
// \index{otb::VegetationIndicesFunctor}
// \index{otb::VegetationIndicesFunctor!header}
//
// The following example illustrates the use of the
// \doxygen{itk}{BinaryFunctorImageFilter} 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}
//
// \relatedClasses
// \begin{itemize}
// \item \subdoxygen{otb}{Functor}{RVI}
// \item \subdoxygen{otb}{Functor}{PVI}
// \item \subdoxygen{otb}{Functor}{SAVI}
// \item \subdoxygen{otb}{Functor}{TSAVI}
// \item \subdoxygen{otb}{Functor}{MSAVI}
// \item \subdoxygen{otb}{Functor}{GEMI}
// \item \subdoxygen{otb}{Functor}{WDVI}
// \item \subdoxygen{otb}{Functor}{IPVI}
// \item \subdoxygen{otb}{Functor}{TNDVI}
// \end{itemize}
//
// Let's look at the minimal code required to use this algorithm.
#include "itkMacro.h"
#include "otbImage.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
#include "itkBinaryFunctorImageFilter.h"
#include "otbVegetationIndicesFunctor.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;
}
// The image types are now defined using pixel types the
// dimension. Input and output images are defined as \doxygen{otb}{Image}.
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;
// We instantiate reader and writer types
typedef otb::ImageFileReader<InputRImageType> RReaderType;
typedef otb::ImageFileReader<InputNIRImageType> NIRReaderType;
typedef otb::ImageFileWriter<OutputImageType> WriterType;
// The NDVI (Normalized Difference Vegetation Index) is instantiated using
// the images pixel type as template parameters. It is
// implemented as a functor class which will be passed as a
// parameter to an \doxygen{itk}{BinaryFunctorImageFilter}.
typedef otb::Functor::NDVI<InputPixelType, InputPixelType, OutputPixelType> FunctorType;
// The \doxygen{itk}{BinaryFunctorImageFilter} type is instantiated using the images
// types and the NDVI functor as template parameters.
typedef itk::BinaryFunctorImageFilter<InputRImageType, InputNIRImageType, OutputImageType, FunctorType> NDVIImageFilterType;
// Instantiating object
NDVIImageFilterType::Pointer filter = NDVIImageFilterType::New();
RReaderType::Pointer readerR = RReaderType::New();
NIRReaderType::Pointer readerNIR = NIRReaderType::New();
WriterType::Pointer writer = WriterType::New();
// Now the input images are set and a name is given to the output image.
readerR->SetFileName(argv[1]);
readerNIR->SetFileName(argv[2]);
writer->SetFileName(argv[3]);
// We set the processing pipeline: filter inputs are linked to
// the reader output and the filter output is linked to the writer
// input.
filter->SetInput1(readerR->GetOutput());
filter->SetInput2(readerNIR->GetOutput());
writer->SetInput(filter->GetOutput());
// Invocation of the \code{Update()} method on the writer triggers the
// execution of the pipeline. It is recommended to place \code{update()} calls in a
// \code{try/catch} block in case errors occur and exceptions are thrown.
try
{
writer->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;
}
// 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;
}
// 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 SISA and CNES)
// 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 left (Red channel and NIR channel), on the right the result of the algorithm.}
// \label{fig:NDVIRAndNIRIndex}
// \end{figure}
return EXIT_SUCCESS;
}
......@@ -35,7 +35,6 @@ otb_add_test(NAME raTeARVIMultiChannelRAndBAndNIRVegetationIndexImageFilterTest
1
2
3
0.6 # Gamma parameter
)
# ------- AVIMultiChannelRAndGAndNIRVegetationIndexImageFilterTest ------------------------------
......@@ -52,24 +51,6 @@ otb_add_test(NAME raTeAVIMultiChannelRAndGAndNIRVegetationIndexImageFilterTest C
3
2
4 # indices of the channels
660.
560.
830. # lambdaR, lambdaG, lambdaNir
)
# ------- NDVIRAndNIRVegetationIndexImageFilter ------------------------------
otb_add_test(NAME raTeNDVIRAndNIRVegetationIndexImageFilterTest COMMAND ${OTB_TEST_DRIVER}
--compare-image ${NOTOL}
${BASELINE}/NDVIRAndNIRVegetationIndex.tif
${TEMP}/NDVIRAndNIRVegetationIndex.tif
Execute $<TARGET_FILE:NDVIRAndNIRVegetationIndexImageFilter>
${INPUTDATA}/poupees_sub_c1.png
${INPUTDATA}/poupees_sub_c2.png
${TEMP}/NDVIRAndNIRVegetationIndex.tif
${TEMP}/NDVIRAndNIRVegetationIndex2.tif
${TEMP}/NDVIRAndNIRVegetationIndex3.tif
${TEMP}/NDVIRAndNIRVegetationIndex4.tif
)
if(OTBOpticalCalibration_LOADED)
......@@ -103,4 +84,4 @@ otb_add_test(NAME raTeAtmosphericCorrectionSequencementTest COMMAND ${OTB_TEST_D
2 # Radius;
0.020 # pixel spacing in kilometers
)
endif()
\ No newline at end of file
endif()
......@@ -64,7 +64,7 @@ int main(int argc, char* argv[])
// Filter type is a generic \doxygen{itk}{UnaryFunctorImageFilter} using Formosat2 specific LAI
// \doxygen{otb}{LAIFromNDVIFormosat2Functor}.
typedef otb::Functor::LAIFromNDVIFormosat2Functor<InputImageType::InternalPixelType, InputImageType::InternalPixelType, OutputImageType::PixelType>
typedef otb::Functor::LAIFromNDVIFormosat2Functor<InputImageType::InternalPixelType, OutputImageType::PixelType>
FunctorType;
typedef itk::UnaryFunctorImageFilter<InputImageType, OutputImageType, FunctorType> LAIFRomNDVIImageFilterType;
......@@ -96,8 +96,8 @@ int main(int argc, char* argv[])
//
unsigned int redChannel = static_cast<unsigned int>(atoi(argv[5]));
unsigned int nirChannel = static_cast<unsigned int>(atoi(argv[6]));
filter->GetFunctor().SetRedIndex(redChannel);
filter->GetFunctor().SetNIRIndex(nirChannel);
filter->GetFunctor().SetBandIndex(otb::Functor::Band::RED,redChannel);
filter->GetFunctor().SetBandIndex(otb::Functor::Band::NIR,nirChannel);
// The invocation of the \code{Update()} method triggers the
// execution of the pipeline.
......
......@@ -51,19 +51,19 @@ template<class TInput, class TOutput = double>
class RadiometricNonWaterNonVegetationIndexFunctor
{
public:
typedef Functor::NDVI<double, double, double> VegetationFunctorType;
typedef Functor::NDWI2<double, double, double> WaterFunctorType;
typedef Functor::NDVI<double, double> VegetationFunctorType;
typedef Functor::NDWI2<double, double> WaterFunctorType;
typedef TOutput ValueType;
VegetationFunctorType GetVegetationFunctor(){ return m_VegetationFunctor; }
WaterFunctorType GetWaterFunctor(){ return m_WaterFunctor; }
void SetRedIndex(int id){ m_VegetationFunctor.SetRedIndex(id); }
void SetGreenIndex(int id){ m_WaterFunctor.SetGIndex(id); }
void SetRedIndex(int id){ m_VegetationFunctor.SetBandIndex(otb::Functor::Band::RED,id); }
void SetGreenIndex(int id){ m_WaterFunctor.SetBandIndex(otb::Functor::Band::GREEN,id); }
void SetNIRIndex(int id)
{
m_VegetationFunctor.SetNIRIndex(id);
m_WaterFunctor.SetNIRIndex(id);
m_VegetationFunctor.SetBandIndex(otb::Functor::Band::NIR,id);
m_WaterFunctor.SetBandIndex(otb::Functor::Band::NIR,id);
}
RadiometricNonWaterNonVegetationIndexFunctor(){}
......
......@@ -25,6 +25,7 @@
#include <array>
#include <set>
#include <string>
#include <map>
namespace otb
{
......
......@@ -52,7 +52,7 @@ namespace otb
*
* \ingroup OTBSimulation
*/
template <class TReduceSpectralResponse , class TFunction = Functor::NDVI< typename TReduceSpectralResponse::ValuePrecisionType, typename TReduceSpectralResponse::ValuePrecisionType,
template <class TReduceSpectralResponse , class TFunction = Functor::NDVI< typename TReduceSpectralResponse::ValuePrecisionType,
typename TReduceSpectralResponse::ValuePrecisionType > >
class ReduceSpectralResponseClassifierRAndNIR
: public itk::DataObject
......
......@@ -50,7 +50,13 @@ namespace otb
ReduceSpectralResponseClassifierRAndNIR<TReduceSpectralResponse , TFunction>
::operator()()
{
return m_Functor((*m_InputReduceSpectralResponse)(m_RBandNumber), (*m_InputReduceSpectralResponse)(m_NIRBandNumber));
itk::VariableLengthVector<ValuePrecisionType> sr(2);
sr[0]=(*m_InputReduceSpectralResponse)(m_RBandNumber);
sr[1]=(*m_InputReduceSpectralResponse)(m_NIRBandNumber);
m_Functor.SetBandIndex(otb::Functor::Band::RED,0);
m_Functor.SetBandIndex(otb::Functor::Band::NIR,1);
return m_Functor(sr);
}
......
......@@ -45,7 +45,7 @@ int otbReduceSpectralResponseClassifierRAndNIR(int argc, char * argv[])
typedef otb::ReduceSpectralResponse < ResponseType, SatRSRType> ReduceResponseType;
typedef ReduceResponseType::Pointer ReduceResponseTypePointerType;
typedef otb::Functor::NDVI<double, double, double > TFunctionType;
typedef otb::Functor::NDVI<double, double> TFunctionType;
typedef otb::ReduceSpectralResponseClassifierRAndNIR <ReduceResponseType, TFunctionType> ReduceSpectralResponseClassifierRAndNIRType;
typedef ReduceSpectralResponseClassifierRAndNIRType::Pointer ReduceSpectralResponseClassifierRAndNIRPointerType;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment