Skip to content
Snippets Groups Projects
Commit e8a373d4 authored by Julien Malik's avatar Julien Malik
Browse files

ENH: add mean shift segmentation application

parent a5a27684
Branches
Tags
No related merge requests found
......@@ -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)
OTB_CREATE_APPLICATION(NAME MeanShiftSegmentation
SOURCES otbMeanShiftSegmentation.cxx
LINK_LIBRARIES OTBBasicFilters)
/*=========================================================================
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)
......@@ -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)
#--- 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 )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment