Skip to content
Snippets Groups Projects
Commit 84291fb0 authored by Julien Michel's avatar Julien Michel
Browse files

TEST: Simplifying and robustifying test on RCC8 graph computation

parent 84db0207
No related branches found
No related tags found
No related merge requests found
......@@ -205,24 +205,7 @@ ADD_TEST(srTvPolygonListToRCC8GraphFilter ${SPATIALREASONING_TESTS2}
${BASELINE_FILES}/srTvPolygonListToRCC8GraphFilterOuptut.dot
${TEMP}/srTvPolygonListToRCC8GraphFilterOuptut.dot
otbPolygonListToRCC8GraphFilter
4
${TEMP}/srTvPolygonListToRCC8GraphFilterOuptut.dot
${INPUTDATA}/rcc8_mire1.png
${INPUTDATA}/rcc8_mire2.png
${INPUTDATA}/rcc8_mire3.png
${INPUTDATA}/rcc8_mire4.png)
ADD_TEST(srTvPolygonListToRCC8GraphFilter2 ${SPATIALREASONING_TESTS2}
--compare-ascii ${NOTOL}
${BASELINE_FILES}/srTvPolygonListToRCC8GraphFilter2Ouptut.dot
${TEMP}/srTvPolygonListToRCC8GraphFilter2Ouptut.dot
otbPolygonListToRCC8GraphFilter
3
${TEMP}/srTvPolygonListToRCC8GraphFilter2Ouptut.dot
${INPUTDATA}/Seg3InputForRCC8Graph.tif
${INPUTDATA}/Seg4InputForRCC8Graph.tif
${INPUTDATA}/Seg5InputForRCC8Graph.tif
)
${TEMP}/srTvPolygonListToRCC8GraphFilterOuptut.dot)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbSPATIALREASONINGTests3 ~~~~~~~~~~~~~~~~~~~~~~
......
......@@ -21,76 +21,89 @@
#include "otbObjectList.h"
#include "otbRCC8VertexBase.h"
#include "otbPolygonListToRCC8GraphFilter.h"
#include "otbImageFileReader.h"
#include "otbImage.h"
#include "itkMinimumMaximumImageCalculator.h"
#include "otbImageToEdgePathFilter.h"
#include "otbRCC8GraphFileWriter.h"
#include "otbSimplifyPathListFilter.h"
#include "itkMinimumMaximumImageCalculator.h"
int otbPolygonListToRCC8GraphFilter(int argc, char* argv[])
// typedefs
typedef otb::Polygon<> PolygonType;
typedef otb::ObjectList<PolygonType> PolygonListType;
typedef otb::RCC8VertexBase<PolygonType> VertexType;
typedef otb::RCC8Graph<VertexType> RCC8GraphType;
typedef otb::PolygonListToRCC8GraphFilter<PolygonListType, RCC8GraphType> RCC8GraphFilterType;
typedef otb::RCC8GraphFileWriter<RCC8GraphType> GraphWriterType;
PolygonType::VertexType Vertex(double i,double j)
{
const unsigned int Dimension = 2;
PolygonType::VertexType vertex;
vertex[0] = i;
vertex[1] = j;
int nbImages = atoi(argv[1]);
char * outfile = argv[2];
return vertex;
}
// typedefs
typedef otb::Polygon<> PolygonType;
typedef otb::ObjectList<PolygonType> PolygonListType;
typedef otb::RCC8VertexBase<PolygonType> VertexType;
typedef otb::RCC8Graph<VertexType> RCC8GraphType;
typedef otb::PolygonListToRCC8GraphFilter<PolygonListType, RCC8GraphType> RCC8GraphFilterType;
typedef otb::RCC8GraphFileWriter<RCC8GraphType> GraphWriterType;
typedef unsigned short PixelType;
typedef otb::Image<PixelType, Dimension> ImageType;
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef otb::ImageToEdgePathFilter<ImageType, PolygonType> EdgeExtractionFilterType;
typedef itk::MinimumMaximumImageCalculator<ImageType> MinMaxCalculatorType;
typedef otb::SimplifyPathListFilter<PolygonType> SimplifyPathFilterType;
int otbPolygonListToRCC8GraphFilter(int argc, char* argv[])
{
const unsigned int Dimension = 2;
char * outfile = argv[1];
PolygonListType::Pointer regions = PolygonListType::New();
RCC8GraphFilterType::SegmentationRangesType ranges;
// Reading input images
for (int cpt = 1; cpt <= nbImages; ++cpt)
{
ranges.push_back(regions->Size());
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[2 + cpt]);
reader->Update();
MinMaxCalculatorType::Pointer minMax = MinMaxCalculatorType::New();
minMax->SetImage(reader->GetOutput());
minMax->Compute();
for (PixelType p = minMax->GetMinimum(); p <= minMax->GetMaximum(); ++p)
{
if (p != 0)
{
EdgeExtractionFilterType::Pointer extraction = EdgeExtractionFilterType::New();
extraction->SetInput(reader->GetOutput());
extraction->SetForegroundValue(p);
extraction->Update();
if (extraction->GetOutput()->GetVertexList()->Size() > 2)
{
regions->PushBack(extraction->GetOutput());
}
}
}
}
// Simplifying regions
SimplifyPathFilterType::Pointer simplifier = SimplifyPathFilterType::New();
simplifier->SetInput(regions);
simplifier->GetFunctor().SetTolerance(0.1);
simplifier->Update();
ranges.push_back(0);
PolygonType::Pointer polygon = PolygonType::New();
polygon->AddVertex(Vertex(0,0));
polygon->AddVertex(Vertex(2,0));
polygon->AddVertex(Vertex(2,6));
polygon->AddVertex(Vertex(0,6));
regions->PushBack(polygon);
polygon = PolygonType::New();
polygon->AddVertex(Vertex(1,1));
polygon->AddVertex(Vertex(4,1));
polygon->AddVertex(Vertex(4,5));
polygon->AddVertex(Vertex(1,5));
regions->PushBack(polygon);
ranges.push_back(2);
polygon = PolygonType::New();
polygon->AddVertex(Vertex(3,1));
polygon->AddVertex(Vertex(4,1));
polygon->AddVertex(Vertex(4,2));
polygon->AddVertex(Vertex(3,2));
regions->PushBack(polygon);
polygon = PolygonType::New();
polygon->AddVertex(Vertex(5,1));
polygon->AddVertex(Vertex(8,1));
polygon->AddVertex(Vertex(8,5));
polygon->AddVertex(Vertex(5,5));
regions->PushBack(polygon);
ranges.push_back(4);
polygon = PolygonType::New();
polygon->AddVertex(Vertex(6,2));
polygon->AddVertex(Vertex(7,2));
polygon->AddVertex(Vertex(7,3));
polygon->AddVertex(Vertex(6,3));
regions->PushBack(polygon);
polygon = PolygonType::New();
polygon->AddVertex(Vertex(8,1));
polygon->AddVertex(Vertex(9,1));
polygon->AddVertex(Vertex(9,5));
polygon->AddVertex(Vertex(8,5));
regions->PushBack(polygon);
// Filter instantiation
RCC8GraphFilterType::Pointer filter = RCC8GraphFilterType::New();
filter->SetInput(simplifier->GetOutput());
filter->SetInput(regions);
filter->SetSegmentationRanges(ranges);
GraphWriterType::Pointer writer = GraphWriterType::New();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment