-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBONUS 1.cpp
More file actions
61 lines (50 loc) · 1.88 KB
/
Copy pathBONUS 1.cpp
File metadata and controls
61 lines (50 loc) · 1.88 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
#include <iostream>
#include "Image_Class.h"
#include <cmath>
using namespace std;
// Function to apply Sepia Tone filter to the image
void SepiaTone(int width, int height, Image& image) {
int newR, newG, newB;
// Iterate over each pixel in the image
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
// For each pixel, calculate new RGB values based on the sepia tone effect
for (int k = 0; k < 3; k++) {
int PixelValue = image(i, j, k);
if (k == 0) {
// Calculate new Red value
newR = min(255, (int)(0.393 * PixelValue + 0.769 * image(i, j, 1) + 0.189 * image(i, j, 2)));
}
else if (k == 1) {
// Calculate new Green value
newG = min(255, (int)(0.349 * image(i, j, 0) + 0.686 * PixelValue + 0.168 * image(i, j, 2)));
}
else {
// Calculate new Blue value
newB = min(255, (int)(0.272 * image(i, j, 0) + 0.534 * image(i, j, 1) + 0.131 * PixelValue));
}
}
// Update the pixel with the new RGB values
image(i, j, 0) = newR;
image(i, j, 1) = newG;
image(i, j, 2) = newB;
}
}
}
int main() {
string filename, new_filename;
cout << "Please enter the first image name: ";
cin >> filename;
// Load the original image
Image image(filename);
// Apply the sepia tone filter
SepiaTone(image.width, image.height, image);
// Get the filename for the filtered image
cout << endl << "Please enter image name to store new image\n";
cout << "and specify extension .jpg .bmp .png .tga: ";
cin >> new_filename;
// Save the filtered image
image.saveImage(new_filename);
system(new_filename.c_str());
return 0;
}