Better skeletonization of an image to found branchpoints

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

답변 (1개)

Massimo Zanetti
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

tsaiwu
tsaiwu 2017년 1월 5일
편집: tsaiwu 2017년 1월 5일
thanks for your help thats a great way and I get a much finer skeleton, but after this I want to know where the single branchpoints are (x,y). And I have still to many branchpoints, only in the image it appears as one branchpoint. My goal is to finde the single branchpoints (x,y coordinates) in the grid.
Ok, found a way to do it. I do it with circle detection and find the center points of it. Now I will try if this code works with a other painted grid.
Edit: Code doesn't work so well for the second grid.
clc; clear all;
%read image
G = imread('grid.jpg');
G = im2bw(rgb2gray(G));
%dilate image complement to thick it up
I = imdilate(imcomplement(G),strel('disk',13));
%skeletonize, and remove spur branches
S = bwmorph(I,'skel',inf);
S2 = bwmorph(S,'spur',inf);
S3 = bwmorph(S2,'clean',inf);
%find branchpoints, dilate them to see them in image
B = bwmorph(S3,'branchpoints');
B2 = imdilate(B,strel('disk',10));
[centers, radii] = imfindcircles(B2,[10 30],'ObjectPolarity','bright');
figure; imshow(G);
hold on
plot(centers(:,1),centers(:,2), 'r+', 'MarkerSize', 10, 'LineWidth', 2);
centers
Why are you dilating and calling infindcircles()? Simply call find() and plot
[y, x] = find(B);
plot(x, y, 'r+', 'MarkerSize', 10, 'LineWidth', 2);
tsaiwu
tsaiwu 2017년 1월 6일
편집: tsaiwu 2017년 1월 6일
because bwmorph(branchpoints) finds to many branchpoints, I want the coordinates of the intersections points of the grid.
I have dilated the branchpoints (image B2) only to enhance their visualization.. In matrix B you have only the right pixels on.. to get the coordinates (i,j index) just call [I,J]=find(B).
There is no need to run additional code after the piece of code I wrote.
tsaiwu
tsaiwu 2017년 1월 6일
편집: tsaiwu 2017년 1월 6일
If i ran find[B] it gives me to many branchpoints backs, like I said before. I want to find only the intersections point of the grid, for example in the first grid 12 points.
And do you have an idea to get the intersection points of the second grid? thanks
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;

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

질문:

2017년 1월 4일

댓글:

2017년 1월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by