forked from marcusstenbeck/tnm034-qr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedge_detection.m
More file actions
65 lines (48 loc) · 1.56 KB
/
edge_detection.m
File metadata and controls
65 lines (48 loc) · 1.56 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
function imout = edge_detection(imin)
% DESCRIPTION
% A function that detects edges in an image and returns the result as a
% new image. Based on Gaussian high-pass filter from the book Digital
% Image Processing by Gonzalez & Woods.
% PARAMETERS
% IN:
% imin: The input image of the captured QR-code.
% OUT:
% imout: The resulting image containing the edges from the original
% image.
% Get width and height of image
[height, width] = size(imin);
% Transform image
im_fft = fft2(imin);
% Shift the transformed image
im_fft_shifted = fftshift(im_fft);
% DELETABLE: View fourier spectra
%figure(1)
%imshow(log(1+abs(im_fft_shifted)), []);
% WIP: Create a high-pass filter
[x,y] = meshgrid(-width/2:1:(width/2-1), -height/2:1:(height/2-1));
D = (x.^2 + y.^2).^(1/2);
% Set threshold
% TODO: Base threshold on image size. Larger thresholds better for larger
% images.
D0 = 150;
% Create ideal high-pass
ideal_hpf = D;
ideal_hpf(ideal_hpf<D0) = 0;
ideal_hpf(ideal_hpf>=D0) = 1;
% Create Gaussian high-pass filter
gaussian_hpf = 1 - exp(-(D.^2)/(2.*D0.^2));
% Choose high-pass filter type: gaussian_hpf OR ideal_hpf
hpf = gaussian_hpf;
% Apply the high-pass filter
im_hpf = im_fft_shifted .* hpf;
% DELETABLE: View high-pass filtered fourier spectra
%figure(2)
%imshow(log(1+abs(im_hpf)), []);
% Copy the last variable which will be inverse transformed
im_to_ifft = im_hpf;
% Shift back the image
im_to_ifft = fftshift(im_to_ifft);
% Inverse transform image
im_ifft = ifft2(im_to_ifft);
% Do some magic to be able to show the image again
imout = real(im_ifft);