Noober
Noober

Reputation: 1626

Segmentation image processing using MATLAB

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

Upvotes: 0

Views: 230

Answers (1)

Jan Eglinger
Jan Eglinger

Reputation: 4090

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.

Upvotes: 1

Related Questions