Problem with tracing boundaries of handwritten letter

2 views (last 30 days)
Hello,
I am trying to use the bwtraceboundary function to trace the shape of a handwritten letter. First, I have converted it to binary, used imcomplement to invert the pixels, then dilated and closed the image in order to fill in the gaps, then finally have thinned the image. I got the image showed below.
Now, when I try to use the code below to apply a bwtraceboundary from the point of mouseclick, it gives me this error: 'Attempted to access BW(:,-48); index must be a positive integer or logical'. Can anyone explain why?
Thanks in advance
Debs
The code:
I = imread('image.png');
[x, y] = getpts;
imshow(I)
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);
end

Answers (1)

Image Analyst
Image Analyst on 22 Sep 2014
Why are you using bwtraceboundary? That's only useful if you need to start your boundary at some special particular point. I never use it. I use bwboundaries().
  2 Comments
Image Analyst
Image Analyst on 23 Sep 2014
Debs "Answer" moved here since it's not an "Answer" to her original question:
Hello, thanks for this! I am trying to trace the outline of the thinned letter shape in order to compare the shape of two different letters. I am trying to get row and column co-ordinates of the boundary pixels in the object. Thanks for your advice, I will give bwboundaries a try today!
Debs
Image Analyst
Image Analyst on 23 Sep 2014
But it looks like your image is already skeletonized, and it has branches. I'm not sure of the order and direction that the boundaries will take. For example with a "spur", are the coordinates counted twice, once as it goes out to the tip, and once again on the return trip? Which direction does it take when it hits a 3 or 4 way branch point and will that match up with the direction you expected it to take when you are following strokes for hand written letters?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!