2
$\begingroup$

What is the good way to extract the objects(circles) from image as shown in picture below? enter image description here

respectively create two images one with lines and one with circles from source image.

I started with detecting contours in image to filter everything that may be circle from image which gives me results like this:

enter image description here

I'm new to computer vision and dealing with this specific task, so want thank you for any help and guidance.

Thank you all, here are some answers to questions from comments:

Define "best"

a good way to do it

Which techniques do you know that have something like that?

Today I looked at template matching, created a template for the black and white circle and localised them in an original image. Once I have this extracting lines is straightforward (just subtracting circles from the original image). This seems working well in the simplest scenario when circles are the same size as templates.

The more robust way I think will be to use Haar Cascade classifier, train it on different size circles, and continue as with results from template matching.

Correct me if there maybe a better way?

The main idea is to digitalize diagrams consisting of black and white circles connected by lines, The size of diagrams and quality of images may vary. Also, the circles may contain numbers (Extracting those is something for future)

The lines connecting circles are axis aligned, they define position of circles in diagram (similar to cartesian plane)

I mentioned Python (js) and OpenCV languages in case there are some specific implementation details I should be aware of. I'm also learning Python while doing this :).

I don't expect the solution or code, rather pushing to right direction and strategy to deal with this kind of problems.

$\endgroup$
8
  • 1
    $\begingroup$ Define "best". It's clear that you'll have to be able to tell the algorithm what kind of shape you're looking for. Which techniques do you know that have something like that? Alternatively, you could do some tailored post-processing on the contour data; what have you tried in this direction? $\endgroup$
    – Raphael
    Commented Aug 31, 2016 at 13:05
  • $\begingroup$ what does python( javascript) mean ? $\endgroup$ Commented Aug 31, 2016 at 14:44
  • 1
    $\begingroup$ Welcome to CS.SE! I don't understand what your question is. You start by asking how to extract circles, but then it becomes clear that you already know how to do that. Your results look great. Your title suggests you want to know how to detect the intersection between a circle and a line, but isn't that straightforward? Why are you having difficulty with that? What are you stuck on? Also, your title doesn't match the body of your post. Please edit the question to clarify what you are asking. $\endgroup$
    – D.W.
    Commented Aug 31, 2016 at 16:45
  • 1
    $\begingroup$ Note that coding/programming questions are off-topic here, so "how do I do this in Javascript/Python/OpenCV?" is off-topic. However, questions about algorithms and techniques are fine. $\endgroup$
    – D.W.
    Commented Aug 31, 2016 at 16:45
  • 1
    $\begingroup$ "a good way to do it" -- sorry, is that supposed to be funny? You can't define "best" by saying "good". Okay, deep breaths. There are many metrics you may conceivably want to optimize for: runing time, memory consumption, accuracy, recall, range of admissible inputs, ... -- and these are usually opposing each other. So, which are important to you? $\endgroup$
    – Raphael
    Commented Aug 31, 2016 at 21:46

1 Answer 1

1
$\begingroup$

First, I would suggest you to take a look at morphological operations on images, especially dilation and erosion. Dilation grows the boundary of foreground pixels (gets rid of holes), and erosion shrinks the boundary of foreground pixels (gets rid of bridges). In your case, erosion with an appropriate kernel might get rid of those unwanted lines. Then you apply dilation with the same kernel to preserve the circles. The two of them applied together in this order is called opening. Those functions are predefined in OpenCV, check out morphologyEx function.

Second, I would suggest you to take a look at convexity of shapes. The output circles in your images are convex, but the ones with lines are now. Thus, you can find the non-convex points of the contours (that you already found), and connect the contours from those points, so that you have convex shapes, i.e. desired output circles. To accomplish this, you can find the convex hull and convexity defects using related OpenCV functions.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.