Sorting Data to follow down a line

4 ビュー (過去 30 日間)
Andrew Luce
Andrew Luce 2020 年 3 月 3 日
コメント済み: Andrew Luce 2020 年 3 月 10 日
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 Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by