Re: 2-D Fourier Transform?
- To: mathgroup at smc.vnet.net
- Subject: [mg113766] Re: 2-D Fourier Transform?
- From: "Nasser M. Abbasi" <nma at 12000.org>
- Date: Thu, 11 Nov 2010 06:10:14 -0500 (EST)
- References: <ibdvnp$8tk$1@smc.vnet.net> <4CDAD964.8030500@12000.org>
- Reply-to: nma at 12000.org
On 11/10/2010 9:41 AM, Nasser M. Abbasi wrote:
>
> ------ 2D spectrum of image ------------------------------
> img=Import["ExampleData/lena.tif"];
> ImageDimensions[img] (*look at image*)
>
> ImageChannels[img] (*see how many channels*)
>
> data=ImageData[img]; (*get data*)
> {nRow,nCol,nChannel}=Dimensions[data]
>
> Map[Image[data[[All,All,#]]]&,Range[1,nChannel]](*look at each channel*)
>
> d=data[[All,All,2]]; (*get channel 2*)
> Image[d,ImageSize->400]
>
> (*center Image first*)
> indx=Flatten[Outer[List,Range[1,nRow],Range[1,nCol]],1];
> Map[(d[[ #[[1]],#[[2]] ]]=(-1)^(#[[1]]+#[[2]])*d[[#[[1]],#[[2]] ]])&,indx];
>
> (*make FFT and look at spectrum and phase*)
> fw= Fourier[d,FourierParameters->{1,1}];
>
> fudgeFactor=100; (*adjust for better viewing as needed*)
>
> ArrayPlot[Abs@(fudgeFactor * Log[1+fw]),PlotLabel->"Magnitude spectrum",ImageSize->400]
> ArrayPlot[Arg[fw],PlotLabel->"Phase spectrum",ImageSize->400]
> -----------------------------------------
>
> see my howto note #95
> http://12000.org/my_notes/mma_matlab_control/KERNEL/e95/mma/index.htm
>
> --Nasser
Opps, In the above, I took the Abs of the FFT outside the log.
Instead of
ArrayPlot[Abs@(fudgeFactor * Log[1+fw]),PlotLabel->"Magnitude spectrum",ImageSize->400]
It should be
ArrayPlot[(fudgeFactor * Log[1+Abs@fw]),PlotLabel->"Magnitude spectrum",ImageSize->400]
The fudgefactor is something one changes to get a clearer picture of the spectrum. There is no magic formula for it that I know of.
--Nasser