0

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- enter image description here

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- enter image description here enter image description here

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'?

Noober
  • 1,516
  • 4
  • 22
  • 48

1 Answers1

1

You are analyzing the areas of connected white pixels in your image, so you get:

  • the white background (1)
  • the inner area of the benzene ring (1)
  • the inner areas of the two Os (2)
  • the inner areas of the 8 (2)

These are six objects in total.

Invert your image before processing, and you'll get all the lines and letters.

Jan Eglinger
  • 3,995
  • 1
  • 25
  • 51
  • Thanks a lot.I have another question is there any way I can join all the bonds and remove out the alphabets ? – Noober Jun 21 '15 at 18:53
  • 1
    @Noober - Yeah, this question that you asked here: http://stackoverflow.com/questions/30934611/line-detection-in-image/30942695#30942695 - There are three good answers that find the lines for you and you haven't accepted any of them. – rayryeng Jun 21 '15 at 19:25