Remove unconnected lines from Canny Edge Detection

5 次查看(过去 30 天)
Hi Guys,
I have run a canny edge detection on an image and it has worked fairly well. After some processing I have been able to use the canny edge detector to find the edges. I then connect the edges using image dilate, and take the skeleton of the dilated lines. The problem is I am left with this unconnected lines. I have been searching for a while and cant seem to find a way to remove them.
I feel as though this should be quite simple but I am struggling to figure it out.
I have tried selecting each individual segment and dilating and eroding it, but I cant seem to get this to work.
Thanks in advance,
  1 个评论
Samuel Leeney
Samuel Leeney 2020-12-2
To anyone who comes across this problem in the future, the solution was as follows:
  1. Give each segment a value using bwlabel
  2. Index through each segment and imdilate them imerode with a fairly large strel.
This removed the 'tails' without affecting the segments by a noticible amount.
For example:
Note my method is quite slow, I am yet to optimise it.
SE = strel('disk',25);
for n = 1:max(ul) %checks through each segment
for k = 1:(length(L)^2) %checks through the indicie of each segment
if L(k) ~= n
Lnew(k) = 0;
else
Lnew(k) = L(k);
end
end
id = imdilate(Lnew,SE);
ie = imerode(id,SE);
seg = seg + ie;
end
figure
imshow(seg)

请先登录,再进行评论。

回答(0 个)

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by