possible bug with -motion-blur in IM 6.4.0-10

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

possible bug with -motion-blur in IM 6.4.0-10

Post by fmw42 »

Hi,

For my testing of the FFT routines, I have been trying to deblur an image that has been blurred by motion blur. The definition of "ideal" motion blur in the spatial domain is a convolution with a 1D uniform weight filter. (See http://www.jhlabs.com/ip/blurring.html for interesting blurring java applet). Thus for a horizontal motion blur that is 15 pixels wide, that would be a kernel of "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1". Visually that would be a 15x1 white line, which if inserted into a black background would look as follows:
Image

I took the following image (white square in a black backround):
Image

and applied a motion blur to it in IM, ImageJ, Photoshop and GraphicConverter. Then I made the profile of the middle
row of the blurred image. As the filter has constant weight and the image is a constant white square in a black background, I would expect the profile to ramp LINEARLY from black to white on the left and right side. Here are my results:

Photoshop (motion blur filter)
Image
Image

ImageJ (1D convolution)
Image
Image

GraphicConverter (motion blur filter)
Image
Image

IM (-motion-blur)
Image
Image

It seems to me that Photoshop and ImageJ use a proper constant weight filter and GraphicConverter probably uses a gaussian weighted filter.

But I don't understand what IM is doing. I would have at least expected it to be symmetric.

Can someone check to see if this asymmetry is intended? What is the possibility that a "proper" motion blur can be implemented; or that a non-square convolution can be implemented, or both?


The issue that I see on the surface regarding IM convolution, would be to use some kind of row separator in the interface. For example a 3x3 uniform weight filter could be expressed as "1,1,1 1,1,1 1,1,1". Thus a space becomes the separator. Any other character could be used, if that is easier for you. I understand that the code underneath would likely need to be changed as well and may not be so trivial. But could this be added to the enhancements if it is not already.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug with -motion-blur in IM 6.4.0-10

Post by magick »

We have a patch in ImageMagick 6.4.0-11 Beta (available sometime tomorrow) to fix the problem you reported.

Non-square convolution currently requires a square convolution kernel with a coefficient of 0 for row/column elements that do not contribute to the results.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: possible bug with -motion-blur in IM 6.4.0-10

Post by fmw42 »

Thanks for the fix to motion blur. Will it give a linear (I hope) or gaussian profile to my test case?

With regard to the convolution, I understand that square filters is the current limitation, but padding with zeros is rather impractical for large 1D filters. I would have to build a 15x15 filter ( i.e. type 225 values). Not very practical (even though 210 values are the same).

Actually I just tried the following that helped make it easier to type:

filt15="\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
"
convert square31.png -convolve $filt15 square31_IM_filt15.png


Anyway, I just want to recommend that a non-square convolution be added to the "wish" list.

Thanks.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: possible bug with -motion-blur in IM 6.4.0-10

Post by magick »

The kernel is linear for motion blur.

We added a non-square kernel to the ImageMagick "wish list".
Post Reply