Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

- We are required to use a two 2D array as the background/floor/grid for a picture in which we have to generate random blocks within

- We are required to use a two 2D array as the background/floor/grid for a picture in which we have to generate random blocks within that grid and store it in the array. JAVA coding We have to have two functions one is depth first search using stacks class, and the other is depth first search using queues class. Please use double pointers when creating the arrays. One array has to pass through DFS and the other through BFS. The point in this project to show that the result is the same, but the timing is different. The functions should look similar to this:- generateArray(int **arrayA, int **arrayB); depthFirstSearch(int **arrayA); breadthFirstSearch(int **arrayB); displayArrayA(); displayArrayB(); Important Design Requirement: Your design must be based on Modularity and "Separation of Concerns". The Stack and Queue Data Structure implementations must be based on "Information Hiding" and "Encapsulation". The Application Code (e.g. Rat In Maze, Wire Router, Image Component Labeling, ...) know about the Data Structures only through their Interfaces (APIs). Remember that interfaces represent behavior, while classes represent implementation. Image Component Labeling A digitized image is an m x m matrix of pixels. - pixel is a word invented from picture elementSolution Strategy The components are determined by scanning the pixels by rows, from top to bottom, and within each row by coImage Component Labeling Example 1 1 1 1 1 1 1 DS&A Image Component Labeling Slide # 4Image Component Labeling Example 5515 5 4 616 DS&A Image Component Labeling Slide # 5Implementation o The program to label component pixels uses much of the development used for the Rat in the Maze and LeesImportant Design Requirement Your design must be based on Modularity and Separation of Concerns The Stack and Queue Data StrGeneral Strategy 1) Prompt the user for two values - The DIMENSION of the image in pixels (square grid of pixels) Must be anGeneral Strategy - continue For the purpose of illustration here, assume only for now, that the user chooses a DIMENSION of 1General Strategy- continue 3) Create imageDFS by randomly generating the pixel values The generatelmage operation will populaGenerating a Random Images Let R be the DENSITY, where 0 R 1 a The following pseudocode is used to populate the pixelsquare aGeneral Strategy-continue 4) Create imageBFS as an identical copy of imageDFS After populating the grid with pixel values andExample - Initial (After random pixel generation) Suppose the user entered 0,x 0,x 0,x0,x 0,x 0,x 0,x 0,x 1,x1,x 1,x 0,x 0,xExample - Corresponding DFS 0,x 0,x0,x 0,x 0,x0,x 0,x 0, 1,1 1,2 1,3 0,x 0,x 0,x 0,x 1,8 1,40x 2,1 2,2 2,3 0,x 1,7 1,5 1,6 0,Example - Corresponding BFS 0,x 0,x0,x0,x0,x0,x 0,x 0,x 1,1 1,2 1,40,x 0,x 0,x 0,x 1,3 1,5 0,x2,12,2 2,3 0,x 1,6 1,7 1,80,x 2

1) Prompt the user for two values: The DIMENSION of the image in pixels (square grid of pixels) Must be an integer between 5 and 20 inclusive (default is 15) 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.

2) 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, ...).

3) Create imageDFS by randomly generating the pixel values. 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)

4) 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.

5) Apply the Depth First Search algorithm to imageDFS Apply the Breadth First Search Algorithm to imageBFS Proceed as in the adapted Rate in Maze for DFS and then as in the adapted Lees Wire Router for BFS. 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.

6) Printout the two resulting images (see slides 13 and 14 below).

i've attached all the slides required with this questionimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

The answer should display the following results

Results

Sample 1 (Screenshots):

Dialog and Initial Grids (density is percentage):

image text in transcribed

Post DFS & BFS Traversal of Identical Input Grids:

image text in transcribed

Sample 2 (Screenshots):

DFS Before and After

image text in transcribed

BFS Before and After

