-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblockImage.h
executable file
·123 lines (86 loc) · 3.24 KB
/
blockImage.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
#ifndef MATRIX_H
#define MATRIX_H
#include <ostream>
#include <istream>
#include <string>
#include "compareImages.h"
/*
Class for storing and processing an pnm image
*/
class blockImage{
/*
stores image as a blockRowCount by blockColCount
of blocks where each block is blockDimension by blockDimension pixels
*/
int blockDimension;
int blockColCount;
int blockRowCount;
int blockCount;//blockRowCount * blockColCount
std::string type;//PNM reading input/output data
/*
Method responsible for turning a blockDimension by blockDimension matrix stored as array
into a blockDimension/2 by blockDimension/2 matrix stored as an array. Method does this
by approximating each 2 by 2 block of elements in matrix down to one by one block by taking average value
of the four pixels.
array input and output storage is equivalent to reading matrix row by row, left to right.
*/
double * blurMatrix(double * matrix, int blockDimension);
double * expandMatrix(double * matrix, int blockDimension);
//stores the image in the specified block fashion
double **blockStore;
//rounding of pixels in blockImage to match the integer 0-255 range is ON for default
bool round = true;
friend class compareImages;
public:
//defines an array for matrix
blockImage(int blockDimension);
//reads in the input to fill the blockStore structure
//same as the method before, but for double
void readMatrixPNM(std::istream &infile);
/*
Method for reading a matrix in from specified inputstream infile.
The data read in, number by number is equivalent to reading matrix row by row
from left to right. However, the data is read in and stored in such a way that
it represents a set of blockDimensionxblockDimension blocks that when put in the original
matrix form blockRowCountxblockColCount blocks.
For example:
xybb
azbb
ccdd
ccdd
would be read in and stored as
store = [A,B,C,D]
where
A = [x,y,a,z]
likewise for B,C,D
Requirements:
store: has to be defined ahead of time with appropriate dimensions
infile usually points to some PNM type file input.
*/
void writeMatrixPNM(std::ostream &ofile);
//reduces all of the blockDimension by blockDimension blocks to
//blockDimension/2 by blockDimension/2
void blur();
//this method allows a user to define to empty blockStore of specified blockCount given that constructor
//with dimension size has already been called (blockCount = blockRowCount * blockColCount)
//should only ever be used when readMatrixPNM has not been yet called to avoid memeory leaks
void makeEmpty(int blockRowCount, int blockColCount, std::string t);
//destructor
~blockImage();
//getter methods
int getBlockDimension();
int getBlockColCount();
int getBlockRowCount();
int getBlockCount();
std::string getType();
//updates the blockStore to correct Dimension, but keeps same block Dimensions
void updateMap(int blockDimension);
//return the norm between two matrices
//both need same blockDimension and blockCount
double differenceNormalized(blockImage * bi);
//rounding ON or OFF for writeMatrixPNM
void writeRoundOFF(bool isItOFF);
//expand a matrix --> the opposite of blur
void expand();//doubles the blockDimension
};
#endif