Commit 5367de74 authored by remi cresson's avatar remi cresson

FIX: add raffaele's patch

parent 45a3be1c
......@@ -18,6 +18,7 @@
#ifndef GRM_GRAPH_OPERATIONS_TXX
#define GRM_GRAPH_OPERATIONS_TXX
#include <otbImageFileReader.h>
#include <otbNoDataHelper.h>
#include "grmGraphOperations.h"
namespace grm
......@@ -37,7 +38,40 @@ namespace grm
const long unsigned int num_nodes = width * height;
seg.m_Graph.m_Nodes.reserve(num_nodes);
std::vector<bool> noDataFlags;
std::vector<double> noDataValues;
bool noDataPresent = otb::ReadNoDataFlags(inputImg->GetMetaDataDictionary(), noDataFlags, noDataValues);
typedef itk::ImageRegionIterator<ImageType> ImageIterator;
ImageIterator it(inputImg, inputImg->GetLargestPossibleRegion());
unsigned int i = 0;
for(it.GoToBegin(); !it.IsAtEnd(); ++it) {
NodePointerType n(new NodeType);
n->m_Id = i;
n->m_Valid = true;
n->m_Expired = (noDataPresent && otb::IsNoData<double>(it.Get(), noDataFlags, noDataValues));
n->m_IsMerged = true; // force to compute costs for the first iteration
n->m_Perimeter = 4;
n->m_Area = 1;
n->m_Bbox.m_UX = i % width;
n->m_Bbox.m_UY = i / width;
n->m_Bbox.m_W = 1;
n->m_Bbox.m_H = 1;
// An initial contour is the one aroun a pixel
ContourOperator::Push1(n->m_Contour);
ContourOperator::Push2(n->m_Contour);
ContourOperator::Push3(n->m_Contour);
ContourOperator::Push0(n->m_Contour);
seg.m_Graph.m_Nodes.push_back(n);
++i;
}
/*
for(long unsigned int i = 0;
i < num_nodes;
++i)
......@@ -62,8 +96,7 @@ namespace grm
seg.m_Graph.m_Nodes.push_back(n);
}
seg.InitFromImage();
*/
if(mask == FOUR)
{
......@@ -73,9 +106,10 @@ namespace grm
FOURNeighborhood(neighborhood, r->m_Id, width, height);
for(short j = 0; j < 4; ++j)
{
if(neighborhood[j] > -1 && !seg.m_Graph.m_Nodes[neighborhood[j]]->m_Expired)
if(neighborhood[j] > -1 && !seg.m_Graph.m_Nodes[neighborhood[j]]->m_Expired)
r->m_Edges.push_back(EdgeType( seg.m_Graph.m_Nodes[neighborhood[j]], 0, 1));
}
r->m_Valid = (r->m_Edges.size() > 0);
}
}
else
......@@ -84,19 +118,22 @@ namespace grm
{
long int neighborhood[8];
EIGHTNeighborhood(neighborhood, r->m_Id, width, height);
bool haveNeighbors = false;
for(short j = 0; j < 8; ++j)
{
if(neighborhood[j] > -1 && !seg.m_Graph.m_Nodes[neighborhood[j]]->m_Expired)
if(neighborhood[j] > -1 && !seg.m_Graph.m_Nodes[neighborhood[j]]->m_Expired)
{
if(j % 2 > 0)
if(j % 2 > 0)
r->m_Edges.push_back(EdgeType( seg.m_Graph.m_Nodes[neighborhood[j]], 0, 0));
else
r->m_Edges.push_back(EdgeType( seg.m_Graph.m_Nodes[neighborhood[j]], 0, 1));
}
}
r->m_Valid = (r->m_Edges.size() > 0);
}
}
seg.InitFromImage();
RemoveExpiredNodes(seg.m_Graph);
}
......@@ -116,6 +153,8 @@ namespace grm
for(auto& r : seg.m_Graph.m_Nodes)
{
if (r->m_Edges.size() == 0) continue;
min_cost = std::numeric_limits<float>::max();
idx = 0;
min_idx = 0;
......@@ -356,7 +395,7 @@ namespace grm
for(auto& region : seg.m_Graph.m_Nodes)
{
auto res_node = CheckLMBF(region, seg.GetThreshold());
if(res_node)
......@@ -506,7 +545,7 @@ namespace grm
return false;
for(auto& r : seg.m_Graph.m_Nodes)
r->m_Valid = true;
r->m_Valid = (r->m_Edges.size() > 0);
return merged;
}
......@@ -546,8 +585,10 @@ namespace grm
++idx;
}
}
assert(min_idx < r->m_Edges.size());
std::swap(r->m_Edges[0], r->m_Edges[min_idx]);
}
} // end of namespace grm
......
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