0

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, which 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?

gideon
  • 19,329
  • 11
  • 72
  • 113
sap
  • 3
  • 1
  • 5

1 Answers1

1

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!

AVB
  • 3,994
  • 22
  • 21
  • @Phonon: It is among the list of [corner cases](http://stackoverflow.com/questions/1710299/corner-cases-unexpected-and-unusual-matlab) – Jonas Mar 25 '11 at 22:07
  • The potential mix-up is why I'd always write `[y,x]=getpts` – Jonas Mar 26 '11 at 03:16
  • thanks for the prompt reply. getpts was what i was looking for. But when i run it, it shows error saying 'Index exceeds matrix dimensions.' Error in ==> dry at 12 `plot(boundary(:,2),boundary(:,1),'b','LineWidth',1);` I read the warning,yet i tried swapping y and x, just to see if it worked. but no. the altered code is `imshow(BW) [x,y]=getpts boundary = bwtraceboundary(BW,[x,y],'E');` direction need not be specified, does it? – sap Mar 26 '11 at 08:31