Input into your program a black and white image. (png, jpg, etc)
Convert the image to a 2D matrix of pixels, where each index is the grayscale value of the image.
Take each index of the matrix and average the 8 pixels around it. Then replace that index with the average.
For example if you had:
120 80 60 20 10 30 40 100 05
If you were finding the average for 10, the result would be
56.875, which is
Round to up to the nearest integer (57) and replace the index. The result of this iteration would be
120 80 60 20 57 30 40 100 05
If you are finding the average for a pixel on an edge then only take values that are valid. In the example above if you were finding the average for
20 You would only consider
120, 80, 57, 100, and 40 which is
79.4 rounded to
You may start at any index of the graph but it must be in order. For example you could do
, , ... [n], then , ,... [n]
Once the averaging is complete, convert the matrix back into a new image.
Display the new image as the output of the program. (Or save it and add it in your solution). The result of your code should be a blurry looking image but much smoother than the original.
Example Input two
Example Output two
Please provide your code and start and end image results.
1Q. If one of the 8 neighbors has already been changed, should the average be calculated based on this new value, or based on the original values? That is, does the order of calculation affect the end result?
1A Yes, You should change each index with new values from any potential indices done before. That is why you need to go left-right, top-bottom etc. In order.
2Q. Could you clarify what is meant by "must be in order"? Does this mean that only raster order/reading order is acceptable? Or does it mean that the order must be the same each time the code is run? Would a spiral be valid? Or a shuffled order that is always the same?
2A. You should go left to right, right to left, top to bottom, or bottom to top. I.E. Do all of the 0th row, do all of the 1st row,... do all of the nth row