Image segmentation of connected shapes problem
Mostrar comentarios más antiguos
Hello, Below is the code I used to segment the image however when there are are connected shapes (shown in the img) the code take it as one object. I want it to take it as separate object and get the centroid of each. Your help will be very much appreciated. Thank you.
A = imread('image.png');
figure, imshow(A);
title('Original Image');
B = im2bw(A);
B = ~B;
B = 1-B;
B = (B == 0);
figure, imshow(B);
title('Image Without Holes');
C=imfill(B,'holes');
figure,imshow(C);
title('Image With Holes');
label=bwlabel(B);
max(max(label))
im1=(label==1);
for j=1:max(max(label))
[row, col] = find(label==j);
len=max(row)-min(row)+2;
breadth=max(col)-min(col)+2;
target=uint8(zeros([len breadth]));
sy=min(col)-1;
sx=min(row)-1;
for i=1:size(row,1)
x=row(i,1)-sx;
y=col(i,1)-sy;
target(x,y)=A(row(i,1),col(i,1));
end
mytitle=strcat('Object Number:',num2str(j));
figure,imshow(target);title(mytitle);
end
Image

Result: 2 Objects only should be 5 objects

Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Image Arithmetic en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


