-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfilter_1.cpp
More file actions
46 lines (32 loc) · 1.2 KB
/
Copy pathfilter_1.cpp
File metadata and controls
46 lines (32 loc) · 1.2 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
#include <iostream>
#include "Image_Class.h"
using namespace std;
int main() {
string filename;
cout << "Please enter colored image name to turn to gray scale: ";
cin >> filename;
Image image(filename);
// Loop through each pixel in the image
for (int i = 0; i < image.width; ++i) {
for (int j = 0; j < image.height; ++j) {
unsigned int avg = 0; // Initialize an integer variable to store the average value
// Calculate the average value of RGB channels for each pixel
for (int k = 0; k < 3; ++k) {
avg += image(i, j, k);
}
avg /= 3; // Calculate the final average value
// Set the RGB values of the pixel to the calculated average
for (int k = 0; k < 3; ++k) {
image(i, j, k) = avg;
}
}
}
cout << "Please enter image name to save the new image\n";
cout << "and specify extension .jpg .bmp .png .tga: ";
cin >> filename;
// Save the modified image with the provided filename
image.saveImage(filename);
// Open the saved image using the default system viewer
system(filename.c_str());
return 0;
}