Question: Can someone help with this problem in C++ language, please? -- Prompt the user for two values: The DIMENSION of the image in pixels (square

Can someone help with this problem in C++ language, please?

-- Prompt the user for two values:

The DIMENSION of the image in pixels (square grid of pixels) Must be an integer between 5 and 15 inclusive (default is 10)

The DENSITY of foreground pixels

Must be a floating number between 0.0 and 1.0 (default is 0.33)

For example, DENSITY = 0.25, means that 25% of the pixels should be foreground and the remaining 75% should be background. DENSITY is optional in the Java version.

- Your program maintains a 2-D grid (array) of objects, where each object keeps track of two values, the image component label (to be assigned by DFS or BFS), and the order in which the pixel was discovered, which depends on the search strategy (DFS or BFS). Accordingly, each pixel is represented by an object that encapsulates a label (component label: 1, 2, 3, ...) and (order of discovery: 1, 2, 3, ...).

You may also find it useful to maintain a Boolean instance variable (ivar) per pixel object to indicate if this pixel has been labeled by DFS/BFS or not yet!

- The generateImage operation will populate the pixel[][] square array that represents the image with 1s and 0s for foreground and background, respectively. Dont forget the

artificial wall around the image. Initially, the 0/1

randomly generated number may be stored in each pixel[row][col].label

(i.e. the label field of each pixel[row][col] object)

Generate a random number R such that 0 R 9 1

The following pseudocode is used to populate the pixel[][] square array :

for (int row = 1; row <= DIMENSION; row++)

for (int col = 1; col <= DIMENSION; col++)

{

// generate a Random number R between 0 and 1; if (R < DENSITY)

pixel[row][col].label = 1; // foreground else

pixel[r0w].col].label = 0; // background }

If for example, DENSITY = 0.25, then the image will be 75% background and 25% foreground.

All pixels of the same component will have the same label value and an order number which starts at 1 and keeps counting per image component pixel.

Printout the two resulting images

Suppose the user entered:

DIMENSION = 7

DENSITY = 0.33 (default)

Then your program may generate the following image with 16 foreground pixels out of the 49 image pixels. (This doesnt account for the surrounding wall.)

The x values are unset ORDER ivars

The Depth First Search algorithm will printout the following corresponding grid of pixels:

0,x 0,x 0,x 0,x 0,x 0,x 0,x

0,x 1,1 1,2 1,3 0,x 0,x 0,x

0,x 1,8 1,4 0,x 2,1 2,2 2,3

0,x 1,7 1,5 1,6 0,x 2,8 2,4

0,x 0,x 0,x 0,x 0,x 2,6 2,5

0,x 0,x 0,x 0,x 0,x 2,7 0,x

0,x 0,x 0,x 0,x 0,x 0,x 0,x

And the Breadth First Search algorithm will printout the following corresponding grid of pixels:

0,x 0,x 0,x 0,x 0,x 0,x 0,x

0,x 1,1 1,2 1,4 0,x 0,x 0,x

0,x 1,3 1,5 0,x 2,1 2,2 2,3

0,x 1,6 1,7 1,8 0,x 2,4 2,5

0,x 0,x 0,x 0,x 0,x 2,6 2,7

0,x 0,x 0,x 0,x 0,x 2,8 0,x

0,x 0,x 0,x 0,x 0,x 0,x 0,x

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!