- Could you please elaborate what you exactly mean by "adding some some extra line to the end".
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
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!