--- Saving session to: ECE480.PH437_24-Jan-2002.txt --- Processed startup.m --- ; ; ; ; ; ; ; day21c filt = lpideal f1 = 1 Preprocessing: f(x,y)=f(x,y)-mean(f)... Preprocessing: compute X(u,v)... Filtering: define H(u,v)... Filtering: compute G(u,v)=F(u,v)H(u,v)... Postprocessing: compute g(x,y)... Postprocessing: g(x,y)=g(x,y)+mean(f)... Press a key to continue: Error in ==> c:\personal\class\2001-02\winter\ece480\matlab\fft2demo.m On line 101 ==> pause Error in ==> c:\personal\class\2001-02\winter\ece480\matlab\day21c.m On line 8 ==> fft2demo day21a filt = lpideal2 f1 = 1 Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: filt = lpideal f1 = 1 Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: filt = lp1 f1 = 1 Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: filt = bwlp1 f1 = 1 Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: filt = lpgaussian f1 = 1 Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: filt = lpgaussian2 f1 = 1 Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: hp=1 hp = 1 day21a filt = lpideal2 f1 = 1 Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: filt = lpideal f1 = 1 Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: filt = lp1 f1 = 1 Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: filt = bwlp1 f1 = 1 Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: filt = lpgaussian f1 = 1 Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: Error in ==> c:\personal\class\2001-02\winter\ece480\matlab\fft1demo.m On line 120 ==> pause Error in ==> c:\personal\class\2001-02\winter\ece480\matlab\day21a.m On line 19 ==> fft1demo day21c filt = lpideal f1 = 1 Preprocessing: f(x,y)=f(x,y)-mean(f)... Preprocessing: compute X(u,v)... Filtering: define H(u,v)... Filtering: compute G(u,v)=F(u,v)H(u,v)... Postprocessing: compute g(x,y)... Postprocessing: g(x,y)=g(x,y)+mean(f)... Press a key to continue: Press a key to continue: Press a key to continue: Press a key to continue: filt = lpgaussian f1 = 1 Preprocessing: f(x,y)=f(x,y)-mean(f)... Preprocessing: compute X(u,v)... Filtering: define H(u,v)... Filtering: compute G(u,v)=F(u,v)H(u,v)... Postprocessing: compute g(x,y)... Postprocessing: g(x,y)=g(x,y)+mean(f)... Press a key to continue: Press a key to continue: Press a key to continue: filt = lpgaussian2 f1 = 1 Preprocessing: f(x,y)=f(x,y)-mean(f)... Preprocessing: compute X(u,v)... Filtering: define H(u,v)... Filtering: compute G(u,v)=F(u,v)H(u,v)... Postprocessing: compute g(x,y)... Postprocessing: g(x,y)=g(x,y)+mean(f)... Press a key to continue: Press a key to continue: Press a key to continue: filt = hpgaussian f1 = 1 Preprocessing: f(x,y)=f(x,y)-mean(f)... Preprocessing: compute X(u,v)... Filtering: define H(u,v)... Filtering: compute G(u,v)=F(u,v)H(u,v)... Postprocessing: compute g(x,y)... Postprocessing: g(x,y)=g(x,y)+mean(f)... Press a key to continue: Press a key to continue: Press a key to continue: filt = bpgaussian f1 = 1 Preprocessing: f(x,y)=f(x,y)-mean(f)... Preprocessing: compute X(u,v)... Filtering: define H(u,v)... Filtering: compute G(u,v)=F(u,v)H(u,v)... Postprocessing: compute g(x,y)... Postprocessing: g(x,y)=g(x,y)+mean(f)... Press a key to continue: Press a key to continue: Press a key to continue: exit --- Saving session to: ECE480.PH437_24-Jan-2002.txt --- Processed startup.m --- ; ; ; ; ; ; ; type day21a % EE437 Intro to Image Processing, S96 % Day 21: 1-D FFT-based filtering demonstration % % Calling routine for fft1demo.m filt = 'lpideal2' fft1demo filt = 'lpideal' fft1demo filt = 'lp1' fft1demo filt = 'bwlp1' fft1demo filt = 'lpgaussian' fft1demo filt = 'lpgaussian2' fft1demo type day21c % EE437 Intro to Image Processing, S96 % Day 21: 2-D FFT-based filtering demonstration % % Calling routine for fft2demo.m d=[1 1 1 1 1 1]; filt = 'lpideal' fft2demo d=[0 1 1 1 1 1]; filt = 'lpgaussian' fft2demo d=[0 1 1 1 1 1]; filt = 'lpgaussian2' fft2demo d=[0 1 1 0 1 1]; filt = 'hpgaussian' fft2demo d=[0 1 1 0 1 1]; filt = 'bpgaussian' fft2demo type fft1demo % EE437 Intro to Image Processing, S96 % Day 21: 1-D FFT-based filtering demonstration % Create the figure window f1=figure(1) bigfig set(gca(f1),'Color',[0 0 0]) % Length of the data vectors n=256; % x: input signal (pulse) t=0:n-1; x=zeros(n,1); x(70:80)=ones(11,1)*1; x=x/sum(x); % u: frequency index u=[0:(n/2)-1, -(n/2):-1]; % r: radial distance from origin r=abs(u); % Optional: introduce a shift u0 for bandpass filter (default is zero) if ~exist('u0') u0 = 0; end % H: frequency-domain filter function if strcmp(filt,'hp1') H=r/(n/2); elseif strcmp(filt,'lpideal') H=((r-u0)/16)<1; elseif strcmp(filt,'lpideal2') H=((r-u0)/64)<1; elseif strcmp(filt,'lpgaussian') % Gaussian lowpass with corner at uc=40 H=exp( -log(2)*((r-u0)/40).^2 ); elseif strcmp(filt,'lpgaussian2') % Gaussian lowpass with corner at uc=4 H=exp( -log(2)*((r-u0)/4).^2 ); elseif strcmp(filt,'bwlp1') % 1st order Butterworth, with corner at uc=16 H=1./( 1 + ((r-u0)/16).^(2*1) ); elseif strcmp(filt,'lp1') H=r/(n/2); H=fftshift(H); else disp('Please specify a value for the "filt" variable.') return end % Optional: convert to highpass by doing 1-H if exist('hp') H = 1-H; end % X: frequency-domain version of input signal X=fft(x); % Y: filtered signal (frequency-domain) Y=X.*H'; % y: filtered signal (time domain) y=ifft(Y); % Axis ranges a=[-n/2 (n/2)-1 -0.2 1.2]; ta=[0 n-1 -0.05 0.15]; % time-domain plots % Data plots (time domain) plot(t,x,'y') axis(ta) set(gca(f1),'Color',[0 0 0]) bigtitle('Input signal (time domain)') disp('Press a key to continue:') xlabel('Time index, n'); ylabel('x(n)'); pause plot(-(n/2):(n/2)-1,fftshift(abs(X)),'y') axis(a) set(gca(f1),'Color',[0 0 0]) bigtitle('Input signal (frequency domain)') xlabel('Frequency index, u'); ylabel('|X(u)|'); disp('Press a key to continue:') pause plot(-(n/2):(n/2)-1,fftshift(H),'g') set(gca(f1),'Color',[0 0 0]) axis(a) bigtitle('Filter function') xlabel('Frequency index, u'); ylabel('H(u)'); disp('Press a key to continue:') pause plot(-(n/2):(n/2)-1,fftshift(abs(X)),'y',... -(n/2):(n/2)-1,fftshift(H),'g') set(gca(f1),'Color',[0 0 0]) axis(a) bigtitle('Input signal and filter function') xlabel('Frequency index, u'); disp('Press a key to continue:') pause plot(-(n/2):(n/2)-1,fftshift(abs(Y)),'y') set(gca(f1),'Color',[0 0 0]) axis(a) bigtitle('Filtered signal (frequency domain)') xlabel('Frequency index, u'); ylabel('|Y(u)|'); disp('Press a key to continue:') pause plot(t,real(y),'y', t,x,'y:') set(gca(f1),'Color',[0 0 0]) axis(ta) bigtitle('Filtered signal (time domain)') xlabel('Time index, n'); ylabel('Re{y(n)}'); disp('Press a key to continue:') pause %plot(-(n/2):(n/2)-1,fftshift(H),'g') %disp('Press a key to continue:') %plot(t,x,'y', t,real(y),'g') %axis([0 n-1 min([x y]) max([x y])]) %plot(fftshift(abs(fft(x)))) type fft2demo % EE437 Intro to Image Processing, S96 % Day 16: 2-D FFT-based filtering demonstration % % Usage: % 1. Set 'filt' variable to select filter type % 2. Set 'd' vector to select which items to display % d=[x x x x x x], x=0 or 1 % | | | | | | % | | | | | row profiles % | | | | image with row profile % | | | flip between processed and input images % | | processed image % | filter function % frequency-domain version of input image % % typical values: % d=[1 1 1 1 1 1] <- first time % d=[0 1 1 1 0 1] <- emphasizing quantitative % d=[0 1 1 1 0 0] <- emphasize image comparison % updated Winter 2001-02 % Load the image data % Note: use square image, dimension is power of 2 x=double(imread('camera.png')); % Show the input image while calculations are performed %if exist('f1') delete(f1); clear('f1'); end f1=figure(1) bigfig %image(x); colormap(gray(256)); axis('image') imshow(uint8(x),256,'n'); bigtitle('f(x,y): Input image (spatial domain)') xlabel('x'); ylabel('y'); drawnow % Dimension of input image n=size(x,1); % Subtract the image mean, and save the mean for later use disp('Preprocessing: f(x,y)=f(x,y)-mean(f)...') xmean=mean(x(:)); xm=x-xmean; % Convert image to frequency domain disp('Preprocessing: compute X(u,v)...') X=fft2(xm); X=fftshift(X); % uv-plane frequency index disp('Filtering: define H(u,v)...') [u v]=meshgrid(-(n/2):(n/2)-1, -(n/2):(n/2)-1); % radial distance from origin r=sqrt(u.^2 + v.^2); % H: frequency-domain filter function if strcmp(filt,'lpideal') H=r<40; elseif strcmp(filt,'hpideal') H=r>40; elseif strcmp(filt,'lpgaussian') H=exp(-(r.^2/2000)); elseif strcmp(filt,'lpgaussian2') H=exp(-(r.^2/500)); elseif strcmp(filt,'bpgaussian') H=exp(-((r-40).^2/100)); elseif strcmp(filt,'hpgaussian') H=1-exp(-(r.^2/2000)); else disp('Please specify a value for the "filt" variable.') return end % Y: filtered signal (frequency-domain) disp('Filtering: compute G(u,v)=F(u,v)H(u,v)...') Y=X.*H'; % y: filtered signal (time domain) disp('Postprocessing: compute g(x,y)...') Y=fftshift(Y); y=ifft2(Y); % Add mean value to output image disp('Postprocessing: g(x,y)=g(x,y)+mean(f)...') y=y+xmean; % Data display %if exist('f2') delete(f2); clear('f2'); end f2=figure(2); bigfig drawnow if d(1) colormap(gray(256)); imagesc(log(abs(X)+1e-6)); axis('image') bigtitle('F(u,v): Input image (frequency domain)') xlabel('u'); ylabel('v'); drawnow disp('Press a key to continue:') pause end %mesh(u(1:4:n,1:4:n),v(1:4:n,1:4:n),H(1:4:n,1:4:n)) %colormap('default') %bigtitle('H(u,v): Filter function') %xlabel('u'); ylabel('v'); %drawnow %disp('Press a key to continue:') %pause % %imagesc(H); colormap(gray); axis('image') %bigtitle('H(u,v): Filter function') %xlabel('u'); ylabel('v'); %drawnow %disp('Press a key to continue:') %pause if d(2) subplot(1,2,1) mesh(u(1:4:n,1:4:n),v(1:4:n,1:4:n),H(1:4:n,1:4:n)) colormap('default') bigtitle('H(u,v): Filter function') xlabel('u'); ylabel('v'); drawnow subplot(1,2,2) imagesc(H); axis('image') xlabel('u'); ylabel('v'); disp('Press a key to continue:') pause subplot(1,1,1) end %imagesc(log(Y+1e-6)); axis('image') %bigtitle('G(u,v): Output image (frequency domain)') %xlabel('u'); ylabel('v'); %drawnow %disp('Press a key to continue:') %pause if d(3) %image(real(y)); colormap(gray(256)); axis('image') imshow(uint8(real(y)),256,'n'); bigtitle('Real(g(x,y)): Output image (spatial domain)') xlabel('x'); ylabel('y'); disp('Press a key to continue:') pause end if d(4) % Flip display between input and output images %for i=1:4 figure(1); pause(2); figure(2); pause(2); end for i=1:4 figure(1); pause; figure(2); pause; end end if d(5) % Show row profile at row 80 image(x); colormap(gray(256)); axis('image') imshow(uint8(x),256,'n'); bigtitle('Row profile at line 80') xlabel('x'); ylabel('y'); drawnow line([0 255],[80 80]); disp('Press a key to continue:') pause end if d(6) subplot(2,1,1) plot(x(80,:)) axis([0 n-1 0 255]) bigtitle('Input image') xlabel('x'); ylabel('f(x,y=80)') subplot(2,1,2) plot(real(y(80,:))) axis([0 n-1 0 255]) bigtitle('Output image') xlabel('x'); ylabel('g(x,y=80)') pause end exit