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

- Implémentation du calcul du graphe RCC8...

- Implémentation du calcul du graphe RCC8 (otbImageMultiSegmentationToRCC8GraphFilter), sans l'optimisation de la table de composition.
- Correction d'une erreur dans l'otbBinaryImageMinimalBoudingRegionCalculator.
parent d6f9e6b3
Branches
Tags
No related merge requests found
...@@ -131,7 +131,7 @@ BinaryImageMinimalBoundingRegionCalculator<TInputImage> ...@@ -131,7 +131,7 @@ BinaryImageMinimalBoundingRegionCalculator<TInputImage>
for(int i=0;i<InputImageType::ImageDimension;i++) for(int i=0;i<InputImageType::ImageDimension;i++)
{ {
// If we are not on boundary case, we can do what we want // If we are not on boundary case, we can do what we want
if(min[i]> maxRegion.GetIndex()[i]) if(min[i]-m_Pad> maxRegion.GetIndex()[i])
{ {
index[i]= min[i]-m_Pad; index[i]= min[i]-m_Pad;
} }
......
...@@ -43,22 +43,16 @@ public: ...@@ -43,22 +43,16 @@ public:
itkTypeMacro(ImageMultiSegmentationToRCC8GraphFilter,ImageListToRCC8GraphFilter); itkTypeMacro(ImageMultiSegmentationToRCC8GraphFilter,ImageListToRCC8GraphFilter);
/** Input related typedefs */ /** Input related typedefs */
typedef TInputImage InputImageType; typedef TInputImage InputImageType;
typedef typename InputImageType::PixelType PixelType;
typedef typename InputImageType::Pointer InputImagePointerType; typedef typename InputImageType::Pointer InputImagePointerType;
typedef typename Superclass::InputImageListType InputImageListType;
typedef typename InputImageListType::Pointer InputImageListPointerType;
typedef typename InputImageListType::ConstIterator ConstListIteratorType;
/** Output related typedefs */ /** Output related typedefs */
typedef TOutputGraph OutputGraphType; typedef TOutputGraph OutputGraphType;
typedef typename OutputGraphType::Pointer OutputGraphPointerType; typedef typename OutputGraphType::Pointer OutputGraphPointerType;
typedef typename OutputGraphType::VertexType VertexType; typedef typename OutputGraphType::VertexType VertexType;
typedef typename VertexType::Pointer VertexPointerType; typedef typename VertexType::Pointer VertexPointerType;
/* /// Get The statistics for the different relations */
/* itkGetConstMacro(TotalNumberOfRegions,int); */
/* itkGetConstMacro(NumberOfRelations,int); */
/* /// Get the number of regions by segmentation image */
/* std::vector<int> GetNumberOfRegions(void); */
/* /// Set a filter to not take in account relations whose index is */
/* /// under the threshold */
/* itkGetConstMacro(RelationFilter,int); */
/* itkSetMacro(RelationFilter,int); */
protected: protected:
/** Constructor */ /** Constructor */
...@@ -71,9 +65,6 @@ protected: ...@@ -71,9 +65,6 @@ protected:
void PrintSelf(std::ostream& os, itk::Indent indent) const; void PrintSelf(std::ostream& os, itk::Indent indent) const;
private: private:
/* int m_NumberOfRelations; */
/* int m_TotalNumberOfRegions; */
/* std::vector<unsigned int> m_NumberOfRegions; */
}; };
} // End namespace otb } // End namespace otb
......
...@@ -19,8 +19,9 @@ ...@@ -19,8 +19,9 @@
#define _otbImageMultiSegmentationToRCC8GraphFilter_txx #define _otbImageMultiSegmentationToRCC8GraphFilter_txx
#include "otbImageMultiSegmentationToRCC8GraphFilter.h" #include "otbImageMultiSegmentationToRCC8GraphFilter.h"
#include "itkMinimumMaximumImageFilter.h" #include "itkMinimumMaximumImageCalculator.h"
#include "otbImageToImageRCC8Calculator.h" #include "otbImageToImageRCC8Calculator.h"
#include "otbRCC8VertexIterator.h"
namespace otb namespace otb
{ {
...@@ -45,7 +46,89 @@ template <class TInputImage, class TOutputGraph> ...@@ -45,7 +46,89 @@ template <class TInputImage, class TOutputGraph>
void void
ImageMultiSegmentationToRCC8GraphFilter<TInputImage, TOutputGraph> ImageMultiSegmentationToRCC8GraphFilter<TInputImage, TOutputGraph>
::GenerateData() ::GenerateData()
{} {
// Input image list pointer
InputImageListPointerType segList = this->GetInput();
// Ouptut graph pointer
OutputGraphPointerType graph = this->GetOutput();
// Some typedefs
typedef itk::MinimumMaximumImageCalculator<InputImageType> MinMaxCalculatorType;
typedef ImageToImageRCC8Calculator<InputImageType> RCC8CalculatorType;
typedef RCC8VertexIterator<OutputGraphType> VertexIteratorType;
// Vector of label
std::vector<PixelType> maxLabelVector;
// Vertex indexes
unsigned int vertexIndex = 0;
unsigned int segmentationImageIndex = 0;
// For each segmentation image
for(ConstListIteratorType it = segList->Begin();it!=segList->End();++it)
{
// Compute the maximum label
typename MinMaxCalculatorType::Pointer minMax = MinMaxCalculatorType::New();
minMax->SetImage(it.Get());
minMax->ComputeMaximum();
maxLabelVector.push_back(minMax->GetMaximum());
otbMsgDebugMacro(<<"Number of objects in image "<<segmentationImageIndex<<": "
<<minMax->GetMaximum());
// then for each region of the images
for(PixelType label=1; label<=maxLabelVector.back();++label)
{
// Create a new vertex
VertexPointerType vertex = VertexType::New();
// Set its properties
vertex->SetSegmentationImageIndex(segmentationImageIndex);
vertex->SetObjectLabelInImage(label);
// Put it in the graph
graph->SetVertex(vertexIndex,vertex);
vertexIndex++;
}
segmentationImageIndex++;
}
VertexIteratorType vIt1(graph);
VertexIteratorType vIt2(graph);
// For each couple of vertices
for(vIt1.GoToBegin();!vIt1.IsAtEnd();++vIt1)
{
for(vIt2.GoToBegin();!vIt2.IsAtEnd();++vIt2)
{
// Get the segmentation images indexes
unsigned int source = vIt1.Get()->GetSegmentationImageIndex();
unsigned int target = vIt2.Get()->GetSegmentationImageIndex();
// We do not examine each couple because of the RCC8 simetry
if(source<target)
{
// Get the labels of source and target
PixelType label1 = vIt1.Get()->GetObjectLabelInImage();
PixelType label2 = vIt2.Get()->GetObjectLabelInImage();
// Compute the RCC8 relation
typename RCC8CalculatorType::Pointer calc = RCC8CalculatorType::New();
calc->SetInput1(segList->GetNthElement(source));
calc->SetInsideValue1(label1);
calc->SetInput2(segList->GetNthElement(target));
calc->SetInsideValue2(label2);
calc->Update();
// If the vertices are connected
if(calc->GetValue()>OTB_RCC8_DC)
{
// Add the edge to the graph.
otbMsgDebugMacro(<<"Adding edge: "<<source<<" -> "<<target<<": "<<calc->GetValue());
graph->AddEdge(vIt1.GetIndex(),vIt2.GetIndex(),calc->GetValue());
}
}
}
}
}
template <class TInputImage, class TOutputGraph> template <class TInputImage, class TOutputGraph>
void void
ImageMultiSegmentationToRCC8GraphFilter<TInputImage, TOutputGraph> ImageMultiSegmentationToRCC8GraphFilter<TInputImage, TOutputGraph>
......
...@@ -130,6 +130,8 @@ namespace otb ...@@ -130,6 +130,8 @@ namespace otb
rc->SetInsideValue(this->GetInsideValue2()); rc->SetInsideValue(this->GetInsideValue2());
rc->Update(); rc->Update();
region2=rc->GetRegion(); region2=rc->GetRegion();
// otbMsgDebugMacro(<<"RCC8Calculator->ComputeMinimalRegion() Region1: index: "<<region1.GetIndex()<<" size: "<<region1.GetSize());
// otbMsgDebugMacro(<<"RCC8Calculator->ComputeMinimalRegion() Region2: index: "<<region2.GetIndex()<<" size: "<<region2.GetSize());
typename ImageType::SizeType size; typename ImageType::SizeType size;
typename ImageType::IndexType index; typename ImageType::IndexType index;
...@@ -167,6 +169,8 @@ ImageToImageRCC8Calculator<TInputImage> ...@@ -167,6 +169,8 @@ ImageToImageRCC8Calculator<TInputImage>
typename BoolImageType::IndexType boolImageIndex; typename BoolImageType::IndexType boolImageIndex;
boolImageIndex[0]=m_MinimalROI.GetIndex()[0]-1; boolImageIndex[0]=m_MinimalROI.GetIndex()[0]-1;
boolImageIndex[1]=m_MinimalROI.GetIndex()[1]-1; boolImageIndex[1]=m_MinimalROI.GetIndex()[1]-1;
//otbMsgDebugMacro(<<"RCC8Calculator->ConvertToBoolImage() size: "<<boolImageSize<<" index: "<<boolImageIndex);
typename BoolImageType::RegionType boolRegion; typename BoolImageType::RegionType boolRegion;
boolRegion.SetSize(boolImageSize); boolRegion.SetSize(boolImageSize);
boolRegion.SetIndex(boolImageIndex); boolRegion.SetIndex(boolImageIndex);
...@@ -184,7 +188,7 @@ ImageToImageRCC8Calculator<TInputImage> ...@@ -184,7 +188,7 @@ ImageToImageRCC8Calculator<TInputImage>
++inputIt; ++inputIt;
++outputIt; ++outputIt;
} }
// otbMsgDebugMacro(<<"RCC8Calculator->ConvertToBoolImage() size: "<<output->GetLargestPossibleRegion().GetSize());
return output; return output;
} }
/** /**
......
...@@ -97,7 +97,7 @@ ADD_TEST(bfTvBoundingRegionCalculator ${BASICFILTERS_TESTS} ...@@ -97,7 +97,7 @@ ADD_TEST(bfTvBoundingRegionCalculator ${BASICFILTERS_TESTS}
${BASELINE_FILES}/bfBoundingRegionCalculatorOutput.txt ${BASELINE_FILES}/bfBoundingRegionCalculatorOutput.txt
${TEMP}/bfBoundingRegionCalculatorOutput.txt ${TEMP}/bfBoundingRegionCalculatorOutput.txt
otbBinaryImageMinimalBoundingRegionCalculator otbBinaryImageMinimalBoundingRegionCalculator
4 5
${TEMP}/bfBoundingRegionCalculatorOutput.txt ${TEMP}/bfBoundingRegionCalculatorOutput.txt
${INPUTDATA}/rcc8_mire1.png ${INPUTDATA}/rcc8_mire1.png
${INPUTDATA}/rcc8_mire2.png ${INPUTDATA}/rcc8_mire2.png
......
...@@ -127,20 +127,17 @@ ADD_TEST(srTuMultiSegToRCC8GraphFilterNew ${SPATIALREASONING_TESTS} ...@@ -127,20 +127,17 @@ ADD_TEST(srTuMultiSegToRCC8GraphFilterNew ${SPATIALREASONING_TESTS}
otbImageMultiSegmentationToRCC8GraphFilterNew) otbImageMultiSegmentationToRCC8GraphFilterNew)
#ADD_TEST(srTvMultiSegToRCC8GraphFilter ${SPATIALREASONING_TESTS} ADD_TEST(srTvMultiSegToRCC8GraphFilter ${SPATIALREASONING_TESTS}
# --compare-ascii ${TOL} --compare-ascii ${TOL}
# ${BASELINE_FILES}/srRCC8GraphFilterOutput.dot ${BASELINE_FILES}/srRCC8GraphFilterOutput.dot
# ${TEMP}/srRCC8GraphFilterOutput.dot ${TEMP}/srRCC8GraphFilterOutput.dot
# otbImageMultiSegmentationToRCC8GraphFilter otbImageMultiSegmentationToRCC8GraphFilter
# ${TEMP}/srRCC8GraphFilterOutput.dot ${TEMP}/srRCC8GraphFilterOutput.dot
# 4 2
# ${INPUTDATA}/ ${INPUTDATA}/Seg1InputForRCC8Graph.tif
# ${INPUTDATA}/ ${INPUTDATA}/Seg2InputForRCC8Graph.tif
# ${INPUTDATA}/
# ${INPUTDATA}/ )
#)
# ------- Fichiers sources CXX ----------------------------------- # ------- Fichiers sources CXX -----------------------------------
SET(BasicSpatialReasoning_SRCS SET(BasicSpatialReasoning_SRCS
...@@ -162,7 +159,7 @@ otbRCC8GraphFileReader.cxx ...@@ -162,7 +159,7 @@ otbRCC8GraphFileReader.cxx
otbRCC8GraphIOEndToEnd.cxx otbRCC8GraphIOEndToEnd.cxx
otbImageListToRCC8GraphFilterNew.cxx otbImageListToRCC8GraphFilterNew.cxx
otbImageMultiSegmentationToRCC8GraphFilterNew.cxx otbImageMultiSegmentationToRCC8GraphFilterNew.cxx
#otbImageMultiSegmentationToRCC8GraphFilter.cxx otbImageMultiSegmentationToRCC8GraphFilter.cxx
) )
INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}") INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}")
......
...@@ -46,21 +46,21 @@ try ...@@ -46,21 +46,21 @@ try
ImageListType::Pointer inputList = ImageListType::New(); ImageListType::Pointer inputList = ImageListType::New();
// Reading input images // Reading input images
for(int i=3;i<nbImages+2;i++) for(int i=0;i<nbImages;i++)
{ {
ReaderType::Pointer reader = ReaderType::New(); ReaderType::Pointer reader = ReaderType::New();
reader->SetFilename(argv[i]); reader->SetFileName(argv[3+i]);
reader->Update(); reader->Update();
inputList->PushBack(reader->GetOutput()); inputList->PushBack(reader->GetOutput());
} }
std::cout<<"Input image loaded into images list."<<std::endl;
// Instanatiation // Instanatiation
RCC8GraphFilterType::Pointer filter = RCC8GraphFilterType::New(); RCC8GraphFilterType::Pointer filter = RCC8GraphFilterType::New();
filter->SetInput(inputList); filter->SetInput(inputList);
// Writing output graph // Writing output graph
GraphWriterType::Pointer writer = GraphWriterType::New(); GraphWriterType::Pointer writer = GraphWriterType::New();
writer->SetFilename(outputFilename); writer->SetFileName(outputFilename);
writer->SetInput(filter->GetOutput()); writer->SetInput(filter->GetOutput());
writer->Update(); writer->Update();
......
...@@ -44,5 +44,5 @@ REGISTER_TEST(otbRCC8GraphFileReader); ...@@ -44,5 +44,5 @@ REGISTER_TEST(otbRCC8GraphFileReader);
REGISTER_TEST(otbRCC8GraphIOEndToEnd); REGISTER_TEST(otbRCC8GraphIOEndToEnd);
REGISTER_TEST(otbImageListToRCC8GraphFilterNew); REGISTER_TEST(otbImageListToRCC8GraphFilterNew);
REGISTER_TEST(otbImageMultiSegmentationToRCC8GraphFilterNew); REGISTER_TEST(otbImageMultiSegmentationToRCC8GraphFilterNew);
//REGISTER_TEST(otbImageMultiSegmentationToRCC8GraphFilter); REGISTER_TEST(otbImageMultiSegmentationToRCC8GraphFilter);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment