-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReduceImageNoise.cpp
73 lines (65 loc) · 1.65 KB
/
ReduceImageNoise.cpp
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
// Luke Schlather
// Sunday, September 7 2008
// Licensed under the LGPL
#include<iostream>
#include<vector>
#include <fstream>
using namespace std;
string ppmtype;
int height;
int width;
int bitdepth;
vector<vector<vector <char> > > image;
void checkContinue(string message) {
string input;
cout << "Warning: " << message << endl;
cout << "Continue: (y/n)" << endl;
cin >> input;
if ((input!="y")&&(input!="Y")) {
exit(1);
}
}
int main(int argc,char** argv)
{
if(argc!=3) {
cout << "Usage: ReduceImageNoise <input image> <output image> " << endl;
}
cout << "Infile: " << argv[1] << endl;
ifstream infile(argv[1]);
ofstream outfile(argv[2]);
infile >> ppmtype;
cout << ppmtype << endl;
if(ppmtype!="P6") {
checkContinue("The input file is not a P6 PPM");
}
infile >> height;
infile >> width;
infile >> bitdepth;
if(bitdepth!=255) {
checkContinue("The input depth is not 255.");
}
cout << height << " x " << width << endl;
cout << "Bit Depth: " << bitdepth << endl;
infile.get(); //Discard the newline
image.resize(height);
for (int y=0;y<height;++y) {
image.at(y).resize(width);
for (int x=0;x<width;++x) {
image.at(y).at(x).resize(3);
infile.get(image.at(y).at(x).at(0));
infile.get(image.at(y).at(x).at(1));
infile.get(image.at(y).at(x).at(2));
}
}
outfile << ppmtype << endl;
outfile << height << " " << width << endl;
outfile << bitdepth << endl;;
for (int y=0;y<height;++y) {
for (int x=0;x<width;++x) {
outfile.put(image.at(y).at(x).at(0));
outfile.put(image.at(y).at(x).at(1));
outfile.put(image.at(y).at(x).at(2));
}
}
return 0;
}