-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImagetree.h
180 lines (145 loc) · 4.4 KB
/
Imagetree.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
/****************************************************************
* This is a header file to create a quadtree out of an image
* Author: Pavani Majety (Can be used for academic purposes)
* **************************************************************/
#ifndef IMAGETREE_H
#define IMAGETREE_H
#include <cstdio>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
#include "opencv2/core/types.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace cv;
using namespace std;
#define NUMBER_OF_QUADRANTS 4
/**************************************************
* Abstract class for quadtrees
* can store pixels - pixel is a struct that stores the Red,
* Green and Blue channel values. The quadnode and quad leaf
* are derived from the abstract class for quadtrees.
**************************************************/
enum directions_t { NorthWest = 0, NorthEast, SouthEast, SouthWest };
class Point_xy {
public:
Point_xy(int x_, int y_) : x(x_), y(y_) {}
int x;
int y;
};
class Pixel {
public:
Pixel(int R_, int G_, int B_, int x_, int y_)
: R(R_), G(G_), B(B_), x(x_), y(y_) {}
Pixel(int R_, int G_, int B_) : R(R_), G(G_), B(B_), x(0), y(0) {}
Pixel() : R(0), G(0), B(0), x(0), y(0) {}
int x;
int y;
int R;
int G;
int B;
};
void operator<<(ostream &out, const Pixel &P);
struct PixelDepthQuad {
Pixel P;
int depth;
int quad;
bool isLeaf;
PixelDepthQuad* parentPixelDepth;
};
// typedef Pixel T;
struct Print_tree_parameters {
int depth;
int quad;
int x;
int y;
int rows_image;
int cols_image;
};
class Imagetree {
public:
~Imagetree() {}
Imagetree() {}
virtual bool isLeaf() = 0;
virtual bool isNode() { return !isLeaf(); }
virtual int numberOfLeaves() = 0;
virtual int numberOfNodes() = 0;
virtual int numberOfSubTrees() = 0;
virtual Pixel& value() = 0;
virtual Imagetree*& son(directions_t dir) = 0;
virtual void killAllSons() = 0;
virtual void print_tree(vector<PixelDepthQuad*>& pixVector,
PixelDepthQuad* parent,
Print_tree_parameters params) = 0;
void reconstructImageFromTree(vector<PixelDepthQuad*>& pixVector,
Mat* reconImage);
virtual int heightOfTree() = 0;
};
class QuadLeaf : public Imagetree {
Pixel pixel_val;
public:
// QuadLeaf specific functions
QuadLeaf();
QuadLeaf(Pixel pixel_in);
// QuadLeaf(const QuadLeaf & ql_in);
// overloaded functions
bool isLeaf();
int numberOfNodes();
int numberOfLeaves();
int numberOfSubTrees();
Pixel& value();
Imagetree* const& son(directions_t dir) const;
Imagetree*& son(directions_t dir);
void killAllSons();
void print_tree(vector<PixelDepthQuad*>& pixVector, PixelDepthQuad* parent,
Print_tree_parameters params);
void reconstructImageFromTree(vector<PixelDepthQuad*>& pixVector,
Mat* reconImage);
int heightOfTree() { return 1; };
};
/*********************************************
* A branching node of a quadtree, whose leaves contain
* a value of type T
* *********************************************/
class QuadNode : public Imagetree {
// A quadnode can have either a node or a leaf as its
// child nodes
private:
Imagetree* sons[NUMBER_OF_QUADRANTS];
Pixel average_pixel;
public:
// Constructors are defined below
QuadNode();
QuadNode(Imagetree* inputs[]);
QuadNode(Imagetree* in1, Imagetree* in2, Imagetree* in3, Imagetree* in4);
~QuadNode();
// Overloaded functions from Imagetree
bool isLeaf();
int numberOfLeaves();
int numberOfNodes();
int numberOfSubTrees();
Pixel& value();
Imagetree* const& son(directions_t dir) const;
Imagetree*& son(directions_t dir);
bool killSon(directions_t dir);
void killAllSons();
int heightOfTree();
void print_tree(vector<PixelDepthQuad*>& pixVector, PixelDepthQuad* parent,
Print_tree_parameters params);
void reconstructImageFromTree(vector<PixelDepthQuad*>& pixVector,
Mat* reconImage);
};
class ComparePixVector {
public:
bool operator()(const PixelDepthQuad PDQ1, const PixelDepthQuad PDQ2) {
// if(PDQ1.depth == PDQ2.depth){
// if((PDQ1.isLeaf) && (!PDQ2.isLeaf)) return true;
// else if((PDQ2.isLeaf) && (!PDQ1.isLeaf)) return false;
// else return false;
// }
// else
return PDQ1.depth < PDQ2.depth;
}
};
#endif