-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab_05.m
77 lines (57 loc) · 1.75 KB
/
lab_05.m
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
77
clear variables;
img1 = imread('gull2.bmp');
[rows,cols] = size(img1);
dblImg = double(img1);
lpfilter = generateButterworthFilter(50, 2, rows, cols);
figure;
h = surf(lpfilter);
set(h, 'LineStyle', 'none');
ft1 = fft2(dblImg);
ft1 = fftshift(ft1);
magft1 = abs(ft1);
ft1Spectrum = log(1 + magft1);
img2 = uint8(rescale(ft1Spectrum,0,255));
ft2 = ft1 .* lpfilter;
magft2 = abs(ft2);
ft2Spectrum2 = log(1 + magft2);
img3 = uint8(rescale(ft2Spectrum2,0,255));
ft3 = ifftshift(ft2);
invft = ifft2(ft3);
img4 = uint8(rescale(abs(invft),0,255));
f1 = figure;
subplot(2,2,1), imshow(img1);
subplot(2,2,2), imshow(img2);
subplot(2,2,3), imshow(img3);
subplot(2,2,4), imshow(img4);
impixelinfo(f1);
function [noiseMat] = generateSinNoise(rows, cols, cycles, factor)
vals = linspace(-cycles*pi, cycles*pi, cols);
sinWave = sin(vals);
noiseMat = repmat(sinWave, rows, 1);
noiseMat = factor*noiseMat;
end
function [noiseMatrix] = generateVertLineNoise(spacing, width, value, rows, cols)
noiseMatrix = zeros(rows, cols);
for idx = 1:width
noiseMatrix(:, idx:spacing:end) = value;
end
end
function [noiseMatrix] = generateHoriLineNoise(spacing, width, value, rows, cols)
noiseMatrix = zeros(rows, cols);
for idx = 1:width
noiseMatrix(idx:spacing:end, :) = value;
end
end
function [filter] = generateIdealLPFilter(cutoff, rows, cols)
x = (1:rows) - (rows / 2);
y = (1:cols) - (cols / 2);
[X,Y] = meshgrid(x, y);
filter = double((X.*X + Y.*Y) < cutoff*cutoff);
end
function [filter] = generateButterworthFilter(cutoff, order, rows, cols)
x = (1:rows) - (rows / 2);
y = (1:cols) - (cols / 2);
[X,Y] = meshgrid(x, y);
temp = (sqrt(X.*X + Y.*Y)/cutoff) .^ (2*order);
filter = 1 ./ (1 + temp);
end