Эх сурвалжийг харах

fixed 'multiple defintions' in felzenszwalb segmentation

Sven Sickert 8 жил өмнө
parent
commit
a9c5c11eb0

+ 57 - 0
felzenszwalb/disjoint-set.cpp

@@ -0,0 +1,57 @@
+/*
+Copyright (C) 2006 Pedro Felzenszwalb
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+*/
+
+#include "disjoint-set.h"
+
+// disjoint-set forests using union-by-rank and path compression (sort of).
+using namespace felzenszwalb;
+
+universe::universe(int elements) {
+  elts = new uni_elt[elements];
+  num = elements;
+  for (int i = 0; i < elements; i++) {
+    elts[i].rank = 0;
+    elts[i].size = 1;
+    elts[i].p = i;
+  }
+}
+
+universe::~universe() {
+  delete [] elts;
+}
+
+int universe::find(int x) {
+  int y = x;
+  while (y != elts[y].p)
+    y = elts[y].p;
+  elts[x].p = y;
+  return y;
+}
+
+void universe::join(int x, int y) {
+  if (elts[x].rank > elts[y].rank) {
+    elts[y].p = x;
+    elts[x].size += elts[y].size;
+  } else {
+    elts[x].p = y;
+    elts[y].size += elts[x].size;
+    if (elts[x].rank == elts[y].rank)
+      elts[y].rank++;
+  }
+  num--;
+}

+ 0 - 35
felzenszwalb/disjoint-set.h

@@ -41,41 +41,6 @@ private:
   int num;
 };
 
-universe::universe(int elements) {
-  elts = new uni_elt[elements];
-  num = elements;
-  for (int i = 0; i < elements; i++) {
-    elts[i].rank = 0;
-    elts[i].size = 1;
-    elts[i].p = i;
-  }
-}
-  
-universe::~universe() {
-  delete [] elts;
-}
-
-int universe::find(int x) {
-  int y = x;
-  while (y != elts[y].p)
-    y = elts[y].p;
-  elts[x].p = y;
-  return y;
-}
-
-void universe::join(int x, int y) {
-  if (elts[x].rank > elts[y].rank) {
-    elts[y].p = x;
-    elts[x].size += elts[y].size;
-  } else {
-    elts[x].p = y;
-    elts[y].size += elts[x].size;
-    if (elts[x].rank == elts[y].rank)
-      elts[y].rank++;
-  }
-  num--;
-}
-
 }//namespace
 
 #endif

+ 4 - 4
felzenszwalb/filter.h

@@ -46,7 +46,7 @@ static void normalize(std::vector<float> &mask) {
 /* make filters */
 #define MAKE_FILTER(name, fun)                                \
 static std::vector<float> make_ ## name (float sigma) {       \
-  sigma = std::max(sigma, 0.01F);			      \
+  sigma = std::max(sigma, 0.01F);                             \
   int len = (int)ceil(sigma * WIDTH) + 1;                     \
   std::vector<float> mask(len);                               \
   for (int i = 0; i < len; i++) {                             \
@@ -58,7 +58,7 @@ static std::vector<float> make_ ## name (float sigma) {       \
 MAKE_FILTER(fgauss, exp(-0.5*square(i/sigma)));
 
 /* convolve image with gaussian filter */
-static image<float> *smooth(image<float> *src, float sigma) {
+static image<float> *smooth2(image<float> *src, float sigma) {
   std::vector<float> mask = make_fgauss(sigma);
   normalize(mask);
 
@@ -72,9 +72,9 @@ static image<float> *smooth(image<float> *src, float sigma) {
 }
 
 /* convolve image with gaussian filter */
-image<float> *smooth(image<uchar> *src, float sigma) {
+static image<float> *smooth(image<uchar> *src, float sigma) {
   image<float> *tmp = imageUCHARtoFLOAT(src);
-  image<float> *dst = smooth(tmp, sigma);
+  image<float> *dst = smooth2(tmp, sigma);
   delete tmp;
   return dst;
 }

+ 2 - 2
felzenszwalb/segment-graph.h

@@ -31,7 +31,7 @@ typedef struct {
   int a, b;
 } edge;
 
-bool operator<(const edge &a, const edge &b) {
+static bool operator<(const edge &a, const edge &b) {
   return a.w < b.w;
 }
 
@@ -45,7 +45,7 @@ bool operator<(const edge &a, const edge &b) {
  * edges: array of edges.
  * c: constant for treshold function.
  */
-universe *segment_graph(int num_vertices, int num_edges, edge *edges, 
+static universe *segment_graph(int num_vertices, int num_edges, edge *edges, 
 			float c) { 
   // sort edges by weight
   std::sort(edges, edges + num_edges);

+ 5 - 5
felzenszwalb/segment-image.h

@@ -31,7 +31,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
 namespace felzenszwalb {
 // random color
-rgb random_rgb() {
+static rgb random_rgb() {
   rgb c;
   double r;
 
@@ -61,7 +61,7 @@ static inline float diff(image<float> *r, image<float> *g, image<float> *b,
  * min_size: minimum component size (enforced by post-processing stage).
  * num_ccs: number of connected components in the segmentation.
  */
-image<rgb> *segment_image(image<rgb> *im, float sigma, float c, int min_size,
+static image<rgb> *segment_image(image<rgb> *im, float sigma, float c, int min_size,
                           int *num_ccs) {
   //clog << "\nsegment_image: Sprung in die Methode" << endl;
   int width = im->width();
@@ -81,9 +81,9 @@ image<rgb> *segment_image(image<rgb> *im, float sigma, float c, int min_size,
       imRef(b, x, y) = imRef(im, x, y).b;
     }
   }
-  image<float> *smooth_r = smooth(r, sigma);
-  image<float> *smooth_g = smooth(g, sigma);
-  image<float> *smooth_b = smooth(b, sigma);
+  image<float> *smooth_r = smooth2(r, sigma);
+  image<float> *smooth_g = smooth2(g, sigma);
+  image<float> *smooth_b = smooth2(b, sigma);
   delete r;
   delete g;
   delete b;