Given an image, either in 24-bit color or in 24-bit grayscale format, implement an image blur effect by randomly moving pixels off from their original positions as a method with the header below:
public static BufferedImage blur(BufferedImage src, int offset)
where src is the object reference of an input image and offset is the amount of circular random movement off the original pixel position. The return value of this method is an object reference of the resulting image.
This image blur effect can be visualized above. Image (1) is the original image. Image (2) is the result after applying the effect with offset 10. Image (3) is the result obtained with offset 20. Image (4) is the result obtained with offset 30.
The idea of the algorithm to achieve this effect is given below:
For each pixel (xnew, ynew) in the resulting image, let
• offsetX = random integer (in range between 0 and offset, inclusive) – offset /2
• offsetY = random integer (in range between 0 and offset, inclusive) – offset / 2
• x = xnew + offsetX
• y = ynew + offsetY
ResultImg(xnew,ynew) = OriginalImg(x, y)
That is to assign the color value of pixel (xnew,ynew) in the new image to that of the pixel (x,y) in the original image.