-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.h
81 lines (56 loc) · 2.41 KB
/
stats.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
#ifndef _STATS_H
#define _STATS_H
#include "cs221util/PNG.h"
#include "cs221util/RGBAPixel.h"
#include <utility>
#include <vector>
using namespace std;
using namespace cs221util;
class stats {
private:
vector< vector< long >> sumRed;
vector< vector< long >> sumGreen;
vector< vector< long >> sumBlue;
vector< vector< long >> sumsqRed;
vector< vector< long >> sumsqGreen;
vector< vector< long >> sumsqBlue;
long getSum(char channel, pair<int,int> ul, pair<int,int> lr);
/* returns the sums of all pixel values across the color channel.
* useful in computing the score of a rectangle
* PA3 function
* @param channel is one of r, g, or b
* @param ul is (x,y) of the upper left corner of the rectangle
* @param lr is (x,y) of the lower right corner of the rectangle */
long getSumSq(char channel, pair<int,int> ul, pair<int,int> lr);
/* returns the sums of squares of all pixel values across the color channel.
* useful in computing the score of a rectangle
* PA3 function
* @param channel is one of r, g, or b
* @param ul is (x,y) of the upper left corner of the rectangle
* @param lr is (x,y) of the lower right corner of the rectangle */
public:
void printValues();
// initialize the private vectors so that, for each color, entry
// (x,y) is the cumulative sum of the the color values from (0,0)
// to (x,y). Similarly, the sumSq vectors are the cumulative
// sum of squares from (0,0) to (x,y).
stats(PNG & im);
// given a rectangle, compute its sum of squared deviations from
// mean, over all color channels. Will be used to make split when
// building tree.
/* @param ul is (x,y) of the upper left corner of the rectangle
* @param lr is (x,y) of the lower right corner of the rectangle */
long getScore(pair<int,int> ul, pair<int,int> lr);
// given a rectangle, return the average color value over the
// rectangle as a pixel.
/* Each color component of the pixel is the average value of that
* component over the rectangle.
* @param ul is (x,y) of the upper left corner of the rectangle
* @param lr is (x,y) of the lower right corner of the rectangle */
RGBAPixel getAvg(pair<int,int> ul, pair<int,int> lr);
// given a rectangle, return the number of pixels in the rectangle
/* @param ul is (x,y) of the upper left corner of the rectangle
* @param lr is (x,y) of the lower right corner of the rectangle */
long rectArea(pair<int,int> ul, pair<int,int> lr);
};
#endif