-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from DerThorsten/dev
Dev to master
- Loading branch information
Showing
17 changed files
with
589 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#pragma once | ||
|
||
|
||
namespace nifty{ | ||
namespace graph{ | ||
namespace graph_maps{ | ||
|
||
|
||
|
||
/** | ||
* @brief Implicit edge map | ||
* @details Convert a node map into an edge map by applying | ||
* a binary functor to the node maps values. | ||
* | ||
* @tparam GRAPH the graph type | ||
* @tparam NODE_MAP The node map. This can be a | ||
* (const) reference or a value type (in) case of proxy objects | ||
* @tparam BINARY_FUNCTOR a binary functor.This can be a | ||
* (const) reference or a value type. | ||
*/ | ||
template<class GRAPH, class NODE_MAP, class BINARY_FUNCTOR> | ||
class EdgeMapFromNodeMap { | ||
public: | ||
typedef GRAPH GraphType; | ||
typedef BINARY_FUNCTOR BinaryFunctorType; | ||
typedef typename BinaryFunctorType::value_type value_type; | ||
typedef NODE_MAP NodeMapType; | ||
|
||
/** | ||
* @brief construct edge map from node map and functor | ||
* | ||
* @param graph the graph | ||
* @param nodeMap the node map | ||
* @param binaryFunctor the binary functor | ||
*/ | ||
EdgeMapFromNodeMap( | ||
const GraphType & graph, | ||
NodeMapType nodeMap, | ||
BinaryFunctorType binaryFunctor | ||
) | ||
: graph_(graph), | ||
nodeMap_(nodeMap), | ||
binaryFunctor_(binaryFunctor){ | ||
} | ||
|
||
/** | ||
* @brief get the value for an edge | ||
* @details get the value for an edge | ||
* by calling the binary functor. The functor | ||
* is called with the node maps values at | ||
* the enpoints of the edge. | ||
* | ||
* @param edgeIndex the edge index | ||
* @return the value of the edge map | ||
*/ | ||
value_type operator[](const uint64_t edgeIndex)const{ | ||
const auto uv = graph_.uv(edgeIndex); | ||
const auto u = uv.first; | ||
const auto v = uv.second; | ||
return binaryFunctor_(nodeMap_[u], nodeMap_[v]); | ||
} | ||
|
||
private: | ||
const GraphType & graph_; | ||
NODE_MAP nodeMap_; | ||
BinaryFunctorType binaryFunctor_; | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} // namespace nifty::graph::graph_maps | ||
} // namespace nifty::graph | ||
} // namespace nifty | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
#pragma once | ||
|
||
|
||
#include <algorithm> // sort | ||
|
||
|
||
#include "vigra/priority_queue.hxx" | ||
#include "nifty/tools/changable_priority_queue.hxx" | ||
#include "nifty/ufd/ufd.hxx" | ||
|
||
namespace nifty{ | ||
namespace graph{ | ||
|
||
// \cond SUPPRESS_DOXYGEN | ||
namespace detail_watersheds_segmentation{ | ||
|
||
|
||
|
||
|
||
template< | ||
class GRAPH, | ||
class NODE_WEIGHTS, | ||
class SEEDS, | ||
class LABELS | ||
> | ||
void nodeWeightedWatershedsSegmentationImpl( | ||
const GRAPH & g, | ||
const NODE_WEIGHTS & nodeWeights, | ||
const SEEDS & seeds, | ||
LABELS & labels | ||
){ | ||
typedef GRAPH Graph; | ||
typedef typename NODE_WEIGHTS::value_type WeightType; | ||
typedef typename LABELS::value_type LabelType; | ||
//typedef typename Graph:: template EdgeMap<bool> EdgeBoolMap; | ||
typedef vigra::PriorityQueue<int64_t, WeightType,true> PQ; | ||
|
||
PQ pq; | ||
for(auto node : g.nodes()) | ||
labels[node] = seeds[node]; | ||
|
||
// put edges from nodes with seed on pq | ||
for(auto node : g.nodes()){ | ||
if(labels[node]!=static_cast<LabelType>(0)){ | ||
|
||
for(auto adj : g.adjacency(node)){ | ||
const auto edge = adj.edge(); | ||
const auto neigbour = adj.node(); | ||
//std::cout<<"n- node "<<g.id(neigbour)<<"\n"; | ||
if(labels[neigbour]==static_cast<LabelType>(0)){ | ||
const auto priority = nodeWeights[neigbour]; | ||
pq.push(edge,priority); | ||
//inPQ[edge]=true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
while(!pq.empty()){ | ||
|
||
const auto edge = pq.top(); | ||
pq.pop(); | ||
|
||
const auto u = g.u(edge); | ||
const auto v = g.v(edge); | ||
const LabelType lU = labels[u]; | ||
const LabelType lV = labels[v]; | ||
|
||
|
||
if(lU==0 && lV==0){ | ||
throw std::runtime_error("both have no labels"); | ||
} | ||
else if(lU!=0 && lV!=0){ | ||
// nothing to do | ||
} | ||
else{ | ||
|
||
const auto unlabeledNode = lU==0 ? u : v; | ||
const auto label = lU==0 ? lV : lU; | ||
|
||
// assign label to unlabeled node | ||
labels[unlabeledNode] = label; | ||
|
||
// iterate over the nodes edges | ||
for(auto adj : g.adjacency(unlabeledNode)){ | ||
const auto otherEdge = adj.edge(); | ||
const auto targetNode = adj.node(); | ||
if(labels[targetNode] == 0){ | ||
//if(inPQ[otherEdge] == false && labels[targetNode] == 0){ | ||
const auto priority = nodeWeights[targetNode]; | ||
pq.push(otherEdge,priority); | ||
// inPQ[otherEdge]=true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} // end namespace detail_watersheds_segmentation | ||
|
||
// \endcond | ||
|
||
|
||
/// \brief edge weighted watersheds Segmentataion | ||
/// | ||
/// \param g: input graph | ||
/// \param nodeWeights : node weights / node height | ||
/// \param seeds : seed must be non empty! | ||
/// \param[out] labels : resulting nodeLabeling (not necessarily dense) | ||
template<class GRAPH,class NODE_WEIGHTS,class SEEDS,class LABELS> | ||
void nodeWeightedWatershedsSegmentation( | ||
const GRAPH & g, | ||
const NODE_WEIGHTS & nodeWeights, | ||
const SEEDS & seeds, | ||
LABELS & labels | ||
){ | ||
detail_watersheds_segmentation::nodeWeightedWatershedsSegmentationImpl( | ||
g,nodeWeights,seeds,labels); | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} // namespace nifty::graph | ||
} // namespace nifty | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.