Last night you partied a little too hard. Now there’s a black and white photo of you that’s about to go viral! You can’t let this ruin your reputation, so you want to apply the box blur algorithm to the photo to hide its content.
The pixels in the input image are represented as integers. The algorithm distorts the input image in the following way: Every pixel x in the output image has a value equal to the average value of the pixel values from the 3 × 3 square that has its center at x, including x itself. All the pixels on the border of x are then removed.
Return the blurred image as an integer, with the fractions rounded down.
제출 코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import numpy as np
defboxBlur(image): Row = len(image) Col = len(image[0])
BlurSumSet = np.zeros((Row-2,Col-2))
for i in range(1, Row-1, 1): for j in range(1, Col-1, 1): BlurSum = int((image[i-1][j-1] + image[i-1][j] + image[i-1][j+1] + image[i][j-1] + image[i][j] + image[i][j+1] + image[i+1][j-1] + image[i+1][j] + image[i+1][j+1])/9) BlurSumSet[i-1][j-1] = BlurSum