Question
C++ ppm Hi, I am trying to create a program that will run like this. with output file showing #include #include #include #include using namespace
C++ ppm
Hi, I am trying to create a program that will run like this.
with output file showing
#include
#include
#include
#include
using namespace std;
typedef struct ppm {
string type;
int width;
int height;
int max;
int im[100][100][3];
}PPM;
void readImage(PPM &image, ifstream &ifs) {
ifs >> image.type;
if (image.type == "P1" || image.type == "P2" || image.type == "P3") {
ifs >> image.width >> image.height;
if (image.width > 1000 || image.height > 1000) {
cout
exit(-1);
}
ifs >> image.max;
for (int i = 0; i
for (int j = 0; j
ifs >> image.im[i][j][0] >> image.im[i][j][1] >> image.im[i][j][2];
}
}
}
else {
cout
exit(-1);
}
}
void convertGrayScale(PPM &image) {
if (image.type == "P2") {
return;
}
image.type = "P2";
int tot = 0;
for (int i = 0; i
for (int j = 0; j
tot = image.im[i][j][0] + image.im[i][j][1] + image.im[i][j][2];
image.im[i][j][0] = tot / 3;
image.im[i][j][1] = tot / 3;
image.im[i][j][2] = tot / 3;
}
}
}
void invertRed(PPM &image) {
for (int i = 0; i
for (int j = 0; j
image.im[i][j][0] = image.max - image.im[i][j][0];
}
}
}
void invertBlue(PPM &image) {
for (int i = 0; i
for (int j = 0; j
image.im[i][j][1] = image.max - image.im[i][j][1];
}
}
}
void invertGreen(PPM &image) {
for (int i = 0; i
for (int j = 0; j
image.im[i][j][2] = image.max - image.im[i][j][2];
}
}
}
void invertAll(PPM &image) {
for (int i = 0; i
for (int j = 0; j
image.im[i][j][0] = image.max - image.im[i][j][0];
image.im[i][j][1] = image.max - image.im[i][j][1];
image.im[i][j][2] = image.max - image.im[i][j][2];
}
}
}
void writeImage(PPM &image, ofstream &ofs) {
ofs
ofs
ofs
for (int i = 0; i
for (int j = 0; j
ofs
}
ofs
}
}
void menu() {
cout
cout
cout
cout
cout
}
int main() {
PPM image;
string ofile;
string ifile;
ifstream ifs;
ofstream ofs;
cout
cin >> ifile;
ifs.open(ifile.c_str());
if (!ifs.is_open()) {
cout
return -1;
}
cout
cin >> ofile;
ofs.open(ofile.c_str());
if (!ofs.is_open()) {
cout
return -1;
}
readImage(image, ifs);
ifs.close();
int choice;
menu();
cin >> choice;
switch (choice) {
case 1:convertGrayScale(image); break;
case 2:invertRed(image); break;
case 3:invertBlue(image); break;
case 4:invertGreen(image); break;
case 5:invertAll(image); break;
}
writeImage(image, ofs);
ofs.close();
}
Please help me add these new functions in.
Adding noise:
Remove a color
Scaling the image
Changing contrast
.7 Select C:\UsersiChadDesktop\C++ progNew folderNmageModder-SampleProgram.exe Portable Pixmap (PPM) Image Modder Enter image file name (ppm):cake.ppm Enter output file name(ppm):cake Magic: P3 Width, Height: 720, 540 Number of Pixels: 388800 Max Color: 255 Image Processing Choices 1. Convert to grayscale 2. Invert Red 3. Invert Green 4. Invert Blue 5. Invert All Enter Choice: 1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started