lowpass grayscale HOWTO: m-file s-by-s decomposition m-file: i2.m Main Idea: transform figure into spectra (2D Fast Fourier Transform), apply freq-domain filter and transform back to "time" or space domain (2D inverse FFT) clear all % input filter parametrs, order n, diameter Do (cutoff frequency): n = 80; Do = 20; % load image and convert RGB into grayscale
imrgb = imread('pattern2_cropped.png'); %read image: % get size of image, height, width NOTE: image must be the same in w x h (square for fft!) [im_height,im_width] = size(im); % euclidean distance matrix (spec. matrix for cylincric-symetrical filter), such colorized images: use colormap jet;
[U,V] = rc2uv(im_height,im_width); % generate butterworth filter from linear freq. cone (figure above) H = 1./(1+(D./Do).^(2*n)); %spectrum of image, and freq shift (miniumum freq. was on edges, after shift freq. is in the center of matrix) IM = fftshift(fft2(im)); %power spectrum of image (10log(abs(IM)^2) %filter image with lowpass butterw (matrix dot product), harmonics ai*filter_gain@ai IMF=IM.*H; %power spectrum of filtered image %image reconstruction from spectra IMF (back spectra shift and inverse fft) imf = ifft2(fftshift(IMF)); %filtered image: %print output:
figure(1); clf; %print input figure
imshow(im); %print output figure
subplot(1,2,2); %print butter filter
figure(2); |