-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistogram.cpp
More file actions
137 lines (104 loc) · 2.44 KB
/
histogram.cpp
File metadata and controls
137 lines (104 loc) · 2.44 KB
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
#include<iostream>
#include<string>
#include<fstream>
#include<sstream>
#include<cmath>
using namespace std;
#define DEBUG
#ifdef DEBUG
ostream& debug = cout;
#else
ostringstream nullStream;
ostream& debug = nullStream;
#endif
int main(int argc,char*argv[])
{
string inputPath = argv[1];
string outputPath = argv[2];
fstream file1;
file1.open(inputPath, fstream::in | fstream::binary);
if (!file1.good()) return 0;
string format = "";
int width = 0;
int height = 0;
int maxValue = 0;
file1 >> format >> width >> height >> maxValue;
file1.ignore();
debug << format << " " << width << " " << height << " " << maxValue;
int* wystapienia = new int[maxValue];
int* dystrybuanty = new int[maxValue];
for (int i = 0; i < maxValue; i++)
{
*(wystapienia + i) = 0;
*(dystrybuanty + i) = 0;
}
int** tab = new int* [height];
debug << '\n' << "STARE WARTOSCI" << '\n';
for (int i = 0; i < height; i++)
{
*(tab + i) = new int[width];
for (int j = 0; j < width; j++)
{
int wartosc = (file1.get());
debug << wartosc << " ";
*(*(tab + i) + j) = wartosc;
wystapienia[wartosc]++;
}
debug << '\n';
}
debug << "---------------------------------------" << '\n';
file1.close();
int suma = 0;
debug << "DYSTRYBUANTY" << '\n';
for (int i = 0; i < maxValue; i++)
{
suma += wystapienia[i];
dystrybuanty[i] = suma;
debug << dystrybuanty[i] << " ";
}
debug << "------------------------------" << '\n';
int min_dystrybuanta = 0;
for (int i=0; i < maxValue; i++)
{
if (dystrybuanty[i] > 0)
{
min_dystrybuanta = dystrybuanty[i];
break;
}
}
debug << "MIN DYST: " << min_dystrybuanta << '\n';
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
int nowaWartosc = (round(((dystrybuanty[tab[i][j]] - min_dystrybuanta) / ((width * height) - min_dystrybuanta)) * (maxValue - 1)));
debug << nowaWartosc << " ";
tab[i][j] = nowaWartosc;
}
}
debug << "-------------------------------";
fstream file2;
file2.open(outputPath, fstream::out | fstream::binary);
if (!file2.good()) return 0;
file2 << format << '\n';
file2 << width << " " << height << '\n';
file2 << maxValue << '\n';
debug << '\n';
debug << "NOWE WARTOSCI" << '\n';
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
file2.put(tab[i][j]);
debug << tab[i][j] << " ";
}
debug << '\n';
}
file2.close();
for (int i = 0; i < height; i++)
{
delete[] tab[i];
}
delete[] tab;
return 0;
}