Maziyar Grami
Maziyar Grami

Reputation: 25

Connecting two binary objects in matlab

I have a binary matrix containing several binary objects and I want to bridge between them. Actually I have the following picture:

startingpoint

And the result has to be like this:

result

Is there any function or a shortcut way, other than loops, for this problem?

Upvotes: 0

Views: 703

Answers (2)

user2307268
user2307268

Reputation:

Morphological operations are suitable but i would suggest line structuring element as your arrangement is horizontal and you do not want overlaps between lines:

 clear
 clc
 close all

 BW = im2bw(imread('Silhouette.png'));
 BW = imclearborder(BW);


 se = strel('line',10,0); 
 dilateddBW = imdilate(BW,se);       
 img= imerode(BW,se);

 figure;
 imshow(img)

Upvotes: 2

Photon
Photon

Reputation: 3222

Use a morphological close for this purpose

http://www.mathworks.com/help/images/ref/imclose.html

Try using a square structuring element of various sizes until you get what you expect.

Upvotes: 0

Related Questions