Watershed Segmentation is resulting in more segments than necessary. How can I change this?

1 visualización (últimos 30 días)
I have a ground truth image and I want to find its skeleton points and from these skeleton points I want to use watershed to recreate the ground truth image.
The problem is, when I use bwmorph(skel), the skeleton points touch each other and it results in an under segmented image. I tried to erode the image before I find the skeleton points, and this resulted in oversegmentation. The code and images are below:
img = imread('181091.jpg');
img = double(img);
seg = readSeg('181091.seg');
R = img(:,:,1);
G = img(:,:,2);
B = img(:,:,3);
[GxR,GyR] = gradient(R);
[GxG,GyG] = gradient(G);
[GxB,GyB] = gradient(B);
Grad = sqrt(GxR.^2 + GyR.^2 + GxG.^2 + GyG.^2 + GxB.^2 +GyB.^2);
img_skel = 0;
for i = 1:max(max(seg))
seg_sel = seg==(i);
seg_sel = imerode(seg_sel,ones(3,3));
img_skel1 = bwmorph(seg_sel,'skel',inf);
img_skel = img_skel + img_skel1;
end
figure, imagesc(img_skel)
watersh = imimposemin(Grad,img_skel);
Labels = watershed(watersh);
Labels = label2rgb(Labels);
The ground truth has 6 segments:
However, my result (with imerode, bwmorph, imimposemin and watershed) has 14 segments:
I want to be able to have the same number of segments. What could I add or change in my code? If I don't use imerode, the image looks like this:

Respuestas (1)

Image Analyst
Image Analyst el 6 de Jun. de 2020
Try this instead:
  2 comentarios
Ruba
Ruba el 6 de Jun. de 2020
Thank you Image Analyst for your suggestion.
Unfortunately, this code is for a project I'm working on with a professor and it has to be written by myself and I can't use some one else's code. I just need help figuring out a way to improve what I already wrote

Iniciar sesión para comentar.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by