Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The paint fill or floor fill algorithm is implemented in many imageFigure 1 ( a ) shous example of a 8 9 array with various

The paint fill or floor fill algorithm is implemented in many imageFigure 1(a) shous example of a 89 array with various cell colors, and Figure 1(b) shows its corresponding
2D array, which is what your program will take as input.
(a)
(b)
Figure 1: Example of an input 89 array. (a) Cell colors. (b) Input array to program.
Assume that array indices start from 0, and the top-left cell is (0,0).
(a)
(b)
Figure 2: Example of output 89 array. (a) Cell colors. (b) Output array from program.
editing programs. Given a screen (represented by a two-dimensional array of colors), a point, and a new
color, the algorithm fills in the surrounding area until the color changes from the original color. The 2D
array is like a graph where the nodes are each cell (or, pixel)(i, j) and edges are between adjacent cell /
pixel. For example, (i +1, j),(i 1, j),(i, j +1) and (i, j 1).
You will implement this algorithm in a program to fill connected, similarly colored areas with a different
color. Your algorithm takes as input four parameters: a 2D array, a start node, a target color, and a
replacement color. The 2D arrays elements are colors whose values are (R,G,B,Y,W,g,X),
which refer to (red, green, blue, yellow, white, grey and black) colors. Start node is given as (i, j, where i
is a row index and j is a column index.
Figure 1(a) shows example of a 8\times 9 array with various cell colors, and Figure 1(b) shows its corresponding
2D array, which is what your program will take as input.
Figure 1: Example of an input 8\times 9 array. (a) Cell colors. (b) Input array to program.
Assume that array indices start from 0, and the top-left cell is (0,0).
If the start node is (6,2), target color is B(i.e., black) and the replacement color is g(i.e., grey), the
algorithm looks for all nodes in the 2D array that are connected to the start node by a path of the target
color and changes them to the replacement color. Figure 2(a) shows output of the above input as a 8\times 9
array with black cell colors modified to grey. Figure 2(b) is what your program should output for this
input. You should also print a list of cell locations (i, j) in row major order and the total number of cells
modified. For this input,
1
List of cell locations modified:
(1,6),(1,7),(1,8),
(2,6),(2,7),(2,8),
(3,7),(3,8),
(4,6),(4,7),(4,8),
(5,6),(5,7),(5,8),
(6,2),(6,7),(6,8),
(7,2),(7,3),(7,4),(7,5),(7,6),(7,7),(7,8)
Number of cells modified: 24
Figure 2: Example of output 8\times 9 array. (a) Cell colors. (b) Output array from program.
You must submit the following to receive full credit.
(1) Python or Java script file with comments and structure.
(2) Testcase(s) on which you validated your program. Each testcase must be a testcase-i.txt file where
i =1,2,..., n are indices to your testcase files. You MUST include at least two testcase files.
(3) Please make sure you handle corner cases, and gracefully error out when you are provided with in-
correct inputs, etc. Program crashes or errors or no outputs will be penalized.(a)
(b)
Figure 2: Example of output 89 array. (a) Cell colors. (b) Output array from program.
Give me the correct answer which is asked in the question which satisfies all the requirements and check for corner test cases also?
image text in transcribed

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

Data Analytics And Quality Management Fundamental Tools

Authors: Joseph Nguyen

1st Edition

B0CNGG3Y2W, 979-8862833232

More Books

Students also viewed these Databases questions