Question: Under is the code for this project. I know I need to if statements I could get one done, I just can`t figure out how

 Under is the code for this project. I know I need

Under is the code for this project. I know I need to if statements I could get one done, I just can`t figure out how to do the next if so the picture will only have the white line around it. It is only the if statement in the main function in the bottom.

thanks.

#include

#include

#include

#include

using namespace std;

const int MAX_H = 512;

const int MAX_W = 512;

// Reads a PGM file.

// Notice that: height and width are passed by reference!

void readImage(int image[MAX_H][MAX_W], int &height, int &width) {

char c;

int x;

ifstream instr;

instr.open("inImage.pgm");

// read the header P2

instr >> c;

assert(c == 'P');

instr >> c;

assert(c == '2');

// skip the comments (if any)

while ((instr>>ws).peek() == '#') {

instr.ignore(4096, ' ');

}

instr >> width;

instr >> height;

assert(width

assert(height

int max;

instr >> max;

assert(max == 255);

for (int row = 0; row

for (int col = 0; col

instr >> image[row][col];

instr.close();

return;

}

// Writes a PGM file

// Need to provide the array data and the image dimensions

void writeImage(int image[MAX_H][MAX_W], int height, int width) {

ofstream ostr;

ostr.open("outImage.pgm");

if (ostr.fail()) {

cout

exit(1);

};

// print the header

ostr

// width, height

ostr

ostr

ostr

for (int row = 0; row

for (int col = 0; col

assert(image[row][col]

assert(image[row][col] >= 0);

ostr

ostr

}

}

ostr.close();

return;

}

int main() {

int img[MAX_H][MAX_W];

int h, w;

readImage(img, h, w); // read it from the file "inImage.pgm"

// h and w were passed by reference and

// now contain the dimensions of the picture

// and the 2-dimesional array img contains the image data

// Now we can manipulate the image the way we like

// for example we copy its contents into a new array

int out[MAX_H][MAX_W];

int cr = h/2;

int cc = w/2;

int ar = cr - h;

int ac = cc - w/4;

int dr = cr + h/4;

int dc = cc + w/4;

for(int row = 0; row

for(int col = 0; col

if((row > h/4 && row w/4 && col

//if (row == && col == w) //&& (col == w or col

//out[row][col] = 255;

//if ((row >= ar && col >= ac) && (row

if((row == ar || col == dr) && (col >= ac || col = ac || row

out[row][col] = 255;

}

}

// and save this new image to file "outImage.pgm"

writeImage(out, h, w);

}

Task D. One-pixethick frame Program frame.cpp .Same as the previous task, but it should be a frame exactly one pixel thick. Example: Task D. One-pixethick frame Program frame.cpp .Same as the previous task, but it should be a frame exactly one pixel thick. Example

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!