Commit 565b4787 authored by Jonathan Guinet's avatar Jonathan Guinet
Browse files

ENH: MeanShiftSegmentation application, which duplicates Segmentation...

ENH: MeanShiftSegmentation application, which duplicates Segmentation application has been changed to MeanShiftSmoothing application.
parent 3dfaea46
OTB_CREATE_APPLICATION(NAME MeanShiftSegmentation
SOURCES otbMeanShiftSegmentation.cxx
OTB_CREATE_APPLICATION(NAME MeanShiftSmoothing
SOURCES otbMeanShiftSmoothing.cxx
LINK_LIBRARIES OTBBasicFilters)
OTB_CREATE_APPLICATION(NAME ConnectedComponentSegmentation
......
......@@ -18,7 +18,7 @@
#include "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
#include "otbMeanShiftVectorImageFilter.h"
#include "otbMeanShiftSmoothingImageFilter.h"
namespace otb
{
......@@ -26,75 +26,78 @@ namespace Wrapper
{
class MeanShiftSegmentation : public Application
class MeanShiftSmoothing : public Application
{
public:
/** Standard class typedefs. */
typedef MeanShiftSegmentation Self;
typedef MeanShiftSmoothing Self;
typedef Application Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef otb::MeanShiftVectorImageFilter<FloatVectorImageType, FloatVectorImageType> MSFilterType;
typedef otb::MeanShiftSmoothingImageFilter<FloatVectorImageType, FloatVectorImageType> MSFilterType;
/** Standard macro */
itkNewMacro(Self);
itkTypeMacro(MeanShiftSegmentation, otb::Application);
itkTypeMacro(MeanShiftSmoothing, otb::Application);
private:
void DoInit()
{
SetName("MeanShiftSegmentation");
SetDescription("Perform mean shift clustering");
SetName("MeanShiftSmoothing");
SetDescription("Perform mean shift filtering");
// Documentation
SetDocName("Mean Shift segmentation");
SetDocLongDescription("This application performs mean shift clustering.");
SetDocLimitations("This application relies on old mean shift implementation (EDISON), which is going to be replaced by new one.");
SetDocName("Mean Shift filtering");
SetDocLongDescription("This application performs mean shift fitlering (multi-threaded).");
SetDocLimitations("With mode search option, the result will slightly depend on thread number.");
SetDocAuthors("OTB-Team");
SetDocSeeAlso(" ");
AddDocTag(Tags::Segmentation);
AddDocTag(Tags::Filter);
AddParameter(ParameterType_InputImage, "in", "Input Image");
SetParameterDescription( "in", "The input image." );
AddParameter(ParameterType_OutputImage, "fout", "Filtered output");
SetParameterDescription( "fout", "The filtered output image." );
AddParameter(ParameterType_OutputImage, "cout", "Clustered output");
SetParameterDescription( "cout", "The clustered output image." );
AddParameter(ParameterType_OutputImage, "lout", "Label output");
SetParameterDescription( "lout", "The label output image." );
AddParameter(ParameterType_OutputImage, "cbout", "Cluster Boundaries output");
SetParameterDescription( "cbout", "The cluster boundaries output image." );
MandatoryOff("fout");
MandatoryOff("cout");
MandatoryOff("lout");
MandatoryOff("cbout");
AddParameter(ParameterType_Int, "spatialr", "Spatial radius");
SetParameterDescription( "spatialr", "Spatial radius defining neighborhood." );
AddParameter(ParameterType_Float, "ranger", "Range radius");
SetParameterDescription( "ranger", "Range radius defining the interval in the color space." );
AddParameter(ParameterType_Int, "minsize", "Min region size");
SetParameterDescription( "minsize", "Minimun size of a region to be kept after clustering." );
AddParameter(ParameterType_Float, "scale", "Scale");
SetParameterDescription( "scale", "Scale to stretch the image before processing." );
SetDefaultParameterInt("spatialr", 5);
SetDefaultParameterFloat("ranger", 15.0);
SetDefaultParameterInt("minsize", 100);
SetDefaultParameterFloat("scale", 100000.);
AddParameter(ParameterType_Int, "spatialr", "Spatial radius");
SetParameterDescription("spatialr", "Spatial radius of the neighborhood.");
AddParameter(ParameterType_Float, "ranger", "Range radius");
SetParameterDescription("ranger", "Range radius defining the radius (expressed in radiometry unit) in the multi-spectral space.");
AddParameter(ParameterType_Float, "thres", "Mode convergence threshold");
SetParameterDescription("thres", "Algorithm iterative scheme will stop if mean-shift "
"vector is below this threshold or if iteration number reached maximum number of iterations.");
MandatoryOff("thres");
AddParameter(ParameterType_Int, "maxiter", "Maximum number of iterations");
SetParameterDescription("maxiter", "Algorithm iterative scheme will stop if convergence hasn't been reached after the maximum number of iterations.");
MandatoryOff("maxiter");
AddParameter(ParameterType_Empty, "modesearch", "Mode search.");
SetParameterDescription("modesearch", "If activated pixel iterative convergence is stopped if the path . Be careful, with this option, the result will slightly depend on thread number");
EnableParameter("modesearch");
MandatoryOff("modesearch");
SetDefaultParameterInt("spatialr", 5);
SetDefaultParameterFloat("ranger", 15.0);
SetDefaultParameterFloat("thres", 0.1);
SetMinimumParameterFloatValue("thres", 0.1);
SetDefaultParameterInt("maxiter", 100);
SetMinimumParameterIntValue("maxiter", 1);
// Doc example parameter settings
SetDocExampleParameterValue("in", "maur_rgb.png");
SetDocExampleParameterValue("cout", "MeanShift_ClusteredOutput.tif");
SetDocExampleParameterValue("fout", "MeanShift_FilterOutput.tif");
SetDocExampleParameterValue("lout", "MeanShift_LabeledClusteredOutput.tif uint32");
SetDocExampleParameterValue("cbout", "MeanShift_ClusterBoundariesOutput.tif uint8");
SetDocExampleParameterValue("spatialr", "16");
SetDocExampleParameterValue("ranger", "16");
SetDocExampleParameterValue("minsize", "10");
SetDocExampleParameterValue("scale", "1.0");
SetDocExampleParameterValue("thres", "0.1");
SetDocExampleParameterValue("maxiter", "100");
}
......@@ -110,16 +113,21 @@ private:
m_Filter = MSFilterType::New();
m_Filter->SetInput(input);
m_Filter->SetSpatialRadius(GetParameterInt("spatialr"));
m_Filter->SetRangeRadius(GetParameterFloat("ranger"));
m_Filter->SetMinimumRegionSize(GetParameterInt("minsize"));
m_Filter->SetScale(GetParameterFloat("scale"));
if (IsParameterEnabled("fout") && HasValue("fout")) SetParameterOutputImage("fout", m_Filter->GetOutput());
if (IsParameterEnabled("cout") && HasValue("cout")) SetParameterOutputImage("cout", m_Filter->GetClusteredOutput());
if (IsParameterEnabled("lout") && HasValue("lout")) SetParameterOutputImage<UInt16ImageType> ("lout", m_Filter->GetLabeledClusteredOutput());
if (IsParameterEnabled("cbout") && HasValue("cbout")) SetParameterOutputImage<UInt16ImageType> ("cbout", m_Filter->GetClusterBoundariesOutput());
}
m_Filter->SetSpatialBandwidth(GetParameterInt("spatialr"));
m_Filter->SetRangeBandwidth(GetParameterFloat("ranger"));
m_Filter->SetThreshold(GetParameterFloat("thres"));
m_Filter->SetMaxIterationNumber(GetParameterInt("maxiter"));
if(!IsParameterEnabled("modesearch"))
{
otbAppLogINFO(<<"Mode Search is disabled." << std::endl);
m_Filter->SetModeSearch(false);
}
SetParameterOutputImage("fout", m_Filter->GetOutput());
}
MSFilterType::Pointer m_Filter;
......@@ -129,4 +137,4 @@ private:
}
}
OTB_APPLICATION_EXPORT(otb::Wrapper::MeanShiftSegmentation)
OTB_APPLICATION_EXPORT(otb::Wrapper::MeanShiftSmoothing)
#--- MeanShift ---#
OTB_TEST_APPLICATION(NAME apTvSeMeanShift
APP MeanShiftSegmentation
OPTIONS -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
VALID --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)
#OTB_TEST_APPLICATION(NAME apTvSeMeanShift
# APP MeanShiftSegmentation
# OPTIONS -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
# VALID --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)
#--- ConnectedComponentSegmentation ---#
......
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