Image Component Labeling . A digitized image is an m x m matrix of pixels. - "pixel" is a word invented from "picture element" . In a binary image, each pixel is either 0 or 1. - A 0 pixel represents image background, while a 1 represents a pixel on an image component. - We will refer to pixels whose value is 1 as component pixels. Two pixels are adjacent if one is to the left, above, right, or below the other. Two component pixels that are adjacent are pixels of the same image component. . The objective of component labeling is to label the component pixels so that two pixels get the same label if and only if they are pixels of the same image component. DS&A Image Component Labeling Slide # 2 Solution Strategy . The components are determined by scanning the pixels 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 component pixel is encountered, it is given a component identifier/label (new color). 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" using a stack as in the Rat-in-the-Maze problem or in "Breadth First Search" using a queue as in Lee's Wire Routing problem. - This process continues until no new unlabeled adjacent component pixels are found. DS&A Image Component Labeling Slide # 3 Image Component Labeling Example TT11 111 111 1 1 1 1 111111111111 1 1 1 1 1111 111 11 |11 111 |11|11 |11| 1| 11) 1|11| 11| 1 1 |11| 11 1 1 1 1 1 1 1 1) 1 1 1 1 111) DS&A Image Component Labeling Slide # 4 Image Component Labeling Example 2 2 2 2 3 3 3 2 3 3 3 3 2 2 5555 55 55 5555 551 6 6 1 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 DS&A Image Component Labeling Slide # 5 Implementation The program to label component pixels uses much of the development used for the "Rat in the Maze" and "Lee's Wire-Routing" problems. - To move around the image with ease, we surround the image with a wall of blank (here 0 pixels), unlike Rat in the Maze and Lee's Wire (Why?). - We use the "offset" array to determine the pixels adjacent to a given pixel. See starter code on Assignment 1 Canvas webpage... . Your task is to complete the labelComponents method and adapt the DFS and BFS algorithms from "Rat in Maze" and "Lee's Wire Router" in order to implement Depth First Search and Breadth First Search. DS&A Image Component Labeling Slide # 6 Important Design Requirement Your design must be based on Modularity and "Separation of Concerns". The Stack and Queue Data Structure implementations must be based on "Information Hiding" and "Encapsulation". The Application Code (e.g. Rat In Maze, Wire Router, Image Component Labeling, ...) know about the Data Structures only through their Interfaces (APIs). Remember that interfaces represent behavior, while classes represent implementation. DS&A Image Component Labeling Slide # 7 General Strategy 1) Prompt the user for two values: - The DIMENSION of the image in pixels (square grid of pixels) Must be an integer between 5 and 20 inclusive (default is 15) - 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. 2) 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, ...). DS&A Image Component Labeling Slide # 8 General Strategy - continue For the purpose of illustration here, assume only for now, that the user chooses a DIMENSION of 15x15 pixels. Create a 2-dimensional array of size 17 by 17 (15 + 2 for the surrounding walls). o Generate a grid of 15x15 cells, in the inner part of the array (i.e. excluding the surrounding walls), where each cell is either 0 (zero) for background, or 1 (one) for foreground. See slide 10 below. Important Observation: Notice that for the "Image component Labeling", we ignore the background O's and trace through the foreground l's, which is the opposite of "Rat in Maze" and "Lee's Wire Router", where we avoid the l's which are walls or transistors, and trace through the O's, which are open paths. DS&A Image Component Labeling Slide # 9 General Strategy - continue 3) Create image DFS by randomly generating the pixel values. The generatelmage operation will populate the pixel [] [] square array that represents the image with l's and O's for foreground and background, respectively. Don't forget the artificial wall around the image. Initially, the 0/1 randomly generated number may be stored in each pixel[row][coll.label (i.e. the label field of each pixel[row][col] object) DS&A Image Component Labeling Slide # 10 Generating a Random Images Let R be the DENSITY, where 0 SR 1 The following pseudocode is used to populate the pixel ( [] square array (image) for (int row = 1; row 20: Enter image density = 33: Before Depth First Search. The labeled image is [@ x][m x ][1,x][0,x][0,x][1,x][1,x][0 ][1.x][0 ][0 ][0 ][1,x][0,x][@.x] (1,x)(0,x][1,x][0 ][1,x][1,x][1,x][0 ][0 ][0 ][0 ][0 ][0 ][0 ][1,x) [0 x ][1,x][0,x][1,x][0,x][1,x][1,x][0 ][1,x][1,x][0 ][0,x][1,x][1,x][2 x ] [0.x][0, x][1,x][9,X] (0,] (0.x][1,x][0.x][0.x][0,x][,x][,x][%, x 9 ,x](,x] [0,x][1,x][0,X][0,x][0,x][0,x][1,x][0,x][0,X][0,x][1,x][0 ][1,x][1,x][0,X] 0.x][1.x][1.x][0,x)[0,x][0,x][0,x][0,x][0,x][0 ][1.x][0 ][0 ][0 ][0,x] [a, x][a, x][, x 1 , x 2 , x][8,x][8,x][8,x][8, x][8, x 1 ,x][a, x][, x 1 ,x][,x] (1.x oxox][0 ][0 ][0x1.xlix][0,x]|1, 10, 11,x][0, 0, 0, 10x10x10x10x0, xo.xile.xlix0.x10,10,x][0,x][0, 1, 0, @xlixo.xloxIo.xli.xlli.xli.x0.x ,x1,x2, 110, 11xx [0xloxox][0 ][1,x][1.xlixo.x][1.x][0 ][1,x)[0 ][0, 0, 0,xl (1.x10x10x10x1,xle.xlfo.xlex0.x0,X0,X][1,110,11,10x (1,x][0 ][0 ][0 ][1,x][0 ][0,x]{1,x][1.x][@ ][@ ][0, ][@ ][0,x][@ ] [0 ][0 ][0 ][1,x][1,x][0 ][0,x][1,x][0.x][0,x][0,x][1,x][1,x][0,x][0,x] (1.x][1,x][0, x][0,x][0,x] [0,x][0,x][1.x][0.x][0,x][0,x][0,x][0,x][0,x][0,x] xile.xiiixile in exile xl xex Before Breadth First Search. The labeled image is 10.xox1 .x][0 ][0 ][1,xl 1.xox][1, 10,110, X0,X][1, 0, 0, (1.xlox 1x10x1,x|(1,xlli.xlox0.x10x10x10x10x10x1.x [0 ][1,x)[0 ][1,x][mx][1,x][1,x][0 ][1,2][1.x][@,x) (@,x][1,X][1,](@,x) 10x10x1 .x][0 ][0 ][0x1.xox][0, 10,110, 110,x][0, 0, 0, [0x 1,x10,X][0 ][0 ][0,x][1,x o x ][@ ][@,x][1,x][@ ][1, 1, 0,x] 10x1x1,x][0x0,x(@xoxo.x][0, 0, 1, 0, 0, 0, 0, [0,x][0.x][0, x][1,x][0,x][0,x][0,x][0,x][0,x][0,x][1.x][0,x][0,x][1,x][0,X] (1,x][0,x][, X 0 ,X ] (0.x][1,x][1,x][0.x][1,x][9,x][1,x][9,x][9.][0.x] (@x oxox][0 ][0 ][0x@xli,x][mx][0 ][0 ][0 ][0, 1, 0,X] (0.xlli xllox][0 ][0 ][1,xli xlix][@.x][0 ][1 ][ x][0 ][1, 110, [0.x][0, x][0, x][0, 1,x][1,x][1,x][0.x][1,x][0.x][1,x][0, X 0 ,X 9 ,X] (0,X] (1.xoxoxoxli.xl@xoxlox][@]0x0.xlii. x11.11.11 (1.xoxox][0x1,xo.xlox li x 1, 0, 0,][0,x][0, 0, 0, [@ ][0 ][0 ][1,x]{1,x](@,x][@x][1,x][@,x][@ ][@ ][1.] [1,x][0,x][@ ] 11.x][1,x][0, x][0 ][0 ][0 ][0 ][1,x][@,x][0 ][0 ][0 ][0,x][0,x][0,x] 1. richard Macintosh 2: Desktop project 1-1 (zsh After Depth First Search, The labeled image is [ 0,x][ @ x][ 2,1][ 0,x][ 0,x][ 3,1][ 3,2][ 0.x][ 4,1][ 0,x][ 0,x][ 0.x][ 5,1][ @,x][ 6,1][ 0.x] 2,2][ 0.x] 3.91 3.811 3.31 0.xl 6xl 0,XI,XI @x10xx 0,xl 8,11 0,x 9,1][ 0.x] 3,7/ 3,40 0,x][ 10, 11 10,21 0, 0.x][ 11,1][ 11,2/ @,x][ 0,x][ 12,1][ 0,x][ @xl xll 3,511 0.xlxlox0.xl. x10x 0x 0.x][ 13,11 ,x] 0.x][ 0.xl 9,xl 3.61 0.x .x. ,x 14,11 0.x][ 15,1][ 15,2][ 0,x][ 13,2][ 13,3] ,xl 0.x][ 0, 0,x] 0,x][ 0.x][ 0,x][ 14,2] 0,x][ 0.x][ 0, x] 0.x][ @ x][ 0.x][ 16,1][ 0,x][ 0.x][ 0.x][ 0.x][ 0.x][ @ x][ 14,3][ 0,x][ 0.x][ 17,1] 18.1 0.x 0. 0.0.xl0.xl 19,1l 19,21 0.x20,11 0,xl 21,110x 0 .xl B.XI 0xC0xl 0,x][ 0xC0x 0xl 19,31 0,XL,XI,XI,XI,XI 22,11 2x 23 100x 0x0.x][1913 19511 19,41 0,XI ,XI 24,11 0,x][0x 22,21 0.XI 0.xlL0xl xl 19.81 19,71 19.610.XI 25, 110,x][ 24,21 0.x . x x l 26,11 0,xl 0.x][ @x][ 19.91 0x 0x 0 .x] @x][ , 0,x][ 27,11 0,xl 28,111 (2621 0.xlL 0x0.x 19.10110.xll exll 29.11 29,21 0, 0, 0, 0, 0, 0x 0.xlL0xl 19.12 | 19.111 @.xl.xll 29,31 @.,xl x1 30.11 30.21 0.xl 31.11 31.210xl 6xl xl xl xll 29,41 @.xl. xl xl x10x 0x XXXXXXXXXXXXXX After Breadth First Search. The labeled image is ,x) [ 0.x][ 0,x][ 2.10 0. .][ 3,11 3,2](_0.x] 4,11 0, 0, 0,x][ 5,10 ,x 6,1][ 0,x][ 2,2) 0,x l 3,6 0 3,3 3,4 0,x][ 9,x][ 0, 0, 0,x][ 0.x][ @,x @x][ 8.111 0.x][ 9.11| 0.x][ 3,511 3.711 0.xl 10,11| 10.21 0.x][ 0.xl 11,111 11,211 0.x][ 0, x][ 12,1 0.x][ 0.x][ 0.XII 3.81 0.xl xl 9.X ,XI 0, x 0 .xl . x @,x][ 13,1][ 0,x][ 0.x] 0,x][ 0x[ 3.9][ 0 ][0x 0 .x][ 14,11 0,x][ 15, 11 15,21 0.x][ 13,2] 13 31 0.x][ 0,x][ 0.x][ 0.x] 0.x][ 0.x][ x]I 14,2][ 0.x][ 0.x][ 0.x][ @XI w.xll 0.xl 16.11 0.xl 0. 1 0. 1 0. 1 0.x10, 14.31 0.x][ 0.x][ 17,1][ 18.10 0.xl 0.x][ 0.x][ 0.x][ 0.x 19,1l 19,210,x][ 20,1 0,x]21,111 0,XI,XI 0.xl 0.xll 9. x 0.xl 0.xl 0.xl xl 19. 3 0.XI,0,x10x10x22.11 0.xl 23.11 0.1 0. 0.xl 19, 19.5| 19,41 0,XI ,XI 24,11 0. x 0 .x 22.21 @xl 0.xl 0.x][ 0.x][ 19.91 19,81 19,60 0,| 25, 100, 24,21 0,x][0x 0x 26.11 0.xlL0xl xl 19,101 .xll .xll 0.XI.XI,XI,X1 27.11 0. x 28, 11 26.21 0.xll 0.x Oxl 19,111 @x o.xll 29,1| 29,21,I0.10 . x .xl . x @xl 0x 0.x][19, 13(19.121 0.xlxll 29,31 0,0 0, 0 0,x]30,1 30,21 0,xl [ 31,1][ 31,2](_0x] 0,x][ 0.x][ 0.x][ 0.x][ 29.4] 0.x][ 0.x][ 0,x][ 0.x][ 0.x][ 0.x][ Nooooooooooo x='xxxxxxx xxx XXX Would you like to run this program again? (y): ni Thanks for using this program! richard@Macintosh-2 /Desktop/aroject_1-1 Image Before Labeling (Depth First Search), a, a 1,8 1,2 1,8 1,8 1,2 , 1,8 1, 1,8 6 8 8, 1,2 8 9 9 o o o o o o 4 6 4 4 6 o o o o 8 0 4 0 o' 0 0 6 6 6 8 8 1. 1,2 1,2 1, 1,8 1,2 1,2 1,2 6, ,. 1,a 1,8 Image After Labeling (Depth First Search) 2,4 8,8 8,8 8, 2,14 2,1 2,9 2,2 2,8 2,3 2,5 , 5,1 5,2 | a, a e,a 5, 6 5,33 5,38 5,32 5,31 8,e 6,e 4,1 4.2 5,15 5,12 0 4 T8,8 4,4 4,3 ,8 | a, a 5,9 8,8 5,18 5,11 ,8 5,16 2, 5,8 6,8 , , 5,13 5,28 5,27 6, 5,29 a, a , 5,14 6, 5,2; 2, , le,e 1,1 8 T6,29 N O G F S S o o o o o o o' , 5,3 5,4 5,18 5,19 5,28 8,8 6,49 6,18 6,11 16,12 , , 6, 13,2 6,27 6 M M 9 6 M & 0 0 0 0 0 0 0 6,9 9 M M 4 M M d d 0 0 0 5,25 6, 8,11 7,2 , ,e 6,24 a,a ,12 6,33 6,34 8,3 , 6,23 6,7 6,8 6,47 6,21 8,8 [6,18 6,19 8, 6,48 6,15 6,16 NOOOOOWO 8,8 6 o o o 6,35 6,38 6,39 6,48 6,36 6,37 , 6,41 N'S 06 0 0 0 0 6,44 2, ,8 11,1 | a, a 6,17 6,43 , 2,8 6,28 8, 12,1 o, a, 8, 13,1 13,3 8, 8,8 15,1 Image Component Labeling . A digitized image is an m x m matrix of pixels. - "pixel" is a word invented from "picture element" . In a binary image, each pixel is either 0 or 1. - A 0 pixel represents image background, while a 1 represents a pixel on an image component. - We will refer to pixels whose value is 1 as component pixels. Two pixels are adjacent if one is to the left, above, right, or below the other. Two component pixels that are adjacent are pixels of the same image component. . The objective of component labeling is to label the component pixels so that two pixels get the same label if and only if they are pixels of the same image component. DS&A Image Component Labeling Slide # 2 Solution Strategy . The components are determined by scanning the pixels 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 component pixel is encountered, it is given a component identifier/label (new color). 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" using a stack as in the Rat-in-the-Maze problem or in "Breadth First Search" using a queue as in Lee's Wire Routing problem. - This process continues until no new unlabeled adjacent component pixels are found. DS&A Image Component Labeling Slide # 3 Image Component Labeling Example TT11 111 111 1 1 1 1 111111111111 1 1 1 1 1111 111 11 |11 111 |11|11 |11| 1| 11) 1|11| 11| 1 1 |11| 11 1 1 1 1 1 1 1 1) 1 1 1 1 111) DS&A Image Component Labeling Slide # 4 Image Component Labeling Example 2 2 2 2 3 3 3 2 3 3 3 3 2 2 5555 55 55 5555 551 6 6 1 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 DS&A Image Component Labeling Slide # 5 Implementation The program to label component pixels uses much of the development used for the "Rat in the Maze" and "Lee's Wire-Routing" problems. - To move around the image with ease, we surround the image with a wall of blank (here 0 pixels), unlike Rat in the Maze and Lee's Wire (Why?). - We use the "offset" array to determine the pixels adjacent to a given pixel. See starter code on Assignment 1 Canvas webpage... . Your task is to complete the labelComponents method and adapt the DFS and BFS algorithms from "Rat in Maze" and "Lee's Wire Router" in order to implement Depth First Search and Breadth First Search. DS&A Image Component Labeling Slide # 6 Important Design Requirement Your design must be based on Modularity and "Separation of Concerns". The Stack and Queue Data Structure implementations must be based on "Information Hiding" and "Encapsulation". The Application Code (e.g. Rat In Maze, Wire Router, Image Component Labeling, ...) know about the Data Structures only through their Interfaces (APIs). Remember that interfaces represent behavior, while classes represent implementation. DS&A Image Component Labeling Slide # 7 General Strategy 1) Prompt the user for two values: - The DIMENSION of the image in pixels (square grid of pixels) Must be an integer between 5 and 20 inclusive (default is 15) - 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. 2) 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, ...). DS&A Image Component Labeling Slide # 8 General Strategy - continue For the purpose of illustration here, assume only for now, that the user chooses a DIMENSION of 15x15 pixels. Create a 2-dimensional array of size 17 by 17 (15 + 2 for the surrounding walls). o Generate a grid of 15x15 cells, in the inner part of the array (i.e. excluding the surrounding walls), where each cell is either 0 (zero) for background, or 1 (one) for foreground. See slide 10 below. Important Observation: Notice that for the "Image component Labeling", we ignore the background O's and trace through the foreground l's, which is the opposite of "Rat in Maze" and "Lee's Wire Router", where we avoid the l's which are walls or transistors, and trace through the O's, which are open paths. DS&A Image Component Labeling Slide # 9 General Strategy - continue 3) Create image DFS by randomly generating the pixel values. The generatelmage operation will populate the pixel [] [] square array that represents the image with l's and O's for foreground and background, respectively. Don't forget the artificial wall around the image. Initially, the 0/1 randomly generated number may be stored in each pixel[row][coll.label (i.e. the label field of each pixel[row][col] object) DS&A Image Component Labeling Slide # 10 Generating a Random Images Let R be the DENSITY, where 0 SR 1 The following pseudocode is used to populate the pixel ( [] square array (image) for (int row = 1; row 20: Enter image density = 33: Before Depth First Search. The labeled image is [@ x][m x ][1,x][0,x][0,x][1,x][1,x][0 ][1.x][0 ][0 ][0 ][1,x][0,x][@.x] (1,x)(0,x][1,x][0 ][1,x][1,x][1,x][0 ][0 ][0 ][0 ][0 ][0 ][0 ][1,x) [0 x ][1,x][0,x][1,x][0,x][1,x][1,x][0 ][1,x][1,x][0 ][0,x][1,x][1,x][2 x ] [0.x][0, x][1,x][9,X] (0,] (0.x][1,x][0.x][0.x][0,x][,x][,x][%, x 9 ,x](,x] [0,x][1,x][0,X][0,x][0,x][0,x][1,x][0,x][0,X][0,x][1,x][0 ][1,x][1,x][0,X] 0.x][1.x][1.x][0,x)[0,x][0,x][0,x][0,x][0,x][0 ][1.x][0 ][0 ][0 ][0,x] [a, x][a, x][, x 1 , x 2 , x][8,x][8,x][8,x][8, x][8, x 1 ,x][a, x][, x 1 ,x][,x] (1.x oxox][0 ][0 ][0x1.xlix][0,x]|1, 10, 11,x][0, 0, 0, 10x10x10x10x0, xo.xile.xlix0.x10,10,x][0,x][0, 1, 0, @xlixo.xloxIo.xli.xlli.xli.x0.x ,x1,x2, 110, 11xx [0xloxox][0 ][1,x][1.xlixo.x][1.x][0 ][1,x)[0 ][0, 0, 0,xl (1.x10x10x10x1,xle.xlfo.xlex0.x0,X0,X][1,110,11,10x (1,x][0 ][0 ][0 ][1,x][0 ][0,x]{1,x][1.x][@ ][@ ][0, ][@ ][0,x][@ ] [0 ][0 ][0 ][1,x][1,x][0 ][0,x][1,x][0.x][0,x][0,x][1,x][1,x][0,x][0,x] (1.x][1,x][0, x][0,x][0,x] [0,x][0,x][1.x][0.x][0,x][0,x][0,x][0,x][0,x][0,x] xile.xiiixile in exile xl xex Before Breadth First Search. The labeled image is 10.xox1 .x][0 ][0 ][1,xl 1.xox][1, 10,110, X0,X][1, 0, 0, (1.xlox 1x10x1,x|(1,xlli.xlox0.x10x10x10x10x10x1.x [0 ][1,x)[0 ][1,x][mx][1,x][1,x][0 ][1,2][1.x][@,x) (@,x][1,X][1,](@,x) 10x10x1 .x][0 ][0 ][0x1.xox][0, 10,110, 110,x][0, 0, 0, [0x 1,x10,X][0 ][0 ][0,x][1,x o x ][@ ][@,x][1,x][@ ][1, 1, 0,x] 10x1x1,x][0x0,x(@xoxo.x][0, 0, 1, 0, 0, 0, 0, [0,x][0.x][0, x][1,x][0,x][0,x][0,x][0,x][0,x][0,x][1.x][0,x][0,x][1,x][0,X] (1,x][0,x][, X 0 ,X ] (0.x][1,x][1,x][0.x][1,x][9,x][1,x][9,x][9.][0.x] (@x oxox][0 ][0 ][0x@xli,x][mx][0 ][0 ][0 ][0, 1, 0,X] (0.xlli xllox][0 ][0 ][1,xli xlix][@.x][0 ][1 ][ x][0 ][1, 110, [0.x][0, x][0, x][0, 1,x][1,x][1,x][0.x][1,x][0.x][1,x][0, X 0 ,X 9 ,X] (0,X] (1.xoxoxoxli.xl@xoxlox][@]0x0.xlii. x11.11.11 (1.xoxox][0x1,xo.xlox li x 1, 0, 0,][0,x][0, 0, 0, [@ ][0 ][0 ][1,x]{1,x](@,x][@x][1,x][@,x][@ ][@ ][1.] [1,x][0,x][@ ] 11.x][1,x][0, x][0 ][0 ][0 ][0 ][1,x][@,x][0 ][0 ][0 ][0,x][0,x][0,x] 1. richard Macintosh 2: Desktop project 1-1 (zsh After Depth First Search, The labeled image is [ 0,x][ @ x][ 2,1][ 0,x][ 0,x][ 3,1][ 3,2][ 0.x][ 4,1][ 0,x][ 0,x][ 0.x][ 5,1][ @,x][ 6,1][ 0.x] 2,2][ 0.x] 3.91 3.811 3.31 0.xl 6xl 0,XI,XI @x10xx 0,xl 8,11 0,x 9,1][ 0.x] 3,7/ 3,40 0,x][ 10, 11 10,21 0, 0.x][ 11,1][ 11,2/ @,x][ 0,x][ 12,1][ 0,x][ @xl xll 3,511 0.xlxlox0.xl. x10x 0x 0.x][ 13,11 ,x] 0.x][ 0.xl 9,xl 3.61 0.x .x. ,x 14,11 0.x][ 15,1][ 15,2][ 0,x][ 13,2][ 13,3] ,xl 0.x][ 0, 0,x] 0,x][ 0.x][ 0,x][ 14,2] 0,x][ 0.x][ 0, x] 0.x][ @ x][ 0.x][ 16,1][ 0,x][ 0.x][ 0.x][ 0.x][ 0.x][ @ x][ 14,3][ 0,x][ 0.x][ 17,1] 18.1 0.x 0. 0.0.xl0.xl 19,1l 19,21 0.x20,11 0,xl 21,110x 0 .xl B.XI 0xC0xl 0,x][ 0xC0x 0xl 19,31 0,XL,XI,XI,XI,XI 22,11 2x 23 100x 0x0.x][1913 19511 19,41 0,XI ,XI 24,11 0,x][0x 22,21 0.XI 0.xlL0xl xl 19.81 19,71 19.610.XI 25, 110,x][ 24,21 0.x . x x l 26,11 0,xl 0.x][ @x][ 19.91 0x 0x 0 .x] @x][ , 0,x][ 27,11 0,xl 28,111 (2621 0.xlL 0x0.x 19.10110.xll exll 29.11 29,21 0, 0, 0, 0, 0, 0x 0.xlL0xl 19.12 | 19.111 @.xl.xll 29,31 @.,xl x1 30.11 30.21 0.xl 31.11 31.210xl 6xl xl xl xll 29,41 @.xl. xl xl x10x 0x XXXXXXXXXXXXXX After Breadth First Search. The labeled image is ,x) [ 0.x][ 0,x][ 2.10 0. .][ 3,11 3,2](_0.x] 4,11 0, 0, 0,x][ 5,10 ,x 6,1][ 0,x][ 2,2) 0,x l 3,6 0 3,3 3,4 0,x][ 9,x][ 0, 0, 0,x][ 0.x][ @,x @x][ 8.111 0.x][ 9.11| 0.x][ 3,511 3.711 0.xl 10,11| 10.21 0.x][ 0.xl 11,111 11,211 0.x][ 0, x][ 12,1 0.x][ 0.x][ 0.XII 3.81 0.xl xl 9.X ,XI 0, x 0 .xl . x @,x][ 13,1][ 0,x][ 0.x] 0,x][ 0x[ 3.9][ 0 ][0x 0 .x][ 14,11 0,x][ 15, 11 15,21 0.x][ 13,2] 13 31 0.x][ 0,x][ 0.x][ 0.x] 0.x][ 0.x][ x]I 14,2][ 0.x][ 0.x][ 0.x][ @XI w.xll 0.xl 16.11 0.xl 0. 1 0. 1 0. 1 0.x10, 14.31 0.x][ 0.x][ 17,1][ 18.10 0.xl 0.x][ 0.x][ 0.x][ 0.x 19,1l 19,210,x][ 20,1 0,x]21,111 0,XI,XI 0.xl 0.xll 9. x 0.xl 0.xl 0.xl xl 19. 3 0.XI,0,x10x10x22.11 0.xl 23.11 0.1 0. 0.xl 19, 19.5| 19,41 0,XI ,XI 24,11 0. x 0 .x 22.21 @xl 0.xl 0.x][ 0.x][ 19.91 19,81 19,60 0,| 25, 100, 24,21 0,x][0x 0x 26.11 0.xlL0xl xl 19,101 .xll .xll 0.XI.XI,XI,X1 27.11 0. x 28, 11 26.21 0.xll 0.x Oxl 19,111 @x o.xll 29,1| 29,21,I0.10 . x .xl . x @xl 0x 0.x][19, 13(19.121 0.xlxll 29,31 0,0 0, 0 0,x]30,1 30,21 0,xl [ 31,1][ 31,2](_0x] 0,x][ 0.x][ 0.x][ 0.x][ 29.4] 0.x][ 0.x][ 0,x][ 0.x][ 0.x][ 0.x][ Nooooooooooo x='xxxxxxx xxx XXX Would you like to run this program again? (y): ni Thanks for using this program! richard@Macintosh-2 /Desktop/aroject_1-1 Image Before Labeling (Depth First Search), a, a 1,8 1,2 1,8 1,8 1,2 , 1,8 1, 1,8 6 8 8, 1,2 8 9 9 o o o o o o 4 6 4 4 6 o o o o 8 0 4 0 o' 0 0 6 6 6 8 8 1. 1,2 1,2 1, 1,8 1,2 1,2 1,2 6, ,. 1,a 1,8 Image After Labeling (Depth First Search) 2,4 8,8 8,8 8, 2,14 2,1 2,9 2,2 2,8 2,3 2,5 , 5,1 5,2 | a, a e,a 5, 6 5,33 5,38 5,32 5,31 8,e 6,e 4,1 4.2 5,15 5,12 0 4 T8,8 4,4 4,3 ,8 | a, a 5,9 8,8 5,18 5,11 ,8 5,16 2, 5,8 6,8 , , 5,13 5,28 5,27 6, 5,29 a, a , 5,14 6, 5,2; 2, , le,e 1,1 8 T6,29 N O G F S S o o o o o o o' , 5,3 5,4 5,18 5,19 5,28 8,8 6,49 6,18 6,11 16,12 , , 6, 13,2 6,27 6 M M 9 6 M & 0 0 0 0 0 0 0 6,9 9 M M 4 M M d d 0 0 0 5,25 6, 8,11 7,2 , ,e 6,24 a,a ,12 6,33 6,34 8,3 , 6,23 6,7 6,8 6,47 6,21 8,8 [6,18 6,19 8, 6,48 6,15 6,16 NOOOOOWO 8,8 6 o o o 6,35 6,38 6,39 6,48 6,36 6,37 , 6,41 N'S 06 0 0 0 0 6,44 2, ,8 11,1 | a, a 6,17 6,43 , 2,8 6,28 8, 12,1 o, a, 8, 13,1 13,3 8, 8,8 15,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

Students also viewed these Databases questions