0% found this document useful (0 votes)
30 views

Chain Code

This document implements a tangent angle function to trace the boundary of an image and assign direction codes. It loads an image, converts it to binary, and finds the starting point along the boundary. It then iteratively moves to the neighboring pixel in the specified direction and assigns the direction code to the function, until returning to the starting point. The directions are defined by 8 codes representing right, above right, above, etc.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Chain Code

This document implements a tangent angle function to trace the boundary of an image and assign direction codes. It loads an image, converts it to binary, and finds the starting point along the boundary. It then iteratively moves to the neighboring pixel in the specified direction and assigns the direction code to the function, until returning to the starting point. The directions are defined by 8 codes representing right, above right, above, etc.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

% Implementation of tangent angle function (chain code)

clear
clc

directions = [ 1, 0
1,-1
0,-1
-1,-1
-1, 0
-1, 1
0, 1
1, 1]

I = imread('./IMAGES/1/M_201005_1_0001.pgm');
Ibw = im2bw(I,0.15); % This is also by setting all the pixels with intesity lower than
17 to 0;

tanAngFunc ={};

[row,col] = find(Ibw);

y = col(find(max(row)==row))
x = max(row)

imshow(I)
hold on;
plot(y,x,'r.','MarkerSize',1)

hold on

l=1;

not_done = true;
while not_done
if l== 36
'test'
end

% Right (0)
if Ibw(x+directions(1,2),y+directions(1,1)) ~=0

tanAngFunc{l} = 0;
x= x+directions(1,2);
y= y+directions(1,1);

% Above right(1)
elseif Ibw(x+directions(2,2),y+directions(2,1)) ~=0
tanAngFunc{l} = 2;
x= x+directions(2,2);
y= y+directions(2,1);

% Above (2)
elseif Ibw(x+directions(3,2),y+directions(3,1)) ~=0
tanAngFunc{l} = 2;
x= x+directions(3,2);

y= y+directions(3,1);

% Above left (3)


elseif Ibw(x+directions(4,2),y+directions(4,1)) ~=0
tanAngFunc{l} = 2;
x= x+directions(4,2);
y= y+directions(4,1);

% Left (4)
elseif Ibw(x+directions(5,2),y+directions(5,1)) ~=0
tanAngFunc{l} = 2;
x= x+directions(5,2);
y= y+directions(5,1);

% Bottom left (5)


elseif Ibw(x+directions(6,2),y+directions(6,1)) ~=0
tanAngFunc{l} = 2;
x= x+directions(6,2);
y= y+directions(6,1);

% Bottom (6)
elseif Ibw(x+directions(7,2),y+directions(7,1)) ~=0
tanAngFunc{l} = 2;
x= x+directions(7,2);
y= y+directions(7,1);

% Bottom right (7)


elseif Ibw(x+directions(8,2),y+directions(8,1)) ~=0
tanAngFunc{l} = 3;

x= x+directions(8,2);
y= y+directions(8,1);
end

plot(y,x,'y.','MarkerSize',3)
hold on

pause(1)
l = l + 1;

not_done = (x ~= col(find(max(row)==row)) && y ~= max(row));


end

You might also like