Assume a 2-D array (matrix) represents an image where zeros are white pixels, and ones are black pixels. For example this 5x7 matrix:
0 0 1 1 1 0 0
0 1 0 0 0 1 0
1 1 1 1 1 1 1
0 1 0 0 0 1 0
0 1 0 1 0 1 0
represents this image:
Filling with Red: When a white pixel is selected, all the white pixels in the same region (including the selected pixel) will be turned into red pixels. (Red is represented with two). For example, if the pixel (1, 0) is selected in the previous image, the result will be the following:
(You will not display 'X' mark. It is just shown for your convenience)
2 2 1 1 1 0 0
2 1 0 0 0 1 0
1 1 1 1 1 1 1
0 1 0 0 0 1 0
0 1 0 1 0 1 0
Or, if the pixel (3,4) is selected, the result will be the following:
0 0 1 1 1 0 0
0 1 0 0 0 1 0
1 1 1 1 1 1 1
0 1 2 2 2 1 0
0 1 2 1 2 1 0
Definition of Region: If two white pixels are adjacent (horizontally or vertically, but not in the diagonal), they are in the same region.
The given program reads two integers: N and M. Then reads NxM integers as a matrix (image). Then reads two integers: pI and pJ as the coordinates of the selected pixel. You should fill the region of the selected pixel with red on the image. Then the given code prints the image to the screen (currently the unchanged image is printed). Assume always a white pixel will be selected.
INPUT | OUTPUT |
4 4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 3 1 |
1 0 0 0 2 1 0 0 2 2 1 0 2 2 2 1 |
5 5 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 0 2 2 |
0 0 1 0 0 0 1 2 1 0 1 2 2 2 1 0 1 2 1 0 0 0 1 0 0 |
6 6 0 0 0 0 0 0 0 1 1 1 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 1 1 1 0 0 0 0 0 0 0 5 5 |
2 2 2 2 2 2 2 1 1 1 1 2 2 1 0 0 1 2 2 1 0 0 1 2 2 1 1 1 1 2 2 2 2 2 2 2 |
Important issues about all exams/projects/quizzes: