Sorting Data to follow down a line

3 次查看(过去 30 天)
Hello,
I'm trying to compare an image of a path to the points in the generated via matlab. I have an image of the path, turinging it into a binary image, skeltonizing the image and taking the row and column data for the skelton. I want to have points of the line in order to follow down the line. I found this code to do so but for some reason its adding some some extra line to the end. I do not know why.
The code I used for sorting is as follows
Coordinates=[col row]; % put the coordinates into a single matrix
dist = pdist2(Coordinates,Coordinates); %calculate the distance between each point in the matrix
N = size(Coordinates,1); % Number of points in the trace line
result = NaN(1,N); %set up the matrix for the loop to order the points to follow the path
result(1) = 1; % first point is first row in data matrix
for ii=2:N % found this on the internet, creates an order for the points to follow the path of the line
dist(:,result(ii-1)) = Inf;
[~, closest_idx] = min(dist(result(ii-1),:));
result(ii) = closest_idx;
end
Coordinates=Coordinates(result,:); %apply that order to the coordinate list
Thank you

回答(1 个)

Prabhan Purwar
Prabhan Purwar 2020-3-6
Hi,
I am getting the following output using the above mentioned code:
load('data (1).mat');
scatter(col,row);
figure
plot(col,row);
Coordinates=[col row]; % put the coordinates into a single matrix
dist = pdist2(Coordinates,Coordinates); %calculate the distance between each point in the matrix
N = size(Coordinates,1); % Number of points in the trace line
result = NaN(1,N); %set up the matrix for the loop to order the points to follow the path
result(1) = 1; % first point is first row in data matrix
for ii=2:N % found this on the internet, creates an order for the points to follow the path of the line
dist(:,result(ii-1)) = Inf;
[~, closest_idx] = min(dist(result(ii-1),:));
result(ii) = closest_idx;
end
Coordinates=Coordinates(result,:); %apply that order to the coordinate list
figure
Hi scatter(Coordinates(:,1),Coordinates(:,2));
figure
plot(Coordinates(:,1),Coordinates(:,2));
  • Could you please elaborate what you exactly mean by "adding some some extra line to the end".
Extra line at the initial point is because algorithm expects the initial point to be accurate.
Workaround: Add a point (21,258) in the data set.
Output:
  1 个评论
Andrew Luce
Andrew Luce 2020-3-10
On the top left of the graph, if you zoom in you'll see that the line doesn't have a clean end it takes a sharp turn downards. It added some extra points it seems.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Read, Write, and Modify Image 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by