-
Notifications
You must be signed in to change notification settings - Fork 1
/
SRMSeg.h
82 lines (60 loc) · 2.19 KB
/
SRMSeg.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/***************************************************************
* Name: SRMSeg.h
* Purpose: Defines SRM (Statistical Region Merging) segmentation class
* Author: Muhammet Bastan ([email protected])
* Created: 27.05.2009
* update: 14.01.2011 (for OpenCV 2.2 Mat)
* Copyright: Muhammet Bastan (https://sites.google.com/site/mubastan)
* License:
**************************************************************/
#ifndef SRMSEG__H__
#define SRMSEG__H__
#include "opencv2/core/core.hpp"
#include "DisjointSet.h"
using namespace cv;
typedef struct
{
int reg1, reg2, delta;
} RegionPair;
class SRMSeg
{
public:
SRMSeg(int w, int h);
~SRMSeg();
void reallocate(int w, int h);
void allocate(int w, int h);
void deallocate();
void initializeMeans(Mat& image);
void segment(Mat& image, float Q = 40.0f, float minsize = 100.0f);
void segmentGraph(RegionPair* pairs, int numEdges);
void mergeSmall(RegionPair* pairs, int numEdges, int minsize);
int buildGraph4( Mat& image );
inline int distance(Vec3b& pix1, Vec3b& pix2);
//uchar labels (upto 255 components), may overfow!!
void getLabels( Mat& labels );
// integer labels
void getLabelsInt(Mat& labels);
/// draw the segment boundaries with the given color
void drawSegmentBoundaries( Mat& dst, Scalar bcolor = Scalar(0,255,222) );
/// Number of components in the current segmentation
int getNumComps() const { return ( dsf != NULL ) ? dsf->numSets() : -1; }
protected:
/// current image size
int width;
int height;
/// determines the coarseness/fineness of segmentation
/// larger value more (smaller) regions
float Q;
float minsize;
/// number of edges in the graph
int numEdges;
/// mean values for each channels, e.g., Red, Green, Blue
float* mean1;
float* mean2;
float* mean3;
/// region pairs, edges..
RegionPair* pairs;
/// disjoint set forest
DisjointSet* dsf;
};
#endif