32 #ifndef GRAPH_SEGMENTATION_H 33 #define GRAPH_SEGMENTATION_H 35 #include <opencv2/opencv.hpp> 38 #define RAND() ((float) std::rand() / (RAND_MAX)) 81 float dr = std::abs(n.
r - m.
r);
82 float dg = std::abs(n.
g - m.
g);
83 float db = std::abs(n.
b - m.
b);
85 return (dr + dg + db);
104 D = std::sqrt(255*255 + 255*255 + 255*255);
112 float dr = n.
r - m.
r;
113 float dg = n.
g - m.
g;
114 float db = n.
b - m.
b;
116 return std::sqrt(dr*dr + dg*dg + db*db);
169 float threshold = std::min(S_n.
max_w + c/S_n.
n, S_m.
max_w + c/S_m.
n);
171 if (e.
w < threshold) {
206 distance = _distance;
220 void buildGraph(
const cv::Mat &image);
224 void oversegmentGraph();
229 void enforceMinimumSegmentSize(
int M);
234 cv::Mat deriveLabels();
unsigned long int n
Size of node after merging with other nodes.
Definition: image_graph.h:101
virtual float operator()(const ImageNode &n, const ImageNode &m)=0
Compute the distance given 2 nodes.
GraphSegmentationEuclideanRGB()
Constructor; sets normalization constant.
Definition: graph_segmentation.h:102
float max_w
Maximum weight.
Definition: image_graph.h:107
Represents a pixel in a video. Each pixel is represented by its color which is needed to compute the ...
Definition: image_graph.h:80
The magic part of the graph segmentation, i.e. s given two nodes decide whether to add an edge betwee...
Definition: graph_segmentation.h:131
void setMagic(GraphSegmentationMagic *_magic)
Set the magic part of graph segmentation.
Definition: graph_segmentation.h:212
unsigned char b
Blue channel.
Definition: image_graph.h:86
void setDistance(GraphSegmentationDistance *_distance)
Set the distance to use.
Definition: graph_segmentation.h:205
GraphSegmentationMagic * magic
The magic part of graph segmentation.
Definition: graph_segmentation.h:251
Manhatten (i.e. L1) distance.
Definition: graph_segmentation.h:67
GraphSegmentationMagic()
Constructor.
Definition: graph_segmentation.h:135
Euclidean RGB distance.
Definition: graph_segmentation.h:98
virtual float operator()(const ImageNode &n, const ImageNode &m)
Compute the distance given 2 nodes.
Definition: graph_segmentation.h:80
ImageGraph graph
The constructed and segmented image graph.
Definition: graph_segmentation.h:245
unsigned char r
Red channel.
Definition: image_graph.h:95
int H
Image height.
Definition: graph_segmentation.h:239
virtual float operator()(const ImageNode &n, const ImageNode &m)
Compute the distance given 2 nodes.
Definition: graph_segmentation.h:111
unsigned char g
Green channel.
Definition: image_graph.h:92
GraphSegmentationManhattenRGB()
Constructor; sets normalization constant.
Definition: graph_segmentation.h:71
Implementation of graph based image segmentation as described in the paper by Felzenswalb and Huttenl...
Definition: graph_segmentation.h:189
virtual bool operator()(const ImageNode &S_n, const ImageNode &S_m, const ImageEdge &e)
Decide whether to merge the two segments corresponding to the given nodes or not. ...
Definition: graph_segmentation.h:166
GraphSegmentationDistance()
Constructor.
Definition: graph_segmentation.h:50
Represents an image graph, consisting of one node per pixel which are 4-connected.
Definition: image_graph.h:115
Interface to be implemented by a concerete distance. The distance defines how the weights between nod...
Definition: graph_segmentation.h:46
GraphSegmentation()
Default constructor; uses the Manhatten distance.
Definition: graph_segmentation.h:193
virtual ~GraphSegmentationDistance()
Destructor.
Definition: graph_segmentation.h:54
float w
Edge weight.
Definition: image_graph.h:57
Definition: graph_segmentation.h:152
int W
Image widt.h.
Definition: graph_segmentation.h:242
Represents an edge between two pixels in an image. Each edge is characterized by a weight and the adj...
Definition: image_graph.h:44
virtual ~GraphSegmentation()
Destructor.
Definition: graph_segmentation.h:200
GraphSegmentationDistance * distance
The underlying distance to use.
Definition: graph_segmentation.h:248
GraphSegmentationMagicThreshold(float c)
Constructor; sets the threshold.
Definition: graph_segmentation.h:157