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

region_shrinking.hxx
1/************************************************************************/
2/* */
3/* Copyright 2012-2013 by 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#ifndef VIGRA_REGION_SHRINK_HXX
38#define VIGRA_REGION_SHRINK_HXX
39
40#include "multi_array.hxx"
41#include "multi_gridgraph.hxx"
42 namespace vigra {
43
44
45 template<unsigned int DIM, class LABEL_TYPE,class LABEL_TYPE_OUT>
46 void regionShrinking(
47 MultiArrayView<DIM,LABEL_TYPE> labels,
48 const size_t shrinkNpixels,
49 MultiArrayView<DIM,LABEL_TYPE_OUT> shrinkedLabels
50 ){
51 shrinkedLabels = labels;
52
53 typedef GridGraph<DIM, undirected_tag> Graph;
54 typedef typename Graph::Node Node;
55 //typedef typename Graph::Edge Edge;
56 typedef typename Graph::NodeIt graph_scanner;
57 typedef typename Graph::OutArcIt neighbor_iterator;
58
59 const Graph g(labels.shape());
60
61 // INITAL LOOP
62 for (graph_scanner n(g); n != lemon::INVALID; ++n){
63 const Node node(*n);
64 for (neighbor_iterator arc(g, node); arc != lemon::INVALID; ++arc){
65 const Node otherNode = g.target(arc);
66
67 if(labels[node]!=labels[otherNode]){
68 shrinkedLabels[node]=0;
69 shrinkedLabels[otherNode]=0;
70 }
71 }
72 }
73
74 MultiArray<DIM,bool> visited(labels.shape());
75 for(size_t r=0;r<shrinkNpixels-1;++r){
76 std::fill(visited.begin(),visited.end(),false);
77 for (graph_scanner n(g); n != lemon::INVALID; ++n){
78 const Node node(*n);
79 if(!visited[n] && shrinkedLabels[node]==0){
80 for (neighbor_iterator arc(g, node); arc != lemon::INVALID; ++arc){
81 const Node otherNode = g.target(arc);
82 shrinkedLabels[otherNode]=0;
83 visited[otherNode]=true;
84 }
85 }
86 }
87 }
88 }
89
90
91} // end namespace vigra
92
93#endif // VIGRA_REGION_SHRINK_HXX
vigra

© 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.12.1