To anyone who comes across this problem in the future, the solution was as follows:
- Give each segment a value using bwlabel
- 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)