diff --git a/Applications/CMakeLists.txt b/Applications/CMakeLists.txt index 9f8ea02ecc2d86a12c924edb188c6b5b1e4ec607..9f56b20aa0b03b2247294114e9daaabc6697341f 100644 --- a/Applications/CMakeLists.txt +++ b/Applications/CMakeLists.txt @@ -8,6 +8,7 @@ add_subdirectory(Classification) add_subdirectory(FeatureExtraction) add_subdirectory(Hyperspectral) add_subdirectory(Projections) +add_subdirectory(Segmentation) add_subdirectory(Util) add_subdirectory(Test) diff --git a/Applications/Segmentation/CMakeLists.txt b/Applications/Segmentation/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..7e8c199de28ba659b939cbc2f9e1a489af7cc04b --- /dev/null +++ b/Applications/Segmentation/CMakeLists.txt @@ -0,0 +1,4 @@ + +OTB_CREATE_APPLICATION(NAME MeanShiftSegmentation + SOURCES otbMeanShiftSegmentation.cxx + LINK_LIBRARIES OTBBasicFilters) diff --git a/Applications/Segmentation/otbMeanShiftSegmentation.cxx b/Applications/Segmentation/otbMeanShiftSegmentation.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c8060e5fc1b8f1099c5fac6b676b7e2441941e62 --- /dev/null +++ b/Applications/Segmentation/otbMeanShiftSegmentation.cxx @@ -0,0 +1,111 @@ +/*========================================================================= + + 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 "otbMeanShiftVectorImageFilter.h" + +namespace otb +{ +namespace Wrapper +{ + + +class MeanShiftSegmentation : public Application +{ +public: + /** Standard class typedefs. */ + typedef MeanShiftSegmentation Self; + typedef Application Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Standard macro */ + itkNewMacro(Self); + + itkTypeMacro(MeanShiftSegmentation, otb::Application); + +private: + + MeanShiftSegmentation() + { + SetName("MeanShiftSegmentation"); + SetDescription("Perfrom mean shift clustering"); + } + + virtual ~MeanShiftSegmentation() + { + } + + void DoCreateParameters() + { + AddParameter(ParameterType_InputImage, "in", "Input Image"); + AddParameter(ParameterType_OutputImage, "fout", "Filtered output"); + AddParameter(ParameterType_OutputImage, "cout", "Clustered output"); + AddParameter(ParameterType_OutputImage, "lout", "Label output"); + AddParameter(ParameterType_OutputImage, "cbout", "Cluster Boundaries output"); + MandatoryOff("fout"); + MandatoryOff("cout"); + MandatoryOff("lout"); + MandatoryOff("cbout"); + + AddParameter(ParameterType_Int, "spatialr", "Spatial radius"); + AddParameter(ParameterType_Float, "ranger", "Range radius"); + AddParameter(ParameterType_Int, "minsize", "Min region size"); + AddParameter(ParameterType_Float, "scale", "Scale"); + SetParameterInt("spatialr", 5); + SetParameterFloat("ranger", 15.0); + SetParameterInt("minsize", 100); + SetParameterFloat("scale", 100000.); + } + + void DoUpdateParameters() + { + // Nothing to do here : all parameters are independent + } + + void DoExecute() + { + FloatVectorImageType* input = GetParameterImage("in"); + + typedef otb::MeanShiftVectorImageFilter<FloatVectorImageType, FloatVectorImageType> MSFilterType; + MSFilterType::Pointer filter = MSFilterType::New(); + + filter->SetInput(input); + filter->SetSpatialRadius( GetParameterInt("spatialr") ); + filter->SetRangeRadius( GetParameterFloat("ranger") ); + filter->SetMinimumRegionSize( GetParameterInt("minsize") ); + filter->SetScale( GetParameterFloat("scale") ); + + m_Ref = filter; + + SetParameterOutputImage("fout", filter->GetOutput()); + SetParameterOutputImage("cout", filter->GetClusteredOutput()); + SetParameterOutputImage("lout", filter->GetLabeledClusteredOutput()); + SetParameterOutputImage("cbout", filter->GetClusterBoundariesOutput()); + } + + itk::LightObject::Pointer m_Ref; + +}; + + +} +} + +OTB_APPLICATION_EXPORT(otb::Wrapper::MeanShiftSegmentation) diff --git a/Testing/Applications/CMakeLists.txt b/Testing/Applications/CMakeLists.txt index dea71dd19c6f23b21f65fd0cf13bbacbe1e203a8..4deffb75678826d62613c2d39dd4915721f465ce 100644 --- a/Testing/Applications/CMakeLists.txt +++ b/Testing/Applications/CMakeLists.txt @@ -15,9 +15,11 @@ SET(OTBAPP_BASELINE_FILES ${OTB_DATA_ROOT}/Baseline/OTB-Applications/Files) SET(NOTOL 0.0) SET(EPSILON_3 0.001) +SET(EPSILON_7 0.0000001) SET(EPSILON_9 0.000000001) add_subdirectory(Classification) add_subdirectory(FeatureExtraction) add_subdirectory(Hyperspectral) +add_subdirectory(Segmentation) add_subdirectory(Util) diff --git a/Testing/Applications/Segmentation/CMakeLists.txt b/Testing/Applications/Segmentation/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..19b718f6242978cdc4dc010444b46c5bc4955163 --- /dev/null +++ b/Testing/Applications/Segmentation/CMakeLists.txt @@ -0,0 +1,25 @@ +#--- MeanShift ---# + +add_test(NAME apTvSeMeanShift + COMMAND otbTestDriver + --compare-n-images ${EPSILON_7} 4 + ${BASELINE}/bfMeanShiftVectorImageFilterOutput.tif + ${TEMP}/apTvSeMeanShift_FilterOutput.tif + ${BASELINE}/bfMeanShiftVectorImageFilterClusteredOutput.tif + ${TEMP}/apTvSeMeanShift_ClusteredOutput.tif + ${BASELINE}/bfMeanShiftVectorImageFilterLabeledClusteredOutput.tif + ${TEMP}/apTvSeMeanShift_LabeledClusteredOutput.tif + ${BASELINE}/bfMeanShiftVectorImageFilterClusterBoundariesOutput.tif + ${TEMP}/apTvSeMeanShift_ClusterBoundariesOutput.tif + Execute $<TARGET_FILE:otbApplicationLauncherCommandLine> + MeanShiftSegmentation + --modulePath $<TARGET_FILE_DIR:otbapp_MeanShiftSegmentation> + --in ${INPUTDATA}/qb_RoadExtract2sub200x200.tif + --fout ${TEMP}/apTvSeMeanShift_FilterOutput.tif + --cout ${TEMP}/apTvSeMeanShift_ClusteredOutput.tif + --lout ${TEMP}/apTvSeMeanShift_LabeledClusteredOutput.tif + --cbout ${TEMP}/apTvSeMeanShift_ClusterBoundariesOutput.tif + --spatialr 16 + --ranger 16 + --minsize 10 + --scale 1.0 )