Re: 2dFFT & image processing
- To: mathgroup at smc.vnet.net
- Subject: [mg101573] Re: 2dFFT & image processing
- From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
- Date: Fri, 10 Jul 2009 06:46:59 -0400 (EDT)
- References: <h340gc$g8m$1@smc.vnet.net>
Hi Allesandro, Your problem lies in the assumption that the low frequency components are in the middle of the Fourier output. In fact, that's the spot with the highest frequencies, so cutting them away blurs your picture. Also, you seem to forget that you have to do an InverseFourier to get back to the picture domain. Check these lines of code: (* Import an example image*) pic = ImageData[ ImageCrop[ExampleData[{"TestImage", "TruckAndAPC"}], {500, 500}]]; (* Show it *) Image[pic] (* Fourier transform *) picf = Fourier[pic]; (* Check to see that inverse Fourier brings back the picture *) Image[Abs[InverseFourier[picf]]] (* Same for this version where amplitude and phase components are used *) Image[Abs[InverseFourier[Abs[picf] Exp[I Arg[picf]]]]] (* Filter LOW frequency components; DC component in the corners is retained *) k = Table[If[x^2 + y^2 < 320^2, 1, 0], {x, -249, 250}, {y, -249, 250}]; k[[1, 1]] = k[[1, -1]] = k[[-1, -1]] = k[[-1, 1]] = 1; Image[Abs[InverseFourier[k Abs[picf] Exp[I Arg[picf]]]]] (* Filter HIGH frequency components; DC component in the corners is retained *) k = Table[If[x^2 + y^2 < 320^2, 0, 1], {x, -249, 250}, {y, -249, 250}]; k[[1, 1]] = k[[1, -1]] = k[[-1, -1]] = k[[-1, 1]] = 1; Image[Abs[InverseFourier[k Abs[picf] Exp[I Arg[picf]]]]] Cheers -- Sjoerd On Jul 9, 7:51 am, "alexxx.ma... at gmail.com" <alexxx.ma... at gmail.com> wrote: > hi everybody, > I need to perform a high-pass filter on some images. > > I know I can get a high pass filter doing a convolution of the image > with a predefined kernel, but for various reasons (and my learning > too) I wanted to follow the sequence: > 1) fft > 2) cut away central region (with a smooth edge) > 3) fft again > > but, due to my ignorance, I'm unable to accomplish the process: > > given the image in a, I put: > > f = Fourier[a[[1]]]; > af = Abs@f; > Dimensions[f] > {500,500} > > and I can check the fft with Graphics[Raster[255*af/Max[af]]] > > I then create the "hole" and apply it to the fft and invert again: > > k = Table[1 - Exp[-(x^2 + y^2)/s], {x, -249, 250}, {y, -249, 250}] /. > s -> 1000.; > holed = af*k; > fholed = Abs[Fourier[holed]]; > > since the reconstructed image Graphics[Raster[255*fholed/Max[fholed]]] > is strongly fuzzed, whichever value I choose for the parameter s > above, I wanted to ask you if I completely misunderstood the process! > > thank you, > > alessandro