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"]
  • 1
    $\begingroup$ Why don't you use ImageConvolve? It's built for convolving images. $\endgroup$ – bill s Jan 3 '14 at 1:37
  • $\begingroup$ @VitaliyKaurov I use standard "Lena" $\endgroup$ – zhangwfjh Jan 3 '14 at 1:37
  • $\begingroup$ @bills I wanna implement the function on my own before I use it. That helps me understand better. $\endgroup$ – zhangwfjh Jan 3 '14 at 1:39
  • $\begingroup$ @bills And I tried, but it says I can't convolve with a complex matrix. $\endgroup$ – zhangwfjh Jan 3 '14 at 1:40
  • $\begingroup$ 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. $\endgroup$ – 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

enter image description here

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

enter image description here

| improve this answer | |
  • $\begingroup$ Oh, Thank you. I will check. Sorry to say that. My "Lena" is gray. $\endgroup$ – zhangwfjh Jan 3 '14 at 2:28
  • $\begingroup$ 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. $\endgroup$ – zhangwfjh Jan 3 '14 at 2:34
  • $\begingroup$ @zhangwfjh Just replace top line with img = ColorConvert[Import["ExampleData/lena.tif"], "Grayscale"]; and it will work. $\endgroup$ – Vitaliy Kaurov Jan 3 '14 at 2:41
  • $\begingroup$ 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. $\endgroup$ – zhangwfjh Jan 3 '14 at 2:47
  • $\begingroup$ 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"] $\endgroup$ – Vitaliy Kaurov Jan 3 '14 at 2:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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