% fourier - display fourier transform of image % % Usage: % [IM,IMv,IMh] = fourier(im,plotRef) % % Magnitude displayed using Grayscale % Phase displayed using Hue % % Arguments: % im - image matrix or image file name(as 'string') % (RGB image will be transformed into grayscale before fft) % plotRef - optional phase color plot using phasecolor.m if '1' % % Output: % IM - fft2 of image % IMv - fft of image vertically % IMh - fft of image horizontally % % Example: % [IM,IMv,IMh] = fourier(image,1); % display fft of image with color ref % [IM,IMv,IMh] = fourier('image.jpg'); % display fft of file image.jpg % % Author: % Tzu Yen Wong % wongt AT csse DOT uwa DOT edu DOT au % Department of Computer Science & Software Engineering % The University of Western Australia % % Oct 2003 % June 2004 change email address to fight SPAM!!! %1234567890123456789012345678901234567890123456789012345678901234567890123456789 function [IM,IMv,IMh] = fourier(im,plotRef) if ischar(im), im=imread(im); end if ndims(im)==3, im=rgb2gray(im); end [r,c] = size(im); downsize = sqrt(40000/(r*c)) if downsize<1, im = imresize(im,downsize,'bicubic'); else im = imresize(im,downsize,'nearest'); end IM = fftshift(fft2(im)); imMag = abs(IM)+eps; imPh = angle(IM)*180/pi; IMv = fftshift(fft(im,[],1),1); % 1D fft, vertically imMagv = abs(IMv)+eps; imPhv = angle(IMv)*180/pi; IMh = fftshift(fft(im,[],2),2); % 1D fft, horizontally imMagh = abs(IMh)+eps; imPhh = angle(IMh)*180/pi; if nargin>1 if plotRef == 1, phasecolor(1); % '1' - range is [-180,180] end end figNo1=figure; subplot(2,3,1); imshow(im), colormap(gray) title('Original image'); axis on axis image subplot(2,3,6); imagesc(log(imMag)) title('Log of Magnitude'); axis image subplot(2,3,5); imagesc(log(imMagv)) title('Log of Magnitude Vertical'); axis image subplot(2,3,2); imagesc(log(imMagh)) title('Log of Magnitude Horizontal'); axis image subplot(2,3,4); imagesc(imMagv) title('Magnitude Vertical'); axis image subplot(2,3,3); imagesc(imMagh) title('Magnitude Horizontal'); axis image figNo2=figure; subplot(2,2,1); imshow(im), colormap(hsv) title('Original image'); axis on axis image subplot(2,2,4); imagesc(imPh) title('Phase'); axis image subplot(2,2,3); imagesc(imPhv) title('Phase Vertical'); axis image subplot(2,2,2); imagesc(imPhh) title('Phase Horizontal'); axis image pixval on warning off truesize(figNo1) truesize(figNo2) warning on