chain code for line
3 views (last 30 days)
Show older comments
majed majed
on 5 Nov 2015
Commented: majed majed
on 7 Nov 2015
here is my question : in this image which I have attached , starting from (x,y) or (s,t)how can I write the chain code for the line ? what is proper idea to write its code ? a lot of thank for everyone help me or try to help .
0 Comments
Accepted Answer
More Answers (1)
Guillaume
on 5 Nov 2015
Edited: Guillaume
on 5 Nov 2015
I've no idea what a chain code is, but if you're wanting to trace the path from (s,t) to (I,J) isn't it simply finding which of the eight neighbouring pixel is black, excluding pixels you've already been through.
currentrow = s;
currentcol = t;
path = [currentrow currentcol]
while currentrow ~= I && currentrow ~= J
[neighbours(:, 1), neighbours(:, 2)] = find(img(currentrow-1:currentrow+1, currentcol-1:currentcol+1) & [1 1 1;1 0 1;1 1 1])); %ignoring edge issues here
notvisited = ~ismember(neighbours, path, 'rows');
path = [path; neighbours(notvisited)]; %assumes there's only ever one non-visited neighbour
currentrow = neighbours(notvisited, 1);
currentcol = neighbours(notvisited, 2);
end
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!