eccentricitytransform.hxx
|
 |
37 #ifndef VIGRA_ECCENTRICITYTRANSFORM_HXX
38 #define VIGRA_ECCENTRICITYTRANSFORM_HXX
45 #include "accumulator.hxx"
46 #include "multi_labeling.hxx"
47 #include "multi_distance.hxx"
48 #include "multi_resize.hxx"
49 #include "graph_algorithms.hxx"
55 template <
class Graph,
class WeightType,
56 class EdgeMap,
class Shape>
57 TinyVector<MultiArrayIndex, Shape::static_size>
58 eccentricityCentersOneRegionImpl(ShortestPathDijkstra<Graph, WeightType> & pathFinder,
59 const EdgeMap & weights, WeightType maxWeight,
60 Shape anchor, Shape
const & start, Shape
const & stop)
62 int maxIterations = 4;
63 for(
int k=0; k < maxIterations; ++k)
65 pathFinder.run(start, stop, weights, anchor, lemon::INVALID, maxWeight);
66 anchor = pathFinder.target();
70 Polygon<TinyVector<float, Shape::static_size> > path;
71 path.push_back_unsafe(anchor);
72 while(pathFinder.predecessors()[path.back()] != path.back())
73 path.push_back_unsafe(pathFinder.predecessors()[path.back()]);
74 return path[
roundi(path.arcLengthQuantile(0.5))];
77 template <
unsigned int N,
class T,
class S,
class Graph,
78 class ACCUMULATOR,
class DIJKSTRA,
class Array>
80 eccentricityCentersImpl(
const MultiArrayView<N, T, S> & src,
82 ACCUMULATOR
const & r,
83 DIJKSTRA & pathFinder,
87 typedef typename MultiArrayShape<N>::type Shape;
88 typedef typename Graph::Node Node;
89 typedef typename Graph::EdgeIt EdgeIt;
90 typedef float WeightType;
92 typename Graph::template EdgeMap<WeightType> weights(g);
93 WeightType maxWeight = 0.0,
96 AccumulatorChainArray<CoupledArrays<N, WeightType, T>,
97 Select< DataArg<1>, LabelArg<2>, Maximum> > a;
99 MultiArray<N, WeightType> distances(src.shape());
104 const Node u(g.u(*
edge)), v(g.v(*
edge));
105 const T label = src[u];
108 weights[*
edge] = NumericTraits<WeightType>::max();
112 WeightType weight =
norm(u - v) *
113 (get<Maximum>(a, label) + minWeight - 0.5*(distances[u] + distances[v]));
114 weights[*
edge] = weight;
115 maxWeight = std::max(weight, maxWeight);
119 maxWeight *= src.size();
121 T maxLabel = r.maxRegionLabel();
122 centers.resize(maxLabel+1);
124 for (T i=0; i <= maxLabel; ++i)
126 if(get<Count>(r, i) == 0)
128 centers[i] = eccentricityCentersOneRegionImpl(pathFinder, weights, maxWeight,
129 get<RegionAnchor>(r, i),
130 get<Coord<Minimum> >(r, i),
131 get<Coord<Maximum> >(r, i) + Shape(1));
171 template <
unsigned int N,
class T,
class S,
class Array>
178 typedef float WeightType;
183 AccumulatorChainArray<CoupledArrays<N, T>,
184 Select< DataArg<1>, LabelArg<1>,
188 eccentricityCentersImpl(src, g, a, pathFinder, centers);
233 template <
unsigned int N,
class T,
class S,
class Array>
242 typedef typename Graph::Node Node;
243 typedef typename Graph::EdgeIt EdgeIt;
244 typedef float WeightType;
246 vigra_precondition(src.
shape() == dest.
shape(),
247 "eccentricityTransformOnLabels(): Shape mismatch between src and dest.");
253 AccumulatorChainArray<CoupledArrays<N, T>,
254 Select< DataArg<1>, LabelArg<1>,
258 eccentricityCentersImpl(src, g, a, pathFinder, centers);
260 typename Graph::template EdgeMap<WeightType> weights(g);
263 const Node u(g.u(*
edge)), v(g.v(*
edge));
264 const T label = src[u];
266 weights[*
edge] = NumericTraits<WeightType>::max();
271 for (T i=0; i <= a.maxRegionLabel(); ++i)
272 if(get<Count>(a, i) > 0)
273 filtered_centers.push_back(centers[i]);
274 pathFinder.runMultiSource(weights, filtered_centers.begin(), filtered_centers.end());
275 dest = pathFinder.distances();
278 template <
unsigned int N,
class T,
class S>
281 MultiArrayView<N, S> dest)
283 ArrayVector<TinyVector<MultiArrayIndex, N> > centers;
292 #endif // VIGRA_ECCENTRICITYTRANSFORM_HXX