Reputation: 1626
I am trying to segment my image using the following code.
image=imread('mob.jpg');
image = im2bw(image);
L = bwlabel(image,8);% Calculating connected components
mx=max(max(L))
[r,c] = find(L==1);
rc = [r c];
[sx sy]=size(rc);
n1=zeros(imx,imy);
for i=1:sx
x1=rc(i,1);
y1=rc(i,2);
n1(x1,y1)=255;
end
imshow(image);
figure,
imshow(n1);
This was my input image-
I wanted to separate it into 2 connected componets-one the actual structure and other 7181
.Instead I am getting 6
components.The first-two component are-
So why is this happening?In all the pics I tested whenever there is a benzene ring it gets separated into another component.How can I just separate it into 2 components -the structure and '7191'?
Upvotes: 0
Views: 230
Reputation: 4090
You are analyzing the areas of connected white pixels in your image, so you get:
O
s (2)8
(2)These are six objects in total.
Invert your image before processing, and you'll get all the lines and letters.
Upvotes: 1