[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

graph_rag_project_back.hxx
1/************************************************************************/
2/* */
3/* Copyright 2014 by Thorsten Beier and Ullrich Koethe */
4/* */
5/* This file is part of the VIGRA computer vision library. */
6/* The VIGRA Website is */
7/* http://hci.iwr.uni-heidelberg.de/vigra/ */
8/* Please direct questions, bug reports, and contributions to */
9/* ullrich.koethe@iwr.uni-heidelberg.de or */
10/* vigra@informatik.uni-hamburg.de */
11/* */
12/* Permission is hereby granted, free of charge, to any person */
13/* obtaining a copy of this software and associated documentation */
14/* files (the "Software"), to deal in the Software without */
15/* restriction, including without limitation the rights to use, */
16/* copy, modify, merge, publish, distribute, sublicense, and/or */
17/* sell copies of the Software, and to permit persons to whom the */
18/* Software is furnished to do so, subject to the following */
19/* conditions: */
20/* */
21/* The above copyright notice and this permission notice shall be */
22/* included in all copies or substantial portions of the */
23/* Software. */
24/* */
25/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
26/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
27/* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
28/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
29/* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
30/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
31/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
32/* OTHER DEALINGS IN THE SOFTWARE. */
33/* */
34/************************************************************************/
35
36/**
37 * This header provides definitions of graph-related algorithms
38 */
39
40#ifndef VIGRA_GRAPH_RAG_PROJECT_BACK_HXX
41#define VIGRA_GRAPH_RAG_PROJECT_BACK_HXX
42
43/*std*/
44#include <algorithm>
45#include <vector>
46#include <functional>
47#include <set>
48
49
50/*vigra*/
51#include "graphs.hxx"
52#include "graph_generalization.hxx"
53#include "multi_gridgraph.hxx"
54#include "priority_queue.hxx"
55#include "union_find.hxx"
56#include "adjacency_list_graph.hxx"
57#include "graph_maps.hxx"
58
59
60
61namespace vigra{
62
63 /// \cond
64 namespace detail_rag_project_back{
65
66 template<
67 class BASE_GRAPH,
68 class BASE_GRAPH_LABELS,
69 class RAG_FEATURES,
70 class BASE_GRAPH_FEATURES
71 >
72 struct RagProjectBack{
73
74
75 static void projectBack(
76 const AdjacencyListGraph & rag,
77 const BASE_GRAPH & bg,
78 const Int64 ignoreLabel,
79 const BASE_GRAPH_LABELS bgLabels,
80 const RAG_FEATURES & ragFeatures,
81 BASE_GRAPH_FEATURES & bgFeatures
82 ){
83 typedef BASE_GRAPH Bg;
84 typedef typename Bg::NodeIt BgNodeIt;
85 typedef typename Bg::Node BgNode;
86
87 if(ignoreLabel==-1){
88 for(BgNodeIt iter(bg); iter!=lemon::INVALID; ++iter){
89 const BgNode bgNode(*iter);
90 bgFeatures[bgNode] = ragFeatures[rag.nodeFromId(bgLabels[bgNode])];
91 }
92 }
93 else{
94 for(BgNodeIt iter(bg); iter!=lemon::INVALID; ++iter){
95 const BgNode bgNode(*iter);
96 if(static_cast<Int64>(bgLabels[bgNode])!=ignoreLabel)
97 bgFeatures[bgNode] = ragFeatures[rag.nodeFromId(bgLabels[bgNode])];
98 }
99 }
100 }
101 };
102
103
104 template<
105 class BASE_GRAPH_LABELS,
106 class RAG_FEATURES,
107 class BASE_GRAPH_FEATURES
108 >
109 struct RagProjectBack<
110 vigra::GridGraph<3, undirected_tag>,
111 BASE_GRAPH_LABELS,
112 RAG_FEATURES,
113 BASE_GRAPH_FEATURES
114 >{
115 typedef vigra::GridGraph<3, undirected_tag> BASE_GRAPH;
116
117 static void projectBack(
118 const AdjacencyListGraph & rag,
119 const BASE_GRAPH & bg,
120 const Int64 ignoreLabel,
121 const BASE_GRAPH_LABELS bgLabels,
122 const RAG_FEATURES & ragFeatures,
123 BASE_GRAPH_FEATURES & bgFeatures
124 ){
125 typedef BASE_GRAPH Bg;
126 typedef typename Bg::Node BgNode;
127
128
129 vigra::TinyVector<Int64, 3> shape = bg.shape();
130
131
132 if(ignoreLabel==-1){
133
134// FIXME: replace with threadpool #pragma omp parallel for
135 for(Int64 z=0; z<shape[2]; ++z){
136 BgNode node;
137 node[2]=z;
138 for(node[1]=0; node[1]<shape[1]; ++node[1])
139 for(node[0]=0; node[0]<shape[0]; ++node[0]){
140 bgFeatures[node] = ragFeatures[rag.nodeFromId(bgLabels[node])];
141 }
142 }
143
144 }
145 else{
146// FIXME: replace with threadpool #pragma omp parallel for
147 for(Int64 z=0; z<shape[2]; ++z){
148 BgNode node;
149 node[2]=z;
150 for(node[1]=0; node[1]<shape[1]; ++node[1])
151 for(node[0]=0; node[0]<shape[0]; ++node[0]){
152 if(static_cast<Int64>(bgLabels[node])!=ignoreLabel)
153 bgFeatures[node] = ragFeatures[rag.nodeFromId(bgLabels[node])];
154 }
155 }
156 }
157 }
158 };
159
160
161
162 }
163 /// \endcond
164
165 /// project node features of a region adjacency
166 /// graph back to the base graph.
167 ///
168 /// This function can be used to show a segmentation
169 /// or node features of RAG on pixel / voxel level
170 template< class BASE_GRAPH,
171 class BASE_GRAPH_LABELS,
172 class RAG_FEATURES,
173 class BASE_GRAPH_FEATURES
174 >
175 inline void projectBack(
176 const AdjacencyListGraph & rag,
177 const BASE_GRAPH & bg,
178 const Int64 ignoreLabel,
179 const BASE_GRAPH_LABELS bgLabels,
180 const RAG_FEATURES & ragFeatures,
181 BASE_GRAPH_FEATURES & bgFeatures
182 ){
183 using namespace detail_rag_project_back;
184 detail_rag_project_back::RagProjectBack< BASE_GRAPH,BASE_GRAPH_LABELS,RAG_FEATURES,BASE_GRAPH_FEATURES>::projectBack(rag,
185 bg,ignoreLabel,bgLabels,ragFeatures,bgFeatures);
186 }
187
188
189
190}
191
192#endif /* VIGRA_GRAPH_RAG_PROJECT_BACK_HXX */
193
undirected adjacency list graph in the LEMON API
Definition: adjacency_list_graph.hxx:228
Define a grid graph in arbitrary dimensions.
Definition: multi_gridgraph.hxx:1429
Class for fixed size vectors.
Definition: tinyvector.hxx:1008
detail::SelectIntegerType< 64, detail::SignedIntTypes >::type Int64
64-bit signed int
Definition: sized_int.hxx:177
void projectBack(const AdjacencyListGraph &rag, const BASE_GRAPH &bg, const Int64 ignoreLabel, const BASE_GRAPH_LABELS bgLabels, const RAG_FEATURES &ragFeatures, BASE_GRAPH_FEATURES &bgFeatures)
Definition: graph_rag_project_back.hxx:175

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de)
Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany

html generated using doxygen and Python
vigra 1.11.1