Question: I need help implementing the following function: def blur(image,radius=5): Returns True after bluring the image. To blur an image you loop over all pixels.
I need help implementing the following function:
def blur(image,radius=5): """ Returns True after bluring the image. To blur an image you loop over all pixels. For each pixel, you average all colors (all 4 values including alpha) in a box centered at the pixel with the given radius. For example, suppose you are blurring the pixel at position (4,7) with a radius 2 blur. Then you will average the pixels at positions (2,5), (2,6), (2,7), (2,8), (2,9), (3,5), (3,6), (3,7), (3,8), (3,9), (4,5), (4,6), (4,7), (4,8), (4,9), (5,5), (5,6), (5,7), (5,8), (5,9), (6,5), (6,6), (6,7), (6,8), and (6,9). You then assign that average value to the pixel. If the box goes outside of the image bounds, go to the edge of the image. So if you are blurring the pixel at position (0,1) with a radius 2, you average the pixels at positions (0,0), (0,1), (0,2), (0,3), (1,0), (1,1), (1,2), (1,3), (2,0), (2,1), (2,2), and (2,3). This calculation MUST be done in a COPY. Otherwise, you are using the blurred value in future pixel computations (e.g. when you try to blur the pixel to the right of it). All averages must be computed from the original image. Use the steps from transpose() to modify the image. WARNING: This function is very slow (Adobe's programs use much more complicated algorithms and are not written in Python). Blurring 'Walker.png' with a radius of 30 can take up to 10 minutes. Parameter image: The image to blur Precondition: image is a 2d table of RGB objects Parameter radius: The blur radius Precondition: radius is an int > 0 """ # We recommend enforcing the precondition for radius # Change this to return True when the function is implemented return False
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
