Question: I need to create a new image that is the mirror-image of the image from the previous step. (The left side and the right side

I need to create a new image that is the mirror-image of the image from the previous step. (The left side and the right side are reversed). But the line of code that is bold, is throwing an out of bounds exception, can someone please help me fix that?

#include #include #include "ImageLib.h" #include

using namespace std; // Type Definitions void PC(pixel& p, int row, int col); void originalimage(image in); void newImage(image inp); int compareImg(image p1, image p2);

int main() { image input = ReadGIF("test1.gif"); if (input.rows == 0 && input.cols == 0) { cout << "Unable to open file: test1.gif" << endl; return -1; }

newImage(input);

// output results WriteGIF("output.gif", input); image input1 = ReadGIF("test1.gif");//read in original again int count = compareImg(input1, input); cout << "The difference in pixels is : " << count << endl; system("PAUSE"); DeallocateImage(input); return 0; }

void originalimage(image in) { for (int row = 0; row < in.rows; row++) { for (int col = 0; col < in.cols; col++) { PC(in.pixels[row][col], row, col); } } }

void PC(pixel& p, int row, int col) { p.blue = p.blue - (row % 7); p.red = p.red + (col % 9);

if (p.blue < 0) {//This is for underflow

p.blue = 0;//if blue is less than zero, then set it back to 0. } else if (p.blue > 255) {//This is for overflow p.blue = 255;//if blue overflows, then set it back to 255. } if (p.red < 0) {//This is for underflow p.red = 0;//if red is less than zero, then set it back to 0 } else if (p.red > 255) {//This is for overflow p.red = 255;//If red is more than 255, then set it back to 255. }

}

void newImage(image input) {

int temp = 0; for (int row = 0; row < input.rows; row++) for (int col = 0; col < input.cols / 2; col++) {

input.pixels[row][col].blue = input.pixels[row][col].blue - (row % 7); if (input.pixels[row][col].blue > 255) input.pixels[row][col].blue = 255; if (input.pixels[row][col].blue < 0) input.pixels[row][col].blue = 0; input.pixels[row][col].red = input.pixels[row][col].red + (row % 9); if (input.pixels[row][col].red > 255) input.pixels[row][col].red = 255; if (input.pixels[row][col].red < 0) input.pixels[row][col].red = 0; }

for (int row = 0; row < input.rows; row++) for (int col = 0; col < input.cols / 2; col++) //this will scan over our pixels input.pixels[row][col] = input.pixels[input.cols - row][col]; }

int compareImg(image a1, image a2) { int count = 0; for (int row = 0; row < a1.rows; row++) for (int col = 0; col < a1.cols / 2; col++) { if (a1.pixels[row][col].blue != a2.pixels[row][col].blue) { count++; } else if (a1.pixels[row][col].green != a2.pixels[row][col].green) { count++; } else if (a1.pixels[row][col].red != a2.pixels[row][col].red) { count++; }

}

return count; }

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!