Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following should be done in C++. Have the user enter 2 parameters. One of the range 5-25 for the number of positions of a

The following should be done in C++.

Have the user enter 2 parameters. One of the range 5-25 for the number of positions of a grid, and one for the density of nonzero numbers (foreground pixels in this case) in the foreground. This decimal represents the percentage of squares which will have nonzero numbers . Squares should be 0 in the background (background pixels) and an integer number in the foreground (each cluster will be a positive integer). Two grids should be made. The first does a depth search first using stacks, and the second does a breadth first search using queues.

The components are determined by scanning the squares by rows, from top to bottom, and within each row by columns, from left to right. Accordingly, the scanning order is similar to reading a page of English text.

When an unlabeled foreground pixel (nonzero number in the grid) is encountered, it is given a component identifier/label. Labels are assigned starting with 2, because 1 denotes foreground and 0 denotes background.

This pixel forms the seed of a new component.

We determine the remaining pixels in the component by identifying and labeling all component pixels that are adjacent to the seed.

Labeling adjacent component pixels allows to discover more adjacent component pixels (neighbor of neighbor is a neighbor).

This exploration can be directed in Depth First Search or Breadth First Search using a queue problem.

This process continues until no new unlabeled adjacent component pixels are found.

We use the offset array to determine the pixels adjacent to a given pixel.

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: 2, 3, 4, ...) and (order of discovery: 1, 2, 3, ...).

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

Create imageBFS as an identical copy of imageDFS.

After populating the grid with pixel values and surrounding walls, clone the grid so that the first copy is used for DFS and the identical second copy for BFS.

Apply the Depth First Search algorithm to imageDFS Apply the Breadth First Search Algorithm to imageBFS . The image components are labeled in the order discovered by the respective search algorithm. 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

image text in transcribed

image text in transcribed

- X Assic X C 3 X File 30P X 30 P x Con X 045 x 3px Grat x ma x And X Sylle x 2021 + C:/Users/Jakes%20Radical%20PC/Downloads/3e%20Programming%20Assignment%201%20Image%20Component%20Labeling%20v2%20(3).pdf E 3e Programming Assignment 1 Image Component Labeling v2 15/17 Example - Corresponding BFS 0, 0, 0, 0,x 0, 0, 0,x And the Breadth First Search algorithm will printout the following corresponding grid of pixels: 0.X 1,1 1,2 1,4 0x 0x 0x 0,x 0,x 0, 1,3 1,6 0, 1,5 1,7 0,x 0,x 1,8 2,1 0,x 2,2 2,4 2,3 2,5 0,x 0.x 0,x 0,4 0,x 2,8 Ox 0.x 0x 0,x 0.x 0x 0x10x 3e Programming A...pdf 2020-1 Spring Syll...pdf A componentLabeling.cpp " 3e Programming...ppsx A 3e Programming...ppsx Show all X 1 Type here to search oto e e 9 W 8:07 PM .E. MENG : 4 EN 2/19/2020 1 Assic X 3 X 30P X 30 P x Con X 045 x 3px Grat x ma x And X Sylle x 2021 + - X C O File C:/Users/Jakes%20Radical%20PC/Downloads/3e%20Programming%20Assignment%201%20Image%20Component%20Labeling%20v2%20(3).pdf a 3e Programming Assignment 1 Image Component Labeling v2 14/17 Example - Corresponding DFS The Depth First Search algorithm will printout the following corresponding grid of pixels: 0,x 0, 0, 0, 0, 0, 0,x 0,x 1,1 1,2 1,3 0,x 0,x 0,x 0,7 1,8 1,4 0,x 2,1 2,2 2,3 0x 1,7 1,5 1,6 0.x 2,8 2,4 0.x 0x 0,x 0,x 0,x 2,6 2,5 0,x 0x 0,x 0,x 0,x 2,70,X 0,2 0,x 0,x 0,x 0,x 0,x 0x DSBA Image Component Labeling Slide # 14 3e Programming A...pdf 2020-1 Spring Syll...pdf A componentLabeling.cpp " 3e Programming...ppsx A 3e Programming...ppsx Show all X 1 Type here to search oto e e 9 W 8:07 PM .E. MENG : 4 EN 2/19/2020 1 - X Assic X C 3 X File 30P X 30 P x Con X 045 x 3px Grat x ma x And X Sylle x 2021 + C:/Users/Jakes%20Radical%20PC/Downloads/3e%20Programming%20Assignment%201%20Image%20Component%20Labeling%20v2%20(3).pdf E 3e Programming Assignment 1 Image Component Labeling v2 15/17 Example - Corresponding BFS 0, 0, 0, 0,x 0, 0, 0,x And the Breadth First Search algorithm will printout the following corresponding grid of pixels: 0.X 1,1 1,2 1,4 0x 0x 0x 0,x 0,x 0, 1,3 1,6 0, 1,5 1,7 0,x 0,x 1,8 2,1 0,x 2,2 2,4 2,3 2,5 0,x 0.x 0,x 0,4 0,x 2,8 Ox 0.x 0x 0,x 0.x 0x 0x10x 3e Programming A...pdf 2020-1 Spring Syll...pdf A componentLabeling.cpp " 3e Programming...ppsx A 3e Programming...ppsx Show all X 1 Type here to search oto e e 9 W 8:07 PM .E. MENG : 4 EN 2/19/2020 1 Assic X 3 X 30P X 30 P x Con X 045 x 3px Grat x ma x And X Sylle x 2021 + - X C O File C:/Users/Jakes%20Radical%20PC/Downloads/3e%20Programming%20Assignment%201%20Image%20Component%20Labeling%20v2%20(3).pdf a 3e Programming Assignment 1 Image Component Labeling v2 14/17 Example - Corresponding DFS The Depth First Search algorithm will printout the following corresponding grid of pixels: 0,x 0, 0, 0, 0, 0, 0,x 0,x 1,1 1,2 1,3 0,x 0,x 0,x 0,7 1,8 1,4 0,x 2,1 2,2 2,3 0x 1,7 1,5 1,6 0.x 2,8 2,4 0.x 0x 0,x 0,x 0,x 2,6 2,5 0,x 0x 0,x 0,x 0,x 2,70,X 0,2 0,x 0,x 0,x 0,x 0,x 0x DSBA Image Component Labeling Slide # 14 3e Programming A...pdf 2020-1 Spring Syll...pdf A componentLabeling.cpp " 3e Programming...ppsx A 3e Programming...ppsx Show all X 1 Type here to search oto e e 9 W 8:07 PM .E. MENG : 4 EN 2/19/2020 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Managerial Accounting

Authors: Ray H. Garrison, Eric W. Noreen, Peter C. Brewer

13th Edition

978-0073379616, 73379611, 978-0697789938

Students also viewed these Accounting questions