segmentation
All Data Structures Namespaces Files Functions Variables Modules Pages
RAList.cpp
1 /*******************************************************
2 
3  Mean Shift Analysis Library
4  =============================================
5 
6  The mean shift library is a collection of routines
7  that use the mean shift algorithm. Using this algorithm,
8  the necessary output will be generated needed
9  to analyze a given input set of data.
10 
11  Region Adjacency List:
12  =====================
13 
14  The Region Adjacency List class is used by the Image
15  Processor class in the construction of a Region Adjacency
16  Matrix, used by this class to applying transitive closure
17  and to prune spurious regions during image segmentation.
18 
19  The definition of the RAList class is provided below. Its
20  prototype is provided in "RAList.h".
21 
22 The theory is described in the papers:
23 
24  D. Comaniciu, P. Meer: Mean Shift: A robust approach toward feature
25  space analysis.
26 
27  C. Christoudias, B. Georgescu, P. Meer: Synergism in low level vision.
28 
29 and they are is available at:
30  http://www.caip.rutgers.edu/riul/research/papers/
31 
32 Implemented by Chris M. Christoudias, Bogdan Georgescu
33 ********************************************************/
34 //include Region Adjacency List class prototype
35 #include "segm/RAList.h"
36 
37 //include needed libraries
38 #include <stdio.h>
39 #include <assert.h>
40 #include <stdlib.h>
41 
42 /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
43 /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
44 /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ PUBLIC METHODS @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
45 /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
46 /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
47 
48  /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
49  /* Class Constructor and Destructor */
50  /*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/*/
51 
52 /*******************************************************/
53 /*Class Constructor */
54 /*******************************************************/
55 /*Constructs a RAList object. */
56 /*******************************************************/
57 /*Post: */
58 /* - a RAlist object has been properly constru- */
59 /* cted. */
60 /*******************************************************/
61 
62 RAList::RAList( void )
63 {
64  //initialize label and link
65  label = -1;
66  next = NULL;
67 
68  //initialize edge strenght weight and count
69  edgeStrength = 0;
70  edgePixelCount = 0;
71 }
72 
73 /*******************************************************/
74 /*Class Destructor */
75 /*******************************************************/
76 /*Destructrs a RAList object. */
77 /*******************************************************/
78 /*Post: */
79 /* - the RAList object has been properly dest- */
80 /* ructed. */
81 /*******************************************************/
82 
83 RAList::~RAList( void )
84 {
85  //do nothing
86 }
87 
88 /*******************************************************/
89 /*Insert */
90 /*******************************************************/
91 /*Insert a region node into the region adjacency list. */
92 /*******************************************************/
93 /*Pre: */
94 /* - entry is a node representing a connected re- */
95 /* gion */
96 /*Post: */
97 /* - entry has been inserted into the region adj- */
98 /* acency list if it does not already exist */
99 /* there. */
100 /* - if the entry already exists in the region */
101 /* adjacency list 1 is returned otherwise 0 is */
102 /* returned. */
103 /*******************************************************/
104 
105 int RAList::Insert(RAList *entry)
106 {
107 
108  //if the list contains only one element
109  //then insert this element into next
110  if(!next)
111  {
112  //insert entry
113  next = entry;
114  entry->next = NULL;
115 
116  //done
117  return 0;
118  }
119 
120  //traverse the list until either:
121 
122  //(a) entry's label already exists - do nothing
123  //(b) the list ends or the current label is
124  // greater than entry's label, thus insert the entry
125  // at this location
126 
127  //check first entry
128  if(next->label > entry->label)
129  {
130  //insert entry into the list at this location
131  entry->next = next;
132  next = entry;
133 
134  //done
135  return 0;
136  }
137 
138  //check the rest of the list...
139  exists = 0;
140  cur = next;
141  while(cur)
142  {
143  if(entry->label == cur->label)
144  {
145  //node already exists
146  exists = 1;
147  break;
148  }
149  else if((!(cur->next))||(cur->next->label > entry->label))
150  {
151  //insert entry into the list at this location
152  entry->next = cur->next;
153  cur->next = entry;
154  break;
155  }
156 
157  //traverse the region adjacency list
158  cur = cur->next;
159  }
160 
161  //done. Return exists indicating whether or not a new node was
162  // actually inserted into the region adjacency list.
163  return (int)(exists);
164 
165 }
166 
167 /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
168 /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
169 /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ END OF CLASS DEFINITION @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
170 /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
171 /*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
172