-
Notifications
You must be signed in to change notification settings - Fork 0
/
edges.cpp
36 lines (30 loc) · 1011 Bytes
/
edges.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
#include "picture.h"
#include <iostream>
#include <cmath>
using namespace std;
int main(int argc, char* argv[]) {
if (argc < 2) {
cout << "Usage: edges infile.bmp [outfile.bmp]" << endl;
return 1;
}
// open the file and construct a Picture object
Picture pic(argv[1]);
// make a copy, initially black
Picture newpic(pic.height(), pic.width());
// edge-finding
for (int row=1; row<pic.height(); row++)
for (int col=1; col<pic.width(); col++) {
Color color1 = pic.get(row, col);
Color color2 = pic.get(row-1, col-1);
Color newcolor;
newcolor.red = (int) abs(color1.red - color2.red);
newcolor.blue = (int) abs(color1.blue - color2.blue);
newcolor.green = (int) abs(color1.green - color2.green);
newpic.set(row, col, newcolor);
}
// show the new picture
newpic.show();
// save it, if the optional command-line argument was provided
if (argc > 2)
newpic.save(argv[2]);
}