# Image convolution, motion blur

I define my degradation function as $$H(x,y;a,b,t)=\frac{T}{z}\sin z~e^{-jz}$$ where $$z=\pi(ax+by)$$ So I write

H[a_, b_, T_] :=
Function[{x, y}, z = Pi*(a*x + b*y); If[z == 0, T, T*N[Sin[z]*Exp[-I*z]/z]]];


But when I convolve it with image

Image[Abs[InverseFourier[Fourier[img]*Array[H[a, b, T], {row, col}]]], "Real"]


The blurred image is almost white. What's wrong with my program?

### Edit

Here is my runnable program

img = Import["Lena.tif", "Data"];
{row, col} = Dimensions[img];
H[a_, b_, T_] := Function[{x, y}, z = Pi*(a*x+b*y); T*N[Sinc[z]*Exp[-I*z]]];
filter = Array[H[0.1, 0.1, 1], {row, col}];
Image[Abs[InverseFourier[Fourier[img]*filter]], "Real"]

-
Why don't you use ImageConvolve? It's built for convolving images. – bill s Jan 3 '14 at 1:37
@VitaliyKaurov I use standard "Lena" – zhangwfjh Jan 3 '14 at 1:37
@bills I wanna implement the function on my own before I use it. That helps me understand better. – zhangwfjh Jan 3 '14 at 1:39
@bills And I tried, but it says I can't convolve with a complex matrix. – zhangwfjh Jan 3 '14 at 1:40
Well then you are doing it the hard way. You are multiplying a sinc in the frequency domain by the FFT of the image. This is the same as convolving with a rectangle in the spatial domain. Why not do actual convolution? If you want motion blur, the first example in the ImageConvolve is the way to go. – bill s Jan 3 '14 at 1:41

You have to go line by line to see your errors. You have to do this for each RGB channel separately.

img = Import["ExampleData/lena.tif"];
data = ImageData /@ ColorSeparate[img];
{row, col} = Dimensions[data[[1]]];

H[a_, b_, T_] := Function[{x, y}, z = Pi*(a*x + b*y); T*N[Sinc[z]*Exp[-I*z]]]

filter = Array[H[0.1, 0.1, 1], {row, col}];
filter // Abs // MatrixPlot


ColorCombine[Image[Abs[InverseFourier[Fourier[#]*filter]], "Real"] & /@ data]


-
Oh, Thank you. I will check. Sorry to say that. My "Lena" is gray. – zhangwfjh Jan 3 '14 at 2:28
I'm sorry. I can't see the difference except the color part. But when I run it on a gray-level "Lena", I always obtain white. – zhangwfjh Jan 3 '14 at 2:34
@zhangwfjh Just replace top line with img = ColorConvert[Import["ExampleData/lena.tif"], "Grayscale"]; and it will work. – Vitaliy Kaurov Jan 3 '14 at 2:41
If I understand right of your comment, you mean the method doesn't work for my "Lena" because it has only one channel? My "lena" data has only two dimensions with size 256*256. – zhangwfjh Jan 3 '14 at 2:47
I do not have your Lena, they way you import it fails for me. This is why I gave you a line which makes a gray Lena. Just make replace 1st line with it and code now will work with gray image. img = ColorConvert[Import["ExampleData/lena.tif"], "Grayscale"] – Vitaliy Kaurov Jan 3 '14 at 2:54