From 1cdeca05c1faa2fc5a299568da65c3f660d2c158 Mon Sep 17 00:00:00 2001 From: Aurelien Bricier <aurelien.bricier@c-s.fr> Date: Mon, 12 Nov 2012 17:49:22 +0100 Subject: [PATCH] ENH: added the LocalStatisticsExtraction application ans associated tests --- Applications/FeatureExtraction/CMakeLists.txt | 4 + .../otbLocalStatisticExtraction.cxx | 136 ++++++++++++++++++ .../FeatureExtraction/CMakeLists.txt | 12 +- 3 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 Applications/FeatureExtraction/otbLocalStatisticExtraction.cxx diff --git a/Applications/FeatureExtraction/CMakeLists.txt b/Applications/FeatureExtraction/CMakeLists.txt index 835e3c0bb1..19a849e816 100644 --- a/Applications/FeatureExtraction/CMakeLists.txt +++ b/Applications/FeatureExtraction/CMakeLists.txt @@ -26,4 +26,8 @@ OTB_CREATE_APPLICATION(NAME BinaryMorphologicalOperation OTB_CREATE_APPLICATION(NAME GrayScaleMorphologicalOperation SOURCES otbGrayScaleMorphologicalOperation.cxx LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters) + +OTB_CREATE_APPLICATION(NAME LocalStatisticExtraction + SOURCES otbLocalStatisticExtraction.cxx + LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters;OTBFeatureExtraction) \ No newline at end of file diff --git a/Applications/FeatureExtraction/otbLocalStatisticExtraction.cxx b/Applications/FeatureExtraction/otbLocalStatisticExtraction.cxx new file mode 100644 index 0000000000..9488cc0fe8 --- /dev/null +++ b/Applications/FeatureExtraction/otbLocalStatisticExtraction.cxx @@ -0,0 +1,136 @@ +/*========================================================================= + + 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 "otbWrapperApplication.h" +#include "otbWrapperApplicationFactory.h" + +#include "otbRadiometricMomentsImageFilter.h" + +#include "otbMultiToMonoChannelExtractROI.h" + +#include "itkTimeProbe.h" + +namespace otb +{ +namespace Wrapper +{ + +class LocalStatisticExtraction : public Application +{ +public: +/** Standard class typedefs. */ +typedef LocalStatisticExtraction Self; +typedef Application Superclass; +typedef itk::SmartPointer<Self> Pointer; +typedef itk::SmartPointer<const Self> ConstPointer; + +typedef MultiToMonoChannelExtractROI<FloatVectorImageType::InternalPixelType,FloatVectorImageType::InternalPixelType> +ExtractorFilterType; + +typedef RadiometricMomentsImageFilter<FloatImageType, FloatVectorImageType> +FilterType; + +/** Standard macro */ +itkNewMacro(Self); + +itkTypeMacro(LocalStatisticExtraction, otb::Application); + +private: + +void DoInit() +{ +SetName("LocalStatisticExtraction"); +SetDescription("Computes local statistics on every pixel of the input image selected channel"); + +// Documentation +SetDocName("Local Statistic Extraction"); +SetDocLongDescription("This application computes local Statistics on a mono band image"); +SetDocLimitations("None"); +SetDocAuthors("OTB-Team"); +SetDocSeeAlso("otbRadiometricMomentsImageFunction class"); + +AddDocTag("Statistics"); +AddDocTag(Tags::FeatureExtraction); + +AddParameter(ParameterType_InputImage, "in", "Input Image"); +SetParameterDescription("in", "The input image to compute the features on."); + +AddParameter(ParameterType_Int, "channel", "Selected Channel"); +SetParameterDescription("channel", "The selected channel index"); +SetDefaultParameterInt("channel", 1); +SetMinimumParameterIntValue("channel", 1); + +AddRAMParameter(); + +AddParameter(ParameterType_Int, "radius", "Neighborhood radius"); +SetParameterDescription("radius", "The computational window radius."); +SetMinimumParameterIntValue("radius",1); +SetDefaultParameterInt("radius",3); + +AddParameter(ParameterType_OutputImage, "out", "Feature Output Image"); +SetParameterDescription("out", "Output image containing the local statistic features."); + +// Doc example parameter settings +SetDocExampleParameterValue("in", "qb_RoadExtract.tif"); +SetDocExampleParameterValue("channel", "1"); +SetDocExampleParameterValue("parameters.spethre", "50.0"); +SetDocExampleParameterValue("parameters.spathre", "100"); +SetDocExampleParameterValue("out", "Statistics.tif"); +} + +void DoUpdateParameters() +{ + // Nothing to do here : all parameters are independent +} + +void DoExecute() +{ + FloatVectorImageType::Pointer inImage = GetParameterImage("in"); + inImage->UpdateOutputInformation(); + + if( GetParameterInt("channel") > inImage->GetNumberOfComponentsPerPixel() ) + { + otbAppLogCRITICAL("Selected band is not available..."); + return; + } + + m_ExtractorFilter = ExtractorFilterType::New(); + m_ExtractorFilter->SetInput(inImage); + m_ExtractorFilter->SetStartX(inImage->GetLargestPossibleRegion().GetIndex(0)); + m_ExtractorFilter->SetStartY(inImage->GetLargestPossibleRegion().GetIndex(1)); + m_ExtractorFilter->SetSizeX(inImage->GetLargestPossibleRegion().GetSize(0)); + m_ExtractorFilter->SetSizeY(inImage->GetLargestPossibleRegion().GetSize(1)); + m_ExtractorFilter->SetChannel(GetParameterInt("channel")); + m_ExtractorFilter->UpdateOutputInformation(); + + m_Filter = FilterType::New(); + m_Filter->SetInput(m_ExtractorFilter->GetOutput()); + m_Filter->SetRadius(GetParameterInt("radius")); + m_Filter->UpdateOutputInformation(); + + SetParameterOutputImage("out", m_Filter->GetOutput()); + +} +ExtractorFilterType::Pointer m_ExtractorFilter; +FilterType::Pointer m_Filter; + +}; +} +} + +OTB_APPLICATION_EXPORT(otb::Wrapper::LocalStatisticExtraction) diff --git a/Testing/Applications/FeatureExtraction/CMakeLists.txt b/Testing/Applications/FeatureExtraction/CMakeLists.txt index 2a5d3d875f..014eaee2a5 100644 --- a/Testing/Applications/FeatureExtraction/CMakeLists.txt +++ b/Testing/Applications/FeatureExtraction/CMakeLists.txt @@ -90,5 +90,15 @@ OTB_TEST_APPLICATION(NAME apTvFEGrayScaleMorphologicalOperation -out ${TEMP}/apTvFEGrayScaleMorphologicalOperation.tif VALID --compare-image ${NOTOL} ${BASELINE}/apTvFEGrayScaleMorphologicalOperation.tif - ${TEMP}/apTvFEGrayScaleMorphologicalOperation.tif) + ${TEMP}/apTvFEGrayScaleMorphologicalOperation.tif) + +OTB_TEST_APPLICATION(NAME apTvFELocalStatisticExtraction + APP LocalStatisticExtraction + OPTIONS -in ${INPUTDATA}/QB_Toulouse_Ortho_PAN.tif + -channel 1 + -radius 3 + -out ${TEMP}/apTvFELocalStatisticExtraction.tif + VALID --compare-image ${NOTOL} + ${BASELINE}/feTvRadiometricMomentsImageFilter.tif + ${TEMP}/apTvFELocalStatisticExtraction.tif) \ No newline at end of file -- GitLab