Effacer les filtres
Effacer les filtres

Connected region (grayconnected)

4 vues (au cours des 30 derniers jours)
Ilya Tcenov
Ilya Tcenov le 3 Mar 2019
Commenté : Image Analyst le 3 Mar 2019
Hi all,
I am using the grayconnected() function (multiplication of grayconnected on all 3 color layers) in order to obtain a mask of a part of the image that is separated by a black line (example given bellow).
You can see how the first line is consistent and it devides the image (using grayconnected), but the second line is not.
For this example I would like to have 3 different masks, but because the bottom line is not consistent, I am getting only 2.
I can't use imclose() on the black lines, because in some cases the lines are very dense, so imclose() will turn my image into one big black blob.
Is there a way to specify (using grayconnected) how many pixels do I consider as "connected" (so that a hole 1-2 pixel wide would not be considered as a connection between two regions)?
Should I consider a different approach?
Thank you very much.

Réponses (1)

Image Analyst
Image Analyst le 3 Mar 2019
What tolerance value did you use in your call to grayconnected()? Did you try adjusting it? Attach your original image and code.
  4 commentaires
Ilya Tcenov
Ilya Tcenov le 3 Mar 2019
Modifié(e) : Ilya Tcenov le 3 Mar 2019
One of the images is attached. You can see how some black lines are consistent, but some are not (even a 1 pixel hole in the separation line merges the segments).
The code is something like this:
myIMG=imread('myIMG.png');
[rows,cols,~]=size(myIMG);
for i=1:rows %run on entire image
for j=1:cols
%segment mark
segment=grayconnected(myIMG(:,:,1),i,j).*grayconnected(myIMG(:,:,2),i,j).*grayconnected(myIMG(:,:,3),i,j);
%operation
% on each such segment im making an operation (once per segment,
% so I delt with marking the segment as completed so that I will not hit
% the same segment on next pixel in loop).
end
end
I want the segment to be as small as possible (devided by black lines, including the inconsistent ones).
I hope it gives enough information about my problem.
Thank you.
Image Analyst
Image Analyst le 3 Mar 2019
I'd probably try 4-connected labeling instead of the default 8-connected. That will help.
You might also try watershed to split apart the blobs, if needed.click here
Or you might try a simple erosion to enlarge all the black lines.

Connectez-vous pour commenter.

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by