The brightness of the pixels in the picture is encoded with numbers from 0 to 255 in the form of a matrix. Convert the picture to black and white using the following algorithm:
calculate the average brightness of pixels over the entire image
all pixels, the brightness of which is less than average, make black (write code 0), and the rest -– white (code 255)
Input
The first line contains space-separated dimensions of the matrix: the number of rows N
and the number of columns M
( 1 <= N ;, M <= 100 ). The following N
lines contain matrix rows, each – by M
natural numbers ranging from 0 to 255, separated by spaces.
Output
The program should display in the first line the average brightness value for the given image with an accuracy of 4 decimal places. The following N
lines display the constructed matrix corresponding to the black and white image.
Examples
# |
Input |
Output |
1 |
4 4
12 14 67 45
32 87 45 63
69 45 14 11
40 12 35 15
|
37.8750
0 0 255 255
0 255 255 255
255 255 0 0
255 0 0 0
|