how to trace ordered external counter of an object

Hello,I need to order point on boundary.I have a logical image so I use bwtraceboundary, but the results is a Bb matrix empty.Can someone help me to understand the reason?I wrote this code:
[filename,pathname]=uigetfile('*.jpg');
im=imread([pathname filename]);
figure,imshow(im,[])
T=graythresh(im);
It=im2bw(im,T);
figure, imshow(It,[])
Bb=bwtraceboundary(It,[12 33],'E',8,Inf,'clockwise')
where r=12 e c=33 is the first pixel of the boundary that I want to order. I attach also the image. Thank you

 채택된 답변

Walter Roberson
Walter Roberson 2015년 5월 30일
It = ~im2bw(im,T);
Remember, black is "no object" for the purpose of boundary tracing.

댓글 수: 3

Thank you,but Bb is still empty matrix.I really don't understand the reason now.
sorry, I was making a mistake! you are right..thank you!
Are you able to answer to my question below?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2015년 5월 30일

0 개 추천

To get ordered points, use the much simpler bwboundaries(). You only would need to use bwtraceboundaries() if you, for some reason, wanted to start at one special, known pixel location. I have never ever needed to do that in all my image processing with MATLAB, or even before (that I can remember). The starting point just doesn't make any difference to me. It can start wherever it wants to as far as I'm concerned. That relieves me of having to find a starting point, which is not easy, or at the very least, a step that does not need to be done with bwboundaries(). Are you sure you need to start at one specific point? If so, why?

댓글 수: 5

Here's a code snippet from my Image Segmentation Tutorial:
% bwboundaries() returns a cell array, where each cell contains the row/column coordinates for an object in the image.
% Plot the borders of all the coins on the original grayscale image using the coordinates returned by bwboundaries.
imshow(originalImage);
title('Outlines, from bwboundaries()', 'FontSize', captionFontSize);
axis image; % Make sure image is not artificially stretched because of screen's aspect ratio.
hold on;
boundaries = bwboundaries(binaryImage);
numberOfBoundaries = size(boundaries, 1);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
end
hold off;
Yes, I want to start at one special known pixel location because I should implement the edge splitting algorithm.I have some problems also to write this algorithm, so I'll be very grateful if you help me or suggest me how to implement. Starting from the ordered pixel in Bb my algorithm should: Starts with a long straight line and divide it into smaller line segments until all edge pixels that are being approximated by this line segment are within the maximum allowable deviation(threshold choose by the user).Like in the image that I attached the first line segment is defined using first and last edge pixels.The fourth edge pixel is the farthest away from this straight line and the distance from this point to the straight line exceeds the threshold, so this line is split into two line.Then I apply the same procedure between first and fourth edge pixel until the distance from edge pixels to the line segments is within the maximum allowable deviation. I hope that you understood this explanation. So to implement this algorithm I thought to write something like:
x1=Bb(1,1);
y1=Bb(1,2);
x2=Bb(end-1,1);
y2=Bb(end-1,2);
m=[(1+(1218-1)/2) 2];
% straight line between two points ax+by+c=0
a=y2-y1;
b=-(x2-x1);
c=-x1*(y2-y1)+y1*(x2-x1);
%distance
d=abs(a*m(1)+b*m(2)+c)/sqrt(a.^2+b.^2);
and if d>threshold split and do the same things with other straight line. Is it correct in your opinion? Maybe it is not a good approach, but I don't know how to carry on.Thank you in advance.
The image is not able to display. Perhaps you want the minimal perimeter polygon, like in this discussion: http://www.mathworks.com/matlabcentral/answers/44072#comment_90696
Silvia Caruso
Silvia Caruso 2015년 5월 30일
편집: Silvia Caruso 2015년 5월 30일
Yes, I need to apply the edge splitting technique to the boundary of a letter, like here: http://dip.sun.ac.za/~hanno/tw444/lesings/lesing_19.pdf
OK, good luck. What a funny coincidence -- that is the same paper Walter mentioned in the link I gave you in my last comment. I have not done that before so I don't have any code for it.

댓글을 달려면 로그인하십시오.

질문:

2015년 5월 30일

댓글:

2015년 5월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by