MATLAB Answers

Remove single pixel width connecting lines between objects

9 views (last 30 days)
Haider Ali
Haider Ali on 21 Oct 2019
Commented: darova on 23 Oct 2019
Hi all,
How can I remove/disconnect the connecting lines between objects while keeping the boundaries of my objects intact?


Show 3 older comments

Sign in to comment.

Answers (1)

darova on 22 Oct 2019
Here is an idea: find large areas and merge them to remove walls
I = imread('image.png');
I1 = im2bw(I);
% I2 = bwmorph(~I1,'thin',3);
[I3,n] = bwlabel(I1,8); % label image
p = regionprops(I3,'Area'); % find area of each region
ar = cat(1,p.Area);
ind = find( 400 < ar & ar < 5000); % find interested areas
I4 = I3*0;
for i = 1:length(ind)
ix = find( I3==ind(i) ); % find pixels of interested areas
I4(ix) = 1;
I5 = imdilate(I4,ones(3)); % merge neigbouring areas
I6 = imdilate(~I5,ones(3)); % return original size of areas
II = cat(3,I1,~I6,I1*0);
imshow(I1 | ~I6)
The result: Green lines/walls removed, Yellow areas detected


Haider Ali
Haider Ali on 22 Oct 2019
@darova, interesting sloution.
But I am afraid it does not solve my actual problem.
The image that I have provided is actaully obtained after applying watershed on binarized cell image. My goal is to segment the cells and calculate their properties.
The probelm I am facing is that after binarization (imbinarize), some of the cells' boundaries are not closed> Therefore, I applied the waterhsed transform. This improves the cell segmentation but also introduces extra ridges (connecting lines) and these extra ridges create false positives.
So there are couple of things that I can do:
  1. Improve my binarization/thresholding algorithm to create strong edged cell boundaries.
  2. Perform some pre-processing before watershedding to join broken cells' boundaries (please see this question too Edge linking and hole filling in binarized cell image).
  3. Remove the newly created connecting lines introduced by watershed transform.
What would the best approach in your opinion?
I am attaching some figures too.
In watershedimage.fig, I have circled 2 false positives which were introduced only because of watwershed transform.
Please let me know if any pther explanation of the problem is required.
darova on 23 Oct 2019
I'm afraid that i can't help. All i can advise is binarizing image and manipulating with graythersh

Sign in to comment.

Translated by