arv100kri
arv100kri

Reputation: 99

Identify a shape inside another shape using AForge.Net

I am using the AForge.Net library to do some basic image processing stuff as part of a project. I have found it trivial to identify individual geometric shapes in an image (like a square, circle etc.,). However when I have an image like image , the program can only identify the outer circle. I would want it to be recognized as a circle and a line.

Similarly another example is, image1 , where the program identifies only a square but I need it to recognize it as a square and a circle.

I guess this library itself is outdated and no longer supported, but I will really appreciate some help! I have found this to be a really easy library to use but if my requirement cannot be met with it I am open to other libraries as well. (in Java, C# or Python). Thanks!

Upvotes: 0

Views: 1011

Answers (1)

Someone Someoneelse
Someone Someoneelse

Reputation: 485

That's an easy task using Python
You'll need libraries like numpy and scipy.ndimage to be installed,and with only scipy.ndimage you can extract any shape on a black background .
So if your image is in white background you need to invert it first which is an easy job.

import scipy.ndimage  
from scipy.misc import imread           # so I can read the image as a numpy array

img=imread('image.png')        # I assume your image is a grayscale image with a black bg.  
labeled,y=scipy.ndimage.label(img)   # this will label all connected areas(shapes).  
                                         #y returns how many shapes??  

shapes=scipy.ndimage.find_objects(labeled)         
# shapes returns indexing slices for ever shape  
# So if you have 2 shapes in your image,then y=2.
# to extract the 1st shape you do like this.  
first_shape=img[shapes[0]]          # that's is a numpy feature if you are familiar with numpy .
second_shape=img[shapes[1]]  

After extracting your individual shapes you can actually do some math work to identify what it is? (e.g circularity ratio >> you can google it , it's helpful in your case)

Upvotes: 1

Related Questions