Question
In C language , Image editing programs often use the flood fill algorithm to fill similarly colored connected areas with a new color. Suppose that
In C language , Image editing programs often use the flood fill algorithm to fill similarly colored connected areas with a new color. Suppose that the two-dimensional 88 array of Figure 11.4a represents the pixels of an image, where 0 represents the black color, 1: white, 2: red, 3: green, and 4: blue, while a pixel is similarly colored connected with another, if they have the same color and it is adjacent to it. The similarly colored areas are depicted in Figure 11.4b.
To implement the flood fill algorithm, write a recursive floodfill() function which change the color (i.e., c) of a pixel at a location (i.e., i, j) to a new color (i.e., nc) and then it changes the color of its neighbouring pixels (i.e., the pixels to the left, right, above, and below the pixel at (i, j)) whose color is also c. This process continues recursively on the neighbours of the changed pixels until there are no more pixel locations to consider.
For example, if we choose to change the color of the pixel in the position 0, 0 from black (i.e., 0) to green (i.e., 3), the color of the top-left area of four pixels changes to green, as shown in Figure 11.4c.
Write a program that creates a two-dimensional 88 array of integers and assigns to its elements random values in [0, 4]. Then, the program should read the location of a pixel and a new color and use floodfill() to change the existing color of its similarly colored area with the new one.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started