[R] 2D fft DC shift

Bill Simpson wsi at gcal.ac.uk
Wed Sep 26 11:48:18 CEST 2001

Here is an example that
--creates an image of a bright square on a dark background
--centres the spectrum using Gonzalez and Wintz method
--creates image plots of uncentred and centred amplitude spectra

#example of 2D amplitude spectrum

# sample image:
w<-5  #width of central square
xn<- 128;  yn<- 128
im<- matrix(0,nrow=yn,ncol=xn)  
xc<-floor(xn/2)+1;  yc<- floor(yn/2)+1  # centers of the image
im[(-m:m)+xc,(-m:m)+yc]<- 1

im2<- matrix(0,nrow=yn,ncol=xn) 
#centres spectrum: Gonzalez & Wintz (1977) Digital Image Processing p.53
im2<-im * (-1)^(row(im) + col(im))

image(im); title('im=Original image')
image(Mod(fftim)); title('Mod(fft(im))')
image(Mod(fftim2)) ; title('Centred Mod(fft(im))')


r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list