Filter löschen
Filter löschen

can any one tell me how can I find the number of pixel between two point on a closed contour? I know that there are two path between two point on a closed contour. i need to find the shortest path. please help me. I think a lot but got no solution

1 Ansicht (letzte 30 Tage)
can any one tell me how can I find the number of pixel between two point on a closed contour? I know that there are two path between two point on a closed contour. i need to find the shortest path. please help me. I think a lot but got no solution

Antworten (2)

Walter Roberson
Walter Roberson am 7 Jul. 2016
José-Luis's response is interesting and might be all you need. But in general, the path along curved contours defined by pixels is often ambiguous. Do you follow the inside of the curve? Do you follow the outside? Do you calculate pixel center to pixel center or do you interpolate?
A*
B
A to B is two over and 1 down so sqrt(5) Euclidean but it had to be approximated due to the coarseness of pixels. Do you calculate it as 1 + sqrt(2) -- that is, one over plus (1 over and 1 down = sqrt(2)) ?
For a curve you will often see multiple adjacent pixels like
****
**
**
***
** *****
****
There can be both horizontal and vertical "duplicates" at any given location, as needed to quantize the curve to pixels. Which pixels do you choose to follow and in which order? José-Luis's answer follows them in the order stored, which might not be the best solution depending on the problem at hand.
There is a different approach that can be used rather than José-Luis's: you can make use of http://www.mathworks.com/help/images/ref/bwdistgeodesic.html . Depending on what you are doing, you might also find graydist to be of interest.
  3 Kommentare
fariba amini
fariba amini am 7 Jul. 2016
thanks a lot. actually I want to calculate the geodesic distance between two point on a close contour. I attached a shape which contain a contour with two point on it,and the distance I need to calculate is colored with red and two point is colored with green. thanks alot in advance

Melden Sie sich an, um zu kommentieren.


José-Luis
José-Luis am 7 Jul. 2016
%random contour, first point is also last point
c = rand(100,2);
c(:,1) = c(:,end);
%index for random starting and ending point
idx = sort(randsample(99,2));
startP = idx(1);
endP = idx(2);
%Computing the distance between successive points
distance2 = diff(c);
distance2 = [sum(distance2.*distance2,2); 0];
total_length = sum(distance2);
%Computing ditance of both paths
sub_distance1 = sum(distance2(startP:endP-1)) %Will be zero if startP == endP
sub_distance2 = total_length - sub_distance1
Voila.

Kategorien

Mehr zu Agriculture finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by