forked from aclapes/segmenthreetion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GridMat.h
executable file
·204 lines (163 loc) · 6.66 KB
/
GridMat.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//
// GridMat.h
// Segmenthreetion
//
// Created by Albert Clapés on 21/04/13.
// Copyright (c) 2013 Albert Clapés. All rights reserved.
//
#ifndef __Segmenthreetion__GridMat__
#define __Segmenthreetion__GridMat__
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace std;
class GridMat
{
friend ostream& operator<<( ostream&, const GridMat& );
public:
/*
* Constructors
*/
GridMat(unsigned int hp = 2, unsigned int wp = 2);
GridMat(unsigned int hp, unsigned int wp, unsigned int helems, unsigned int welems, cv::Scalar s = cv::Scalar(0), int type = CV_32FC1);
GridMat(cv::Mat mat, unsigned int hp = 2, unsigned int wp = 2);
GridMat(const GridMat& other);
GridMat(GridMat& other, GridMat indices, int k, bool inverse = false);
GridMat(GridMat& other, GridMat indices, bool logical = true);
void create(unsigned int hp = 2, unsigned int wp = 2);
GridMat& operator=(const GridMat& other);
template<typename T>
void create(unsigned int hp, unsigned int wp, unsigned int helems = 1, unsigned int welems = 1);
GridMat clone();
void copyTo(cv::Mat mat, unsigned int i, unsigned int j);
bool isEmpty();
// Get the grid cell matrix at (i,j)
cv::Mat& at(unsigned int i, unsigned int j);
template<typename T>
T& at(unsigned int i, unsigned int j, unsigned int row, unsigned int col);
cv::Mat get(unsigned int i, unsigned int j) const;
cv::Rect getCellCoordinates(unsigned int i, unsigned int j);
void assign(cv::Mat cell, unsigned int i, unsigned int j);
void set(GridMat& other);
template<typename T>
void setTo(T value);
template<typename T>
void setTo(T value, unsigned int i, unsigned int j);
template<typename T>
void setTo(T value, unsigned int i, unsigned int j, cv::Mat mask);
// template<>
// void setTo(cv::Mat m);
// template<>
// void setTo(GridMat m);
template<typename T>
void convertToMat(cv::Mat& mat, bool imshow = false);
template<typename T>
cv::Mat convertToMat(bool imshow = false);
GridMat convertToSparse(GridMat indices);
void convertToSparse(GridMat indices, GridMat& sparseGridMat);
GridMat convertToDense(GridMat indices);
void convertToDense(GridMat indices, GridMat& denseGridMat);
void normalize(GridMat& g); // at cell level
GridMat normalize(); // at cell level
void standardize(GridMat& g);
GridMat standardize();
void set(GridMat src, GridMat indices); // size(src) < size(dst)
void set(GridMat src, GridMat indices, int k); // size(src) < size(dst)
void index(GridMat& dst, GridMat indices, int k); // size(src) > size(dst)
void copyTo(GridMat& dst);
void copyTo(GridMat& dst, GridMat indices); // size(src) == src(dst)
void copyTo(GridMat& dst, GridMat indices, int k); // size(src) == size(dst)
// GridMat operator<(GridMat& other);
// GridMat operator<=(GridMat& other);
// GridMat operator>(GridMat& other);
// GridMat operator>=(GridMat& other);
// GridMat operator==(GridMat& other);
// GridMat operator!=(GridMat& other);
// GridMat operator+(GridMat& other);
// GridMat operator-(GridMat& other);
// GridMat operator*(GridMat& other);
// GridMat operator/(GridMat& other);
template<typename T>
GridMat operator<(T value);
template<typename T>
GridMat operator<=(T value);
template<typename T>
GridMat operator>(T value);
template<typename T>
GridMat operator>=(T value);
template<typename T>
GridMat operator==(T value);
template<typename T>
GridMat operator!=(T value);
template<typename T>
GridMat operator+(T value);
template<typename T>
GridMat operator-(T value);
template<typename T>
GridMat operator*(T value);
template<typename T>
GridMat operator/(T value);
GridMat operator!();
GridMat operator&(GridMat g);
GridMat operator|(GridMat g);
// GridMat vget(cv::Mat indices, bool logical = true);
// GridMat hget(cv::Mat indices, bool logical = true);
//
// void vset(GridMat grid, cv::Mat indices, bool logical = true);
// void hset(GridMat grid, cv::Mat indices, bool logical = true);
unsigned int ccols() const;
unsigned int crows() const;
unsigned int cols(unsigned int i, unsigned int j);
unsigned int rows(unsigned int i, unsigned int j);
GridMat row(unsigned int i);
GridMat col(unsigned int i);
void hconcat(GridMat& other);
void vconcat(GridMat& other);
void hconcat(cv::Mat& mat, unsigned int i, unsigned int j);
void vconcat(cv::Mat& mat, unsigned int i, unsigned int j);
void hserial(cv::Mat& serial);
void vserial(cv::Mat& serial);
GridMat flip(int flipCode);
// Cells' collapse functions. Each cell into a row or a column.
void mean(GridMat& gmean, int dim = 0);
void max(GridMat& gmax, int dim = 0);
void min(GridMat& gmin, int dim = 0);
void sum(GridMat& gsum, int dim = 0);
GridMat abs();
// Grid's collapse functions. The grid is turnet into a single-grid (Mat)
cv::Mat accumulate();
void accumulate(cv::Mat& accumulation);
cv::Mat average();
void average(cv::Mat& average);
void biaccumulate(GridMat g, int threshold, cv::Mat& acc1, cv::Mat& acc2);
void biaverage(GridMat g, int threshold, cv::Mat& acc1, cv::Mat& acc2);
template<typename T> cv::Mat findNonZero();
void argmax(GridMat& gargmax);
void argmin(GridMat& gargmax);
GridMat historize (int nbins, double min, double max);
void save(const string & filename);
void load(const string & filename);
void show(const char* namedWindow);
void release();
private:
/*
* Class attributes
*/
vector<cv::Mat> m_grid;
unsigned int m_crows; // Num of cell rows
unsigned int m_ccols; // Num of cell cols
unsigned int m_rows;
unsigned int m_cols;
void init(GridMat& other);
bool accessible(unsigned int i, unsigned int j) const;
// GridMat getIndexedCellElements(cv::Mat indices, int dim = 0, bool logical = true);
// void setIndexedCellElements(GridMat& grid, cv::Mat indices, int dim = 0, bool logical = true);
//
// GridMat getIndexedCellElementsLogically(cv::Mat logicals, int dim = 0);
// void setIndexedCellElementsLogically(GridMat& grid, cv::Mat logicals, int dim = 0);
//
// GridMat getIndexedCellElementsPositionally(cv::Mat indices, int dim = 0);
// void setIndexedCellElementsPositionally(GridMat& grid, cv::Mat indices, int dim = 0);
};
#endif /* defined(__Segmenthreetion__GridMat__) */