-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgammaEdge.m
133 lines (118 loc) · 4.18 KB
/
gammaEdge.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
function edge = gammaEdge(Image, deadpixel)
% The gammaEdge function takes af image as input in order to detect
% itsedges. This is done with a kernel.
%
% input: Image = the givin image one wish to perform the gamme operator on
% deadpixel = giving the values on the edges on the original image a
% value
% output: edge = gamme operated iamge.
%
% Example: gammaEdge(img, 'on');
% performs gamme on img. 'on' gives the operator a deadpixel value of 0.
%%authors: Kristian Sørensen, Eigil Lippert and Simon Lupemba
%
%%
%
% Handling variable input 'deadpixel'. If no input, it's interpreted as
% 'off' and set to zero (since assigning to 'off' doesn't work)
if nargin == 1
deadpixel = 0;
end
n=1; %size of kernel
dimensions = size(Image); %dimensions of input matrix.
edgeY = 0; %Empty array for mean values.
Yright = 0;
Yleft = 0;
edgeX = 0;
Xtop = 0;
Xbottom = 0;
%% Determins edges in Y-direction
for k = -n:n
%Horizontal displacements:
%moves element to the left, adds zeros on the left, if k is on the
%left of the center array (-n).
if k<0
Eh = padarray(Image(:, 1:dimensions(2)-abs(k)),[0 abs(k)], 'pre');
end
%moves element to the right, adds zeros on the right
if k>0
Eh = padarray(Image(:, 1+k:dimensions(2)),[0 k], 'post');
end
%when reaching the center element - do nothing.
if k ~= 0
for i = -n:n
%Vertical displacements:
%moves elements up, adds zeros above
if i < 0
Ev = padarray(Eh(1:dimensions(1)-abs(i),:),[abs(i) 0], 'pre');
end
%moves elements down, adds zeros below
if i > 0
Ev = padarray(Eh(1+i:dimensions(1),:),[i 0], 'post');
end
%when reaching the center element - do nothing.
if i == 0
Ev = Eh;
end
if k < 0
Yleft = Ev + Yleft;
end
if k > 0
Yright = Ev + Yright;
end
end
end
end
Yleft(Yleft<0.01)=0.01; % The low values are set to 0.01 så we don't divde by zero or anything near.
Yright(Yright<0.01)=0.01;
edgeY = Yleft./Yright;
edgeY(edgeY<1) = 1./edgeY(edgeY<1) ;
edgeY = edgeY -1; % set so noEdge=0
clear Yleft Yright Ev Eh
%% Determines edges in X-direction
for k = -n:n
%Horizontal displacements:
%moves element to the left, adds zeros on the left, if k is on the
%left of the center array (-n).
if k<0
Eh = padarray(Image(:, 1:dimensions(2)-abs(k)),[0 abs(k)], 'pre');
end
%moves element to the right, adds zeros on the right
if k>0
Eh = padarray(Image(:, 1+k:dimensions(2)),[0 k], 'post');
end
%when reaching the center element - do nothing.
if k == 0
Eh = Image;
end
for i = -n:n
%Vertical displacements:
%moves elements up, adds zeros above. Then adds to top
%variable
if i < 0
Ev = padarray(Eh(1:dimensions(1)-abs(i),:),[abs(i) 0], 'pre');
Xtop = Ev + Xtop;
end
%moves elements down, adds zeros below. Then adds to bottom
%variable
if i > 0
Ev = padarray(Eh(1+i:dimensions(1),:),[i 0], 'post');
Xbottom = Ev + Xbottom;
end
end
end
Xtop(Xtop<0.01) = 0.01;% The low values are set to 0.01 så we don't divde by zero or anything near.
Xbottom(Xbottom<0.01) = 0.01;
edgeX = Xtop./Xbottom;
edgeX(edgeX<1) = 1./edgeX(edgeX<1) ;
edgeX = edgeX -1; % set so noEdge=0
clear Xtop Xbottom Ev Eh
%% Finalization of edges:
edgetotal = sqrt((edgeY).^2 + (edgeX).^2);
if deadpixel == 'on';
edgetotal(dimensions(1)-5+1:dimensions(1),:) = 0;
edgetotal(1:5,:) = 0;
edgetotal(:,dimensions(2)-5+1:dimensions(2)) = 0;
edgetotal(:,1:5) = 0;
end
edge = edgetotal;