| Bsoft 2.0.5 Bernard's software package

Bsuperpixel.h
Go to the documentation of this file.
1
9 #include "utilities.h"
10
11 #ifndef _Bsuperpixel_
12
13 #define NNEIGHBOR 64
14
15 class Bsuperpixel {
16 private:
17 long idx; // index
18 long cnt; // pixel count
19 vector<double> coor; // coordinate average
20 vector<double> chan; // channels
21 double wt; // weight
22 vector<long> nb; // neigbor list
23 public:
24 Bsuperpixel() : idx(0), cnt(0), wt(0) {
25 nb.resize(NNEIGHBOR, -1);
26 for ( long i=0; i<3; ++i ) coor.push_back(0);
27 }
28 void index(long i) { idx = i; }
29 long index() { return idx; }
30 void count(long i) { cnt = i; }
31 long count() { return cnt; }
32 void coordinates(vector<double>& c) { coor = c; }
33 vector<double>& coordinates() { return coor; }
34 void channels(long nc) { chan.resize(nc, 0); }
35 void channels(vector<double>& v) {
36 chan.resize(v.size(), 0);
37 for ( size_t i=0; i<v.size(); ++i ) chan[i] = v[i];
38 }
39 vector<double>& channels() { return chan; }
40 double channel(long i) { return chan[i]; }
41 void weight(double w) { wt = w; }
42 double weight() { return wt; }
43 void neighbor(long i, long j) { nb[i] = j; }
44 long neighbor(long i) { return nb[i]; }
45 void neighbors(vector<long>& v) {
46 for ( size_t i=0; i<NNEIGHBOR && i<v.size(); ++i ) nb[i] = v[i];
47 }
48 void add_neighbor(long i) {
49 long j;
50 for ( j=0; j<NNEIGHBOR && nb[j] >= 0; ++j ) ;
51 if ( j < NNEIGHBOR ) nb[j] = i;
52 else {
53 cerr << "Too many neighbors for segment " << idx << endl;
54 exit(-1);
55 }
56 }
57 void clear_neighbors() {
58 for ( long i=0; i<NNEIGHBOR; i++ ) nb[i] = -1;
59 }
60 void clear() {
61 cnt = 0;
62 for ( auto i = coor.begin(); i != coor.end(); ++i ) *i = 0;
63 for ( auto i = chan.begin(); i != chan.end(); ++i ) *i = 0;
64 wt = 0;
65 }
66 void add(long cx, long cy, long cz, vector<double> v) {
67 cnt++;
68 coor[0] += cx;
69 coor[1] += cy;
70 coor[2] += cz;
71 for ( size_t i=0; i<chan.size() && i<v.size(); ++i ) chan[i] += v[i];
72 }
73 void add(vector<long> c, vector<double>& v) {
74 add(c[0], c[1], c[2], v);
75 }
76 void average() {
77 if ( cnt ) {
78 coor /= cnt;
79 for ( auto i = chan.begin(); i != chan.end(); ++i )
80 *i /= cnt;
81 }
82 }
83 double difference2(vector<double> v) {
84 double d(0);
85 for ( size_t i=0; i<chan.size() && i<v.size(); ++i )
86 d += (chan[i] - v[i])*(chan[i] - v[i]);
87 return d;
88 }
89 };
90
91 #define _Bsuperpixel_
92 #endif
Bsuperpixel::coordinates
void coordinates(vector< double > &c)
Definition: Bsuperpixel.h:32
Bsuperpixel::Bsuperpixel
Bsuperpixel()
Definition: Bsuperpixel.h:24
Bsuperpixel::clear
void clear()
Definition: Bsuperpixel.h:60
Bsuperpixel::add
void add(long cx, long cy, long cz, vector< double > v)
Definition: Bsuperpixel.h:66
utilities.h
Header file for general utilities.
Bsuperpixel::count
void count(long i)
Definition: Bsuperpixel.h:30
Bsuperpixel::channels
void channels(long nc)
Definition: Bsuperpixel.h:34
Bsuperpixel::weight
double weight()
Definition: Bsuperpixel.h:42
Bsuperpixel::count
long count()
Definition: Bsuperpixel.h:31
Bsuperpixel
Definition: Bsuperpixel.h:15
Bsuperpixel::difference2
double difference2(vector< double > v)
Definition: Bsuperpixel.h:83
Bsuperpixel::coordinates
vector< double > & coordinates()
Definition: Bsuperpixel.h:33
Bsuperpixel::neighbor
void neighbor(long i, long j)
Definition: Bsuperpixel.h:43
Bsuperpixel::index
long index()
Definition: Bsuperpixel.h:29
Bsuperpixel::neighbors
void neighbors(vector< long > &v)
Definition: Bsuperpixel.h:45
Bsuperpixel::channels
vector< double > & channels()
Definition: Bsuperpixel.h:39
Bsuperpixel::index
void index(long i)
Definition: Bsuperpixel.h:28
Bsuperpixel::clear_neighbors
void clear_neighbors()
Definition: Bsuperpixel.h:57
Bsuperpixel::channel
double channel(long i)
Definition: Bsuperpixel.h:40
Bsuperpixel::neighbor
long neighbor(long i)
Definition: Bsuperpixel.h:44
Bsuperpixel::add
void add(vector< long > c, vector< double > &v)
Definition: Bsuperpixel.h:73
NNEIGHBOR
#define NNEIGHBOR
Definition: Bsuperpixel.h:13
Bsuperpixel::average
void average()
Definition: Bsuperpixel.h:76
Bsuperpixel::add_neighbor
void add_neighbor(long i)
Definition: Bsuperpixel.h:48
Bsuperpixel::weight
void weight(double w)
Definition: Bsuperpixel.h:41
Bsuperpixel::channels
void channels(vector< double > &v)
Definition: Bsuperpixel.h:35