-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodediff.m
More file actions
23 lines (21 loc) · 755 Bytes
/
codediff.m
File metadata and controls
23 lines (21 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function d = codediff(fcc, conn)
%CODEDIFF Computes the first difference of a chain code.
% D = CODEDIFF(FCC) computes the first difference of code, FCC. The
% code FCC is treated as a circular sequence, so the last element
% of D is the difference between the last and first elements of
% FCC. The input code is a 1-by-np vector.
%
% The first difference is found by counting the number of direction
% changes (in a counter-clockwise direction) that separate two
% adjacent elements of the code.
sr = circshift(fcc, [0, -1]); % Shift input left by 1 location.
delta = sr - fcc;
d = delta;
I = find(delta < 0);
type = conn;
switch type
case 4 % Code is 4-connected
d(I) = d(I) + 4;
case 8 % Code is 8-connected
d(I) = d(I) + 8;
end