Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


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"]
share|improve this question
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
up vote 4 down vote accepted

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

enter image description here

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

enter image description here

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.