Menu

Need Create New Image Mirror Image Image Previous Step Left Side Right Side Reversed Line Q43874624

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

#include <stdio.h>
#include <string>
#include “ImageLib.h”
#include <iostream>

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 originalagain
   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 lessthan zero, then set it back to 0.
   }
   else if (p.blue > 255) {//This is foroverflow
       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 thanzero, then set it back to 0
   }
   else if (p.red > 255) {//This is for overflow
       p.red = 255;//If red is more than255, 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 ourpixels
          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;
}

Expert Answer


Answer to 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 …

OR