Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program: Codeblocks C++ //Global variables const int BLACK = 0; const int WHITE = 255; class GrayImage { public: // Return the total number of

Program: Codeblocks C++

//Global variables

const int BLACK = 0;

const int WHITE = 255;

class GrayImage

{

public:

// Return the total number of white pixels in this image.

// Postcondition: this image has not been changed.

int countWhitePixels(); //To be completed

//Processes this image in row-major order and decreases the value of each

//pixel at position (row, col) by the value of the pixel at position

//(row + 2, col + 2) if it exists. Resulting values that would be less than

//BLACK are replaced by BLACK. Pixels for which there is no pixel at

//position (row + 2, col + 2) are unchanged.

void processImage(); //To be completed

//Return a pointer to a Pixel object at (row, col)

Pixel * getPixel(int row, int col);

int getRows(); // Return the total number of rows of this image

int getCols(); // Return the total number of columns of this image

private:

int rows; // Total number of rows in this image

int cols; // Total number of columns in this image

// The 2-dimensional representation of this image.

// That is a 2D array of pointers to Pixel objects

Pixel *** pixels;

};

class Pixel

{

public:

//To be completed

//Parameterized constructor

//Necessary getters and setters

private:

int value; // Pixel value

int row; // Row index of this pixel in an image

int col; // Column index of this pixel in an image

GrayImage * img; //The image to which this pixel belongs

}

A grayscale image is represented by a 2-dimensional rectangular array of pixels (picture elements). A pixel is represented by an integer value that represents a shade of gray. In this question, pixel values can be in the range from 0 through 255, inclusive. A black pixel is represented by 0, and a white pixel is represented by 255. The declaration of the GrayImage class is shown below. You will write two unrelated member functions of the GrayImage class.

image text in transcribed

After Call to process image

image text in transcribed

A program skeleton for reference

#include #include using namespace std; class GrayImage; //Pre-declaration //Classes class Pixel { public: Pixel(int v, int r, int c, GrayImage * m); int getValue(); void setValue(int); void print(); private: int value; int rol; int col; GrayImage * img; }; //v: pixel value; r: row; c: column; m is a pointer to the image to which this pixel belongs. Pixel::Pixel(int v, int r, int c, GrayImage * m) { //To be completed } void Pixel::print() { cout   255 184 178 84 | 129 84 255 255 13084 78 255 0 0 78 84 130 255 130 84 A call to count WhitePixels function would return 5 because there are 5 entries (shown in boldface) that have the value WHITE. (c) Write the function process Image that modifies the image by changing the pixel values of an image according to the following description. The pixels in the image are processed one at a time in row-major order. Row-major order processes the first row in the array from left to right and then processes the second row from left to right, continuing until all rows are processed from left to right. The first index of a pixel represents the row number, and the second index represents the column number. The pixel at position (row, col) is decreased by the value at position (row+2, col+2) if such a position exists. If the result of the subtraction is less than the value BLACK, the pixel is assigned the value of BLACK. The values of the pixels for which there is no pixel at position (row + 2, col + 2) remain unchanged. You may assume that all the original pixel values in the image are within the range of (0, 255) or (BLACK, WHITE), inclusive. The following shows the contents of the pixel values before and after a call to processImage. The values shown in boldface represent the pixels that could be modified in a grayscale image with 4 rows and 5 columns. Before Call to process Image 221 184 178 84 135 84 255 255 13084 78 255 0 0 78 84 130 255 130 84 | 221| 184| 100 | 84 |135 | | 0|125 | 171| 130] 84 78 | 255 | 0 10 178 | 84 | 130|25| 130] 84|  255 184 178 84 | 129 84 255 255 13084 78 255 0 0 78 84 130 255 130 84 A call to count WhitePixels function would return 5 because there are 5 entries (shown in boldface) that have the value WHITE. (c) Write the function process Image that modifies the image by changing the pixel values of an image according to the following description. The pixels in the image are processed one at a time in row-major order. Row-major order processes the first row in the array from left to right and then processes the second row from left to right, continuing until all rows are processed from left to right. The first index of a pixel represents the row number, and the second index represents the column number. The pixel at position (row, col) is decreased by the value at position (row+2, col+2) if such a position exists. If the result of the subtraction is less than the value BLACK, the pixel is assigned the value of BLACK. The values of the pixels for which there is no pixel at position (row + 2, col + 2) remain unchanged. You may assume that all the original pixel values in the image are within the range of (0, 255) or (BLACK, WHITE), inclusive. The following shows the contents of the pixel values before and after a call to processImage. The values shown in boldface represent the pixels that could be modified in a grayscale image with 4 rows and 5 columns. Before Call to process Image 221 184 178 84 135 84 255 255 13084 78 255 0 0 78 84 130 255 130 84 | 221| 184| 100 | 84 |135 | | 0|125 | 171| 130] 84 78 | 255 | 0 10 178 | 84 | 130|25| 130] 84|

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 Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions

Question

In your own words describe the purpose of the ACFE.

Answered: 1 week ago

Question

LO3 Describe the purpose of equity legislation.

Answered: 1 week ago

Question

LO4 Describe the purpose of privacy legislation.

Answered: 1 week ago