-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathImageProcessingDemo.cpp
More file actions
38 lines (28 loc) · 950 Bytes
/
Copy pathImageProcessingDemo.cpp
File metadata and controls
38 lines (28 loc) · 950 Bytes
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
// A demo for converting image to gray scale
#include <iostream>
using namespace std;
#include "Image_Class.h"
int main() {
string filename;
cout << "Pls enter colored image name to turn to gray scale: ";
cin >> filename;
Image image(filename);
for (int i = 0; i < image.width; ++i) {
for (int j = 0; j < image.height; ++j) {
unsigned int avg = 0; // Initialize average value
for (int k = 0; k < 3; ++k) {
avg += image(i, j, k); // Accumulate pixel values
}
avg /= 3; // Calculate average
// Set all channels to the average value
image(i, j, 0) = avg;
image(i, j, 1) = avg;
image(i, j, 2) = avg;
}
}
cout << "Pls enter image name to store new image\n";
cout << "and specify extension .jpg, .bmp, .png, .tga: ";
cin >> filename;
image.saveImage(filename);
return 0;
}