-
Notifications
You must be signed in to change notification settings - Fork 3
/
seeds2.h
146 lines (111 loc) · 4.64 KB
/
seeds2.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// ******************************************************************************
// SEEDS Superpixels
// ******************************************************************************
// Author: Beat Kueng based on Michael Van den Bergh's code
// Contact: [email protected]
//
// This code implements the superpixel method described in:
// M. Van den Bergh, X. Boix, G. Roig, B. de Capitani and L. Van Gool,
// "SEEDS: Superpixels Extracted via Energy-Driven Sampling",
// ECCV 2012
//
// Copyright (c) 2012 Michael Van den Bergh (ETH Zurich). All rights reserved.
// ******************************************************************************
#if !defined(_SEEDS_H_INCLUDED_)
#define _SEEDS_H_INCLUDED_
#include <string>
using namespace std;
typedef unsigned int UINT;
class SEEDS
{
public:
SEEDS(int width, int height, int nr_channels, int nr_bins);
~SEEDS();
// initialize. this needs to be called only once
//the number of superpixels is:
// (image_width/seeds_w/(2^(nr_levels-1))) * (image_height/seeds_h/(2^(nr_levels-1)))
void initialize(int seeds_w, int seeds_h, int nr_levels);
//set a new image in YCbCr format
//image must have the same size as in the constructor was given
void update_image_ycbcr(UINT* image);
// go through iterations
void iterate();
UINT* get_labels() { return labels[seeds_top_level]; }
// output labels
UINT** labels; //[level][y * width + x]
// evaluation
int count_superpixels();
void SaveLabels_Text(string filename);
// mean colors
void compute_mean_map();
UINT* means;
private:
void deinitialize();
bool initialized;
// seeds
int seeds_w;
int seeds_h;
int seeds_nr_levels;
int seeds_top_level; // == seeds_nr_levels-1 (const)
int seeds_current_level; //start with level seeds_top_level-1, then go down
// image processing
float* image_l; //input image
float* image_a;
float* image_b;
UINT* image_bins; //bin index (histogram) of each image pixel [y*width + x]
float* bin_cutoff1; //for each bin: define upper limit of L value used to calc bin index from color value
float* bin_cutoff2; //for each bin: define upper limit of a value
float* bin_cutoff3; //for each bin: define upper limit of b value
// keep one labeling for each level
UINT* nr_labels; //[level]
UINT** parent; //[level][label] = corresponding label of block with level+1
UINT** nr_partitions; //[level][label] how many partitions label has on level-1
int** T; //[level][label] how many pixels with this label
int go_down_one_level();
// initialization
void assign_labels();
void compute_histograms(int until_level = -1);
void compute_means();
//void lab_get_histogram_cutoff_values(const Image& image);
// color conversion and histograms
int RGB2HSV(const int& r, const int& g, const int& b, float* hval, float* sval, float* vval);
int RGB2LAB(const int& r, const int& g, const int& b, float* lval, float* aval, float* bval);
int LAB2bin(float l, float a, float b);
int RGB2LAB_special(int r, int g, int b, float* lval, float* aval, float* bval);
int RGB2LAB_special(int r, int g, int b, int* bin_l, int* bin_a, int* bin_b);
void LAB2RGB(float L, float a, float b, int* R, int* G, int* B);
int histogram_size; //= nr_bins ^ 3 (3 channels)
int*** histogram; //[level][label][j < histogram_size]
void update(int level, int label_new, int x, int y);
void add_pixel(int level, int label, int x, int y);
void add_pixel_m(int level, int label, int x, int y);
void delete_pixel(int level, int label, int x, int y);
void delete_pixel_m(int level, int label, int x, int y);
void add_block(int level, int label, int sublevel, int sublabel);
void delete_block(int level, int label, int sublevel, int sublabel);
void update_labels(int level);
// probability computation
bool probability(int color, int label1, int label2, int prior1, int prior2);
bool probability_means(float L, float a, float b, int label1, int label2, int prior1, int prior2);
int threebythree(int x, int y, UINT label);
int threebyfour(int x, int y, UINT label);
int fourbythree(int x, int y, UINT label);
// block updating
void update_blocks(int level, float req_confidence = 0.0);
float intersection(int level1, int label1, int level2, int label2);
// border updating
void update_pixels();
void update_pixels_means();
bool forwardbackward;
int threebythree_upperbound;
int threebythree_lowerbound;
inline bool check_split(int a11, int a12, int a13, int a21, int a22,
int a23, int a31, int a32, int a33, bool horizontal, bool forward);
int* nr_w; //[level] number of seeds in x-direction
int* nr_h;
float* L_channel;
float* A_channel;
float* B_channel;
int width, height, nr_channels, nr_bins;
};
#endif // !defined(_SEEDS_H_INCLUDED_)