MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: 2-D Butterworth lowpass filter?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113841] Re: 2-D Butterworth lowpass filter?
  • From: Matthias Odisio <matthias at wolfram.com>
  • Date: Mon, 15 Nov 2010 05:50:50 -0500 (EST)

Hello,

On 11/12/10 11:58 PM, Patrick Scheibe wrote:
> Hi,
> 
> using Gonzalez/Woods again (page 273, 3rd ed.) the transfer function is
> given by
> 
> d[u_, v_, p_, q_] := Sqrt[(u - p/2)^2 + (v - q/2)^2]
> h[u_, v_, p_, q_, n_, d0_] := 1/(1 + (d[u, v, p, q]/d0)^(2 n));
> 
> I'm using a compiled version of it
> 
> hc = Compile[{u, v, p, q, n, d0}, 
>    1/(1 + (Sqrt[(u - p/2)^2 + (v - q/2)^2]/d0)^(2 n))];
> hcompiled[u_?NumericQ, v_?NumericQ, p_?NumericQ, q_?NumericQ, 
>   n_?NumericQ, d0_?NumericQ] := hc[u, v, p, q, n, d0]
> 
> With this the plots on page 274 are
> 
> Plot3D[hcompiled[u, v, 0, 0, 3, 3], {u, -15, 15}, {v, -15, 15}, 
>  PlotRange -> All, PlotPoints -> 30]
> Plot[Evaluate[h[u, 0, 0, 0, #, 5] & /@ Range[4]], {u, 0, 15}, 
>  PlotStyle -> {Thick}, PlotRange -> All]
> 
> And now (taking the CenteredFourier from Matthias)
> 
> CenteredFourier[img_] := 
>   Module[{data = ImageData[img], dim}, dim = Dimensions[data];
>    Fourier[data*(-1)^Table[i + j, {i, First[dim]}, {j, Last[dim]}]]];
> 
> CenteredInverseFourier[F_] := Module[{dim}, dim = Dimensions[F];
>    Image[Re[
>      InverseFourier[F]*(-1)^
>        Table[i + j, {i, First[dim]}, {j, Last[dim]}]]]];
> 
> ButterWorthFilter[img_, n_, d0_] := Module[{nx, ny, bw},
>   {nx, ny} = ImageDimensions[img];
>   bw = Table[hcompiled[u, v, nx, ny, n, d0], {v, 1, ny}, {u, 1, nx}];
>   CenteredInverseFourier[bw*CenteredFourier[img]]
>   ]
> 
> 
> And to test it you could try to create figure 4.45 of the book (please
> check that there are no unwanted newlines in the link-strings when you
> copy it to the notebook!)
> 
> img = Import[
>    "http://www.imageprocessingplace.com/downloads_V3/dip3e_downloads/\
> dip3e_book_images/DIP3E_CH04_Original_Images.zip", 
>    "DIP3E_Original_Images_CH04/Fig0445(a)(characters_test_pattern).\
> tif"];
> GraphicsGrid@
>  Partition[
>   Flatten[{img, 
>     ButterWorthFilter[img, 2, #] & /@ {10, 30, 60, 160, 460}}], 2]
> 
> 
> I must admit that the images in the book are more blurred with the same
> setting. 
> 

Everything happens as if the figure 4.45 in the book was produced by
filtering a padded version of the image to prevent "incorrect" result
due to the underlying cyclic periodicity, and then cropping the
result of the filtering back to the original dimensions. Since the
filters' parameters seem to stay the same but the image dimensions
seem to double, the blurring is stronger.

This is visually closer:

ButterWorthFilterPadded[img_, n_, d0_] := Module[
  {nx, ny, bw, px, py, imgpadded},
  {nx, ny} = ImageDimensions[img];
  {px, py} = 2*{nx, ny};
  imgpadded = ImageCrop[img, {px, py}, {Left, Top}];
  bw = Table[hcompiled[u, v, px, py, n, d0], {v, 1, py}, {u, 1, px}];
  ImageTake[#, {1, ny}, {1, nx}] &@
   CenteredInverseFourier[bw*CenteredFourier[imgpadded]]]

And producing this grid of graphics take some more time now...

Matthias Odisio
Wolfram Research

> Cheers
> Patrick
> 
> On Fri, 2010-11-12 at 05:28 -0500, hadi motamedi wrote:
>> Dear All
>> Can you please let me know how can I design and apply 2-D Butterworth
>> lowpass filter to my image in Mathematica? Please be informed that I
>> can obtain its Fourier transform but I need to design and apply
>> lowpass Butterworth filtering to it.
>> Thank you
>>
> 
> 


  • Prev by Date: Re: 2-D Butterworth lowpass filter?
  • Next by Date: band pass or notch filtering?
  • Previous by thread: Re: 2-D Butterworth lowpass filter?
  • Next by thread: Constructing matrix out of submatrices