Boundary tracing in matlab
I have already seen complex codes for boundary tracing in this site.
I'm a 1st time Matlab user, with a small code with bwtraceboundary.
This code once traced outline of a leaf image( though without tracing the leaf stalk, whi开发者_开发技巧ch was a lighter shade)... before I changed the image size. then all I get out of this, for any image, is a blank.
I thought I'd missed the starting point of the boundary, and tried different values for computing row & col (coords. of start pt.), but none worked. Can you help me trace the leaf with its stalk please?
The code is:
I = imread('C:\...\images3.jpg');
imshow(I)
BW = im2bw(I);
imshow(BW)
dim = size(BW)
col = round(dim(2))-90;
row = min(find(BW(:,col)))
boundary = bwtraceboundary(BW,[row, col],'N');
imshow(I)
hold off;
plot(boundary(:,2),boundary(:,1),'b','LineWidth',1);
Suppose the image matrix is obtained by typing 'I' in command window, will I be able to choose a starting pt.? How?
Yes, you might be missing the starting point (or the direction). If you do
imshow(I)
[x, y] = getpts
you'll be able to specify the starting point with your mouse. Beware of the eternal mix-up between columns and rows when working with images in Matlab!
精彩评论