Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task E. Scale 200% Program scale.cpp. Scale the original picture to 200% of its size. It can be done by increasing the size of the

Task E. Scale 200%

Program scale.cpp. Scale the original picture to 200% of its size. It can be done by increasing the size of the picture by the factor of 2, and copying each pixel of the input as a small 2x2 square in the output. (We dont do any interpolation of colors as more advanced scaling procedures would do.)

11 22 -> 11 11 22 22 33 44 11 11 22 22 33 33 44 44 33 33 44 44image text in transcribed

I`m adding the code and you just need to do something in the main function, I tried but looks like it`s not working...If you could comment what you did to make it work....

#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;

int avg = 0;

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];

for(int row = 0; row

for(int col = 0; col

avg = (out[row][col] + out[row][col + 1] + out[row + 1][col] + out[row + 1][col + 1])/4; // find ave

out[row][col] = out[row][col + 1] = out[row + 1][col] = out[row + 1][col + 1] = avg;

col += 2; // skip a col

row += 2; // skip a row

}

}

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

writeImage(out, h, w);

}

Example

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions

Question

Differentiate the function. r(z) = 2-8 - 21/2 r'(z) =

Answered: 1 week ago

Question

=+ What topics are contained in the contracts?

Answered: 1 week ago

Question

=+Are they specific or general in nature?

Answered: 1 week ago