Commit 2de54084 authored by Guillaume Pasero's avatar Guillaume Pasero

REFAC: remove code using Edison meanshift

parent 132e6742
......@@ -28,9 +28,6 @@
#include "itkGradientMagnitudeImageFilter.h"
#include "otbWatershedSegmentationFilter.h"
#include "otbMorphologicalProfilesSegmentationFilter.h"
#ifdef OTB_USE_EDISON
#include "otbMeanShiftVectorImageFilter.h"
#endif
// Large scale vectorization framework
#include "otbStreamingImageToOGRLayerSegmentationFilter.h"
......@@ -61,13 +58,6 @@ public:
typedef UInt32ImageType MaskImageType;
// Segmentation filters typedefs
#ifdef OTB_USE_EDISON
// Edison mean-shift
typedef otb::MeanShiftVectorImageFilter
<FloatVectorImageType,
FloatVectorImageType,
LabelImageType> EdisonSegmentationFilterType;
#endif
// Home made mean-shift
typedef otb::MeanShiftSegmentationFilter
......@@ -110,12 +100,6 @@ public:
<FloatVectorImageType, MaskImageType> MaskMuParserFilterType;
// Vectorize filters
#ifdef OTB_USE_EDISON
// Edison mean-shift
typedef otb::StreamingImageToOGRLayerSegmentationFilter
<FloatVectorImageType,
EdisonSegmentationFilterType> EdisontreamingVectorizedSegmentationOGRType;
#endif
// Home made mean-shift
typedef otb::StreamingImageToOGRLayerSegmentationFilter
......@@ -212,27 +196,6 @@ private:
SetDefaultParameterInt("filter.meanshift.maxiter", 100);
SetMinimumParameterIntValue("filter.meanshift.maxiter", 1);
#ifdef OTB_USE_EDISON
AddChoice("filter.edison", "Edison mean-shift");
SetParameterDescription("filter.edison",
"Edison implementation of mean-shift algorithm, by its authors.");
// EDISON Meanshift Parameters
AddParameter(ParameterType_Int, "filter.edison.spatialr", "Spatial radius");
SetParameterDescription("filter.edison.spatialr", "Spatial radius defining neighborhood.");
AddParameter(ParameterType_Float, "filter.edison.ranger", "Range radius");
SetParameterDescription("filter.edison.ranger", "Range radius defining the radius (expressed in radiometry unit) in the multi-spectral space.");
AddParameter(ParameterType_Int, "filter.edison.minsize", "Minimum region size");
SetParameterDescription("filter.edison.minsize", "Minimum size of a region in segmentation. Smaller clusters will be merged to the neighboring cluster with the closest radiometry.");
AddParameter(ParameterType_Float, "filter.edison.scale", "Scale factor");
SetParameterDescription("filter.edison.scale", "Scaling of the image before processing. This is useful for images with narrow decimal ranges (like [0,1] for instance). ");
SetDefaultParameterInt("filter.edison.spatialr", 5);
SetDefaultParameterFloat("filter.edison.ranger", 15.0);
SetDefaultParameterInt("filter.edison.minsize", 100);
SetMinimumParameterIntValue("filter.edison.minsize", 0);
SetDefaultParameterFloat("filter.edison.scale", 1.);
#endif
//Connected component segmentation parameters
AddChoice("filter.cc", "Connected components");
SetParameterDescription("filter.cc", "Simple pixel-based connected-components algorithm with a user-defined connection condition.");
......@@ -600,34 +563,6 @@ private:
"in"),
layer, 0);
}
#ifdef OTB_USE_EDISON
else
if (segType == "edison")
{
otbAppLogINFO(<<"Use Edison Mean-shift segmentation."<<std::endl);
//segmentation parameters
const unsigned int spatialRadius = static_cast<unsigned int> (this->GetParameterInt("filter.edison.spatialr"));
const float rangeRadius = static_cast<float> (this->GetParameterFloat("filter.edison.ranger"));
const unsigned int
minimumObjectSize = static_cast<unsigned int> (this->GetParameterInt("filter.edison.minsize"));
const float scale = this->GetParameterFloat("filter.edison.scale");
EdisontreamingVectorizedSegmentationOGRType::Pointer
edisonVectorizationFilter = EdisontreamingVectorizedSegmentationOGRType::New();
edisonVectorizationFilter->GetSegmentationFilter()->SetSpatialRadius(spatialRadius);
edisonVectorizationFilter->GetSegmentationFilter()->SetRangeRadius(rangeRadius);
edisonVectorizationFilter->GetSegmentationFilter()->SetMinimumRegionSize(minimumObjectSize);
edisonVectorizationFilter->GetSegmentationFilter()->SetScale(scale);
streamSize = GenericApplySegmentation<FloatVectorImageType, EdisonSegmentationFilterType> (
edisonVectorizationFilter,
this->GetParameterFloatVectorImage(
"in"),
layer, 2);
}
#endif
else
if (segType == "meanshift")
{
......
......@@ -24,9 +24,6 @@ otb_module(OTBAppSegmentation
OTBLabelMap
OTBProjection
OPTIONAL_DEPENDS
OTBEdisonMeanShift
TEST_DEPENDS
OTBTestKernel
OTBCommandLine
......
......@@ -24,9 +24,6 @@ set(vector_ref_path ${BASELINE_FILES})
set(raster_ref_path ${BASELINE})
set(fitlerList "Meanshift" "CC" "Watershed")
if(OTB_USE_EDISON)
list(APPEND fitlerList "Edison")
endif()
# Loop on modes
foreach(mode "Raster" "Vector")
......
......@@ -444,7 +444,7 @@ private:
* D. Comaniciu, P. Meer, "Mean Shift Analysis and Applications," iccv, p. 1197, Seventh International Conference
* on Computer Vision (ICCV'99) - Volume 2, 1999
*
* \sa MeanShiftImageFilter
* \sa MeanShiftSegmentationFilter
*
* \ingroup ImageSegmentation
* \ingroup ImageEnhancement
......
......@@ -13,9 +13,6 @@ otb_module(OTBOGRProcessing
OTBLabelling
OTBGDAL
OTBITK
OPTIONAL_DEPENDS
OTBEdisonMeanShift
TEST_DEPENDS
OTBTestKernel
......
......@@ -5,76 +5,11 @@ otbOGRProcessingTestDriver.cxx
otbOGRLayerStreamStitchingFilter.cxx
)
if(OTB_USE_EDISON)
list(APPEND OTBOGRProcessingTests otbStreamingImageToOGRLayerSegmentationFilter.cxx)
endif()
add_executable(otbOGRProcessingTestDriver ${OTBOGRProcessingTests})
target_link_libraries(otbOGRProcessingTestDriver ${OTBOGRProcessing-Test_LIBRARIES})
otb_module_target_label(otbOGRProcessingTestDriver)
# Tests Declaration
if(OTB_USE_EDISON)
otb_add_test(NAME obTvStreamingImageToOGRLayerSegmentationFilter COMMAND otbOGRProcessingTestDriver
--compare-ogr ${EPSILON_8}
${BASELINE_FILES}/obTvStreamingVectorizedSegmentationOutput.sqlite
${TEMP}/obTvStreamingVectorizedSegmentationOutput.sqlite
otbStreamingImageToOGRLayerSegmentationFilter
${INPUTDATA}/QB_Toulouse_Ortho_PAN.tif
${INPUTDATA}/QB_Toulouse_Ortho_PAN_Mask.tif
${TEMP}/obTvStreamingVectorizedSegmentationOutput.sqlite
NewLayer
100
5
15.
100
1 #filter small object
200 #minimum size of object
0 #Simplify Flag
0.2 #Simplification tolerance
)
otb_add_test(NAME obTuStreamingImageToOGRLayerSegmentationFilterNew COMMAND otbOGRProcessingTestDriver
otbStreamingImageToOGRLayerSegmentationFilterNew)
otb_add_test(NAME obTvStreamingImageToOGRLayerSegmentationFilterHalfSpacing COMMAND otbOGRProcessingTestDriver
--compare-ogr ${EPSILON_8}
${BASELINE_FILES}/obTvStreamingVectorizedSegmentationHalfSpacingOutput.sqlite
${TEMP}/obTvStreamingVectorizedSegmentationHalfSpacingOutput.sqlite
otbStreamingImageToOGRLayerSegmentationFilter
${INPUTDATA}/QB_Toulouse_Ortho_PAN_HalfSpacing.tif
${INPUTDATA}/QB_Toulouse_Ortho_PAN_Mask_HalfSpacing.tif
${TEMP}/obTvStreamingVectorizedSegmentationHalfSpacingOutput.sqlite
NewLayer
100
5
15.
100
1 #filter small object
200 #minimum size of object
0 #Simplify Flag
0.2 #Simplification tolerance
)
otb_add_test(NAME obTvStreamingImageToOGRLayerSegmentationFilterQBOrthoWGS84shp COMMAND otbOGRProcessingTestDriver
--compare-ogr ${EPSILON_8}
${BASELINE_FILES}/obTvStreamingVectorizedSegmentationOutputQBOrthoWGS84.shp
${TEMP}/obTvStreamingVectorizedSegmentationOutputQBOrthoWGS84.shp
otbStreamingImageToOGRLayerSegmentationFilter
${INPUTDATA}/QB_Toulouse_Ortho_PAN_WGS84.tif
${INPUTDATA}/QB_Toulouse_Ortho_PAN_Mask_WGS84.tif
${TEMP}/obTvStreamingVectorizedSegmentationOutputQBOrthoWGS84.shp
NewLayer
100
5
15.
100
1 #filter small object
200 #minimum size of object
0 #Simplify Flag
0.2 #Simplification tolerance
)
endif()
otb_add_test(NAME obTuOGRLayerStreamStitchingFilter COMMAND otbOGRProcessingTestDriver
--compare-ogr ${EPSILON_8}
......
#include "otbTestMain.h"
void RegisterTests()
{
#ifdef OTB_USE_EDISON
REGISTER_TEST(otbStreamingImageToOGRLayerSegmentationFilterNew);
REGISTER_TEST(otbStreamingImageToOGRLayerSegmentationFilter);
#endif
REGISTER_TEST(otbOGRLayerStreamStitchingFilter);
}
/*=========================================================================
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 "otbVectorImage.h"
#include "otbStreamingImageToOGRLayerSegmentationFilter.h"
#include "otbImageFileReader.h"
#include "otbMeanShiftVectorImageFilter.h"
#include "otbPersistentImageToOGRDataFilter.h"
#include "otbOGRDataSourceWrapper.h"
int otbStreamingImageToOGRLayerSegmentationFilterNew(int itkNotUsed(argc), char * itkNotUsed(argv)[])
{
typedef float InputPixelType;
const unsigned int Dimension = 2;
/** Typedefs */
typedef otb::Image<InputPixelType, Dimension> ImageType;
typedef otb::MeanShiftImageFilter<ImageType, ImageType> MeanShiftImageFilterType;
typedef otb::StreamingImageToOGRLayerSegmentationFilter<ImageType, MeanShiftImageFilterType>::FilterType StreamingImageToOGRLayerSegmentationFilterType;
StreamingImageToOGRLayerSegmentationFilterType::Pointer filter = StreamingImageToOGRLayerSegmentationFilterType::New();
std::cout << filter << std::endl;
return EXIT_SUCCESS;
}
int otbStreamingImageToOGRLayerSegmentationFilter(int argc, char * argv[])
{
if (argc != 13)
{
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage maskImage outputVec layerName TileDimension"
<< "spatialRadius rangeRadius minObjectSize filterSmallObj minSize"
<< "SimplifyFlag Tolerance" << std::endl;
return EXIT_FAILURE;
}
const char * imageName = argv[1];
const char * maskName = argv[2];
const char * dataSourceName = argv[3];
const char * layerName = argv[4];
const unsigned int tileSize = atoi(argv[5]);
const unsigned int spatialRadiusOldMS = atoi(argv[6]);
const double rangeRadiusOldMS = atof(argv[7]);
const unsigned int minimumObjectSizeOldMS = atoi(argv[8]);
const bool filterSmallObj = atoi(argv[9]);
const unsigned int minSize = atoi(argv[10]);
const bool simplify = atoi(argv[11]);
const double tolerance = atof(argv[12]);
typedef float InputPixelType;
const unsigned int Dimension = 2;
const std::string fieldName("DN");
// Typedefs
typedef otb::VectorImage<InputPixelType, Dimension> ImageType;
typedef otb::Image<unsigned int, Dimension> LabelImageType;
//old mean shift filter
typedef otb::MeanShiftVectorImageFilter<ImageType, ImageType, LabelImageType> SegmentationFilterType;
typedef otb::StreamingImageToOGRLayerSegmentationFilter<ImageType, SegmentationFilterType> StreamingImageToOGRLayerSegmentationFilterType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef otb::ImageFileReader<LabelImageType> MaskReaderType;
ReaderType::Pointer reader = ReaderType::New();
MaskReaderType::Pointer maskReader = MaskReaderType::New();
StreamingImageToOGRLayerSegmentationFilterType::Pointer filter = StreamingImageToOGRLayerSegmentationFilterType::New();
reader->SetFileName(imageName);
reader->UpdateOutputInformation();
maskReader->SetFileName(maskName);
maskReader->UpdateOutputInformation();
// Create the output data-source in overwrite mode
// TODO: Change once flags have been updated
otb::ogr::DataSource::Pointer ogrDS = otb::ogr::DataSource::New(dataSourceName, otb::ogr::DataSource::Modes::Overwrite);
OGRSpatialReference oSRS(reader->GetOutput()->GetProjectionRef().c_str());
// Create the layer
otb::ogr::Layer oLayer = ogrDS->CreateLayer(layerName,&oSRS,wkbMultiPolygon);
// Create the field
OGRFieldDefn field(fieldName.c_str(),OFTInteger);
oLayer.CreateField(field,true);
filter->SetInput(reader->GetOutput());
filter->SetInputMask(maskReader->GetOutput());
filter->SetOGRLayer(oLayer);
filter->GetStreamer()->SetTileDimensionTiledStreaming(tileSize);
filter->SetFieldName(fieldName);
filter->SetStartLabel(1);
filter->SetUse8Connected(false);
filter->SetFilterSmallObject(filterSmallObj);
filter->SetMinimumObjectSize(minSize);
filter->SetSimplify(simplify);
filter->SetSimplificationTolerance(tolerance);
filter->GetSegmentationFilter()->SetSpatialRadius(spatialRadiusOldMS);
filter->GetSegmentationFilter()->SetRangeRadius(rangeRadiusOldMS);
filter->GetSegmentationFilter()->SetMinimumRegionSize(minimumObjectSizeOldMS);
filter->Initialize(); //must be called !
filter->Update();
return EXIT_SUCCESS;
}
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