Better skeletonization of an image to found branchpoints
7 次查看(过去 30 天)
显示 更早的评论
Hi,
I have an image of an grid and want to find the 12 branchpoints of it. But the skeleton is really "rough" so I have to many branchpoints. I tried different "clean up" methods but I can't clean it up enough. Can someone help me with my problem, please.
Grid = imread('grid.jpg');
gray_grid = rgb2gray(Grid);
binary_grid = im2bw(gray_grid);
inverse_grid = imcomplement(binary_grid);
grid_skel = bwmorph(inverse_grid,'skel',inf);
%%clean skel
skel_1 = bwmorph(grid_skel,'spur',inf);
skel_2 = bwmorph(skel_1,'clean',inf);
%%find branchpoints
branchpoints = bwmorph(skel_2,'branchpoints');
[rowsBP, columnsBP] = find(branchpoints)
%%show branchpoints
hold on;
for k = 1 : length(rowsBP);
plot(columnsBP(k), rowsBP(k), 'r+', 'MarkerSize', 8, 'LineWidth', 1);
end
0 个评论
回答(1 个)
Massimo Zanetti
2017-1-5
Dilate your image before skeletonize it. Try this:
%read image
G = imread('grid.jpg');
G = im2bw(rgb2gray(G));
%dilate image complement
I = imdilate(imcomplement(G),strel('disk',15));
figure; imshow(I)
%skeletonize, and remove spur branches
S = bwmorph(I,'skel',inf);
S2 = bwmorph(S,'spur',inf);
figure; imshow(S2);
%find branchpoints, dilate them to see them in image
B = bwmorph(S2,'branchpoints');
B2 = imdilate(B,strel('disk',10));
figure; imshow(B2);
6 个评论
Massimo Zanetti
2017-1-9
Ok, I got it. So, capture the centroids of the cirlces using regionprops. Like this:
I = imdilate(imcomplement(G),strel('disk',15));
S = bwmorph(I,'skel',inf);
S2 = bwmorph(S,'spur',inf);
B = bwmorph(S2,'branchpoints');
B2 = imdilate(B,strel('disk',10));
s = regionprops(B2,'centroid');
centroids = cat(1, s.Centroid);
figure;
imshow(G); hold on;
plot(centroids(:,1),centroids(:,2),'r*');
hold off;
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!