Re: 2-D Butterworth lowpass filter?
- To: mathgroup at smc.vnet.net
- Subject: [mg113845] Re: 2-D Butterworth lowpass filter?
- From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
- Date: Mon, 15 Nov 2010 05:51:36 -0500 (EST)
- References: <ibl9du$b6c$1@smc.vnet.net>
If you're on a PC replace the / in the file name with a \\. Or use ToFileName[] for universal access like in: Import["http://www.imageprocessingplace.com/downloads_V3/dip3e_\ downloads/dip3e_book_images/DIP3E_CH04_Original_Images.zip", ToFileName["DIP3E_Original_Images_CH04", "Fig0445(a)(characters_test_pattern).tif"]] Cheers -- Sjoerd On Nov 13, 6:58 am, Patrick Scheibe <psche... at trm.uni-leipzig.de> 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. > > 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