shortestpath between two points on skeleton in binary image
6 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I have a binary image which contains one pixel width skeleton of an image. I have got the skeleton using the bwmorph function. As you may know basically in this binary image, I have ones on the skeleton and zeros anywhere else. how can I find the shortest ‘quasi-euclidean’ distance between two nonzero elements which are on the skeleton? The path should be on the skeleton itself too. I guess bwdist will be helpful for my problem, but I don't know how to apply it for this case.
I will really appreciate any help. Thanks,
0 件のコメント
回答 (3 件)
Ashish Uthama
2011 年 11 月 4 日
Maybe this blog post by Steve could give you some ideas. You could start out with an image with just the two points, go through the process in the blog and then add your skeleton as a mask at the end.
0 件のコメント
George Abrahams
2023 年 12 月 18 日
Hi Sepideh. To expand upon @Ashish Uthama's answer, if you want to go down the shortestpath route which uses Dijkstra's algorithm, you can use my bwgraph function on File Exchange to construct the graph. See the example below.
By default, the edges of the graph will have weights (effectively, distances) which are Euclidean, so pixels sharing an edge have a distance of 1, and pixels sharing a corner will have a distance of . The total path distance will be the sum of these.
BW = imread( 'circles.png' );
BW = bwmorph( BW, 'skel', Inf ); % also consider bwskel.
% Construct the graph of connected non-zero pixels.
G = bwgraph( BW );
% Calculate the linear indices of the start and end pixels, which are
% used to reference the respective node in G.
sz = size( BW );
source = sub2ind( sz, 25, 28 );
target = sub2ind( sz, 196, 192 );
% Find the shortest path between the 2 nodes.
P = shortestpath( G, source, target );
% Calculate the respective pixels for each node in the path.
[ Pi, Pj ] = ind2sub( sz, P );
% Plot the image and path.
figure
imshow( BW )
hold on
plot( Pj, Pi, 'r-', 'LineWidth', 4 )
0 件のコメント
Catalytic
2023 年 12 月 18 日
1 件のコメント
Image Analyst
2023 年 12 月 19 日
編集済み: Image Analyst
2023 年 12 月 19 日
See Steve's blog series on it:Exploring shortest paths – bwdistgeodesic, as @Ashish Uthama already mentioned.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!