- Could you please elaborate what you exactly mean by "adding some some extra line to the end".
Sorting Data to follow down a line
4 ビュー (過去 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
0 件のコメント
回答 (1 件)
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));
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:
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!