Finding the distances between two boundaries

Hi there,
I have an expanding object, which shows different contours at different time. In this case, I would like to analyze its expansion speed at all sides.
Firstly, these two contours at two adjacent time are binarized and shown below.
  • Boundary 01
  • Boundary 02
Secondly, I got the outline coordinates along these two contours using the edge() function. At the same time, I plotted the gradient arrows started from the first contour, to show the expanding directions at different sides. A part is shown as follows.
My question is, how to find the pairwise coordinates from the second (the larger one, black) contour? Where it is exactly the point of intersection or the one is closest to the arrow expansion line. After locating the pairwise point, we may need to adjust the gradient arrow a little bit, and measure its length to indicate the expanding speed. Thank you in advance!

 Accepted Answer

To get a list of (row, column) coordinates for blobs in a binary image you can do
boundaries = bwboundaries(mask);
% To find the distance between every point in blob #1 to every point in blob #2, you can do this:
% First get x and y for blob #1
b1 = boundaries{1};
x1 = b1(:, 2);
y1 = b1(:, 1);
% First get x and y for blob #1
b2 = boundaries{2};
x2 = b2(:, 2);
y2 = b2(:, 1);
% Now find the distances between all pairs of points
distances = pdist2([x1, y1], [x2, y2]);
Hope you can take it from there.

3 Comments

Hi Image Analyst,
Thank you for your kind help. I read one of your demo before, which could help to get the distances between two independent objects. However, there are some differences in my case.
Firstly, the number of coordinates from these boundaries are not the same, meaning that we need to find the pairwise points from the larger (outer) boundary.
More importantly, I would like to connect these two boundaries point by point to show the expanding speed at all sides, so need to confirm the ending points of the gradient arrows.
Could you give me more suggestions? Thanks a lot!
If you have an initial point, P1a, and a gradient vector, you can draw a line through the point P1a, at the slope of the gradient, all the way through the image. Then for each point along that straight line, use pdist2() to find out which pair of points (P1b on the line and P2 on the next, expanded or shrunken curve) has the minimum distance. Basically you're finding out which point P2 corresponds to point P1a on the original curve and in a direction specified by the gradient vector.
Now that you know the index of the point on the second curve, you can compute the distance from that point to the original point P1a. And the speed if you know the time between the curves.
It works, and the preliminery result is shown as below. Please let me know if you have more fantastic ideas, thank you very much!

Sign in to comment.

More Answers (0)

Asked:

on 15 May 2021

Commented:

on 16 May 2021

Community Treasure Hunt

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

Start Hunting!