-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqtree.hpp
100 lines (66 loc) · 2.06 KB
/
qtree.hpp
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
//
// qtree.hpp
// QuadTree
//
// Created by Max Reynolds on 4/28/19.
// Copyright © 2019 Max Reynolds. All rights reserved.
//
#ifndef qtree_hpp
#define qtree_hpp
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <opencv2/opencv.hpp>
#endif /* qtree_hpp */
#ifndef MAX_DIM
#define MAX_DIM 8192 //from cs1300bmp.h
using namespace std;
struct qt_node{
bool is_leaf;
int pixel_value;
int* p;
//prows/pcols are constant in every node
int prows;
int pcols;
//what parts of the image this node represents
int r_min;
int r_max;
int c_min;
int c_max;
//pixel value deviation in the node
int deviation;
qt_node* NW;
qt_node* NE;
qt_node* SE;
qt_node* SW;
};
struct qt{
};
//creates a qt_node
qt_node* init_node();
//adds pixel values, r_min/max, c_min/max
void add_values(qt_node* q, int* p, int num_rows, int num_cols);
//splits a qt_node into 4 smaller nodes with corresponding pixel values
void split_qt_node(qt_node* q);
//calculates the deviation within the pixels of the node
int get_node_deviation(qt_node* q);
//calculates the average pixel value in the assigned range.
float get_avg_pxvalue(qt_node* q);
//gets the variance in the range of q
float get_pixel_variance(qt_node* q);
//builds the quad-tree based on the specified maximum pixel value variance
//splits starting node and successive nodes into child nodes
void build_tree(qt_node* start, int max_var);
//Unpacks the tree data into an array
//Not used in this implementation
void unpack_tree(qt_node*start, int* unpacked, int total_rows, int total_cols);
//Unpacks the tree data into an OpenCV Matrix structure
void unpack_tree(qt_node*start, cv::Mat& modified, int total_rows, int total_cols);
//counts leaf nodes of an already built tree
//can be a proxy for the number of pixel representations
int count_tree_nodes(qt_node* start);
//Counts the number of pixels used
//Just for checking, should be equal to the image's rows * cols
int check_num_pixels(qt_node* start);
#endif