I have Java code that takes a convolution matrix (just a 2D double[][]
) and applies it to an image. I'm trying to figure out how to create a matrix that will give a motion blur, given an angle (in degrees) and a magnitude for the blur.
An example matrix for a blur with magnitude = 1 (the middle pixel is blurred by one pixel in each direction), 45 degree motion blur is:
0 0 1/3
0 1/3 0
1/3 0 0
The magnitude determines the size of the matrix (size = 2*magnitude + 1) and a single line of cells is non-zero in the direction of motion.
What I'm having trouble with is the math/code necessary to figure out which cells to have non-zero in the matrix given the angle.
Pseudo (or actual) code would be immensely helpful!