-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFiltersScript.m
More file actions
76 lines (63 loc) · 3.34 KB
/
FiltersScript.m
File metadata and controls
76 lines (63 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
clear all;
close all;
clc;
% ************************************************************************
% Kris Cote
% BEE 515
% Digital Image Processing Applications
%
% Generate various versions of img by applying high and low pass spatial
% and frequency domain filters.
% ************************************************************************
img=checkerboard(20); % generate checkerboard
% test image
[m,n]=size(img); % get size of image
figure(1)
imshow(img,[]) % show original test image
title('Original')
% *************************************************************************
% ************************** SPATIAL DOMAIN *****************************
kmean=1/9*[1 1 1; 1 1 1; 1 1 1]; % mean blur filter kernel
klaplace=[0 -1 0; -1 4 -1; 0 -1 0]; % Laplacian filter kernel
% ******************** LOWPASS SPATIAL DOMAIN ***************************
X=conv2(img,kmean); % convolve test img with
% 3x3 mean filter kernel
figure(2)
imshow(X,[]) % show mean filtered img
title('3 \times 3 Mean Blur')
% ******************** HIGHPASS SPATIAL DOMAIN **************************
X=conv2(img,klaplace); % convolve test img with
% 3x3 Laplacian kernel
figure(3)
imshow(X,[]) % show Laplacian filtered
title('Laplacian Edge Detection')
% *************************************************************************
% ************************** FOURIER DOMAIN *****************************
pad=paddedsize([m,n]); % get padding size
imgp=padarray(img,[pad(1),pad(2)],'both'); % set pad before & after
[p,q]=size(imgp); % get size of padded img
fftpad=fft2(imgp); % Fourier transform
F=fftshift(fftpad); % shift low freq to middle
Hlp=fftshift(lpfilter('btw',p,q,60)); % get butterworth filter
Hhp=1-Hlp; % get highpass
figure(4)
imshow(log(1+abs(F)),[]) % show frequency domain
title('FFT Representation') % represntation of test img
% ******************** LOWPASS FOURIER DOMAIN ***************************
LPimg=abs(ifft2(F.*Hlp)); % apply filter and IFFT
figure(5)
subplot(2,1,1)
imshow(Hlp,[]) % show the filter
title('Lowpass Butterworth')
subplot(2,1,2) % show result cropped
imshow(LPimg(round((p-n)/2):round(n+(p-n)/2),round((q-m)/2):round(m+(q-m)/2)),[])
title('FFT Lowpass Filtered')
% ******************** HIGHPASS FOURIER DOMAIN **************************
HPimg=abs(ifft2(F.*Hhp)); % apply filter and IFFT
figure(6)
subplot(2,1,1)
imshow(Hhp,[]) % show the filter
title('Highpass Butterworth')
subplot(2,1,2) % show result cropped
imshow(HPimg(round((p-n)/2):round(n+(p-n)/2),round((q-m)/2):round(m+(q-m)/2)),[])
title('FFT Highpass Filtered')