Ask Your Question

Extract Curves Contours

asked 2017-08-06 01:37:08 -0500

Mafe gravatar image

Hi everyone !

I'm posting this question because, after months, I'm still getting my ease with the library openCV but couldn't reach an automated solution for this curves extraction problem. (also, it's my birthday and finding a solution would be The gift :p )

Don't bother making lines of code; my request is essentially to be tipped in the correct direction.

Heberger image

So, from this sample picture (that some of you might recognize as power/torque graph)

Heberger image

I start quite classic. I pretreated it with bilinear filtering, detected the edges with Canny and then detected contours and houghlinesP. From the last ones, I filtered the outside contour of the graph and every inside contour that was fully included in the houghLines quad.

Heberger image

Then, I simplified all the contours with approxPolyDP and plotted the fitLine to get the tendency of every contour. Here we can see it follows approximately the 4 curves I'm trying to extract.

Heberger image

So the last step here is to clusterize them by hue and display properly the fitted lines.

At this point, there might be some magic involved to help me figure out the curves tendencies and use that to go back to the second image and segment the actual curves from the contours.

But nothing really pops up in my mind and you cannot filter contours properly because points will have messy links in your contours. Though, I just want the pixels of the 4 curves and nothing else.

Thanks for your attention!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-08-07 05:24:28 -0500

KjMag gravatar image

updated 2017-08-07 05:29:49 -0500

You can use the k-means algorithm to segment the curves directly. You just have to experiment a little with the number of clusters you're gonna use because you have to reserve some clusters for the color of the font, grid, axes and plot backgrounds, and also GUI elements such as these buttons with magnifying glass and hand.

I think 11 clusters should do the trick (1 for each of the 4 curves and 7 for the plot elements listed above). Observe the results and try adding more or remove some of them if you don't get the results you want.

This solution could be fully automated because I presume that all the pictures you are going to analyze would be identical in terms of the interface and only the curves change, so the number of pixels constituting each of the other 7 clusters should be very similar on every picture (number of points constituting the curves would probably also be similar for that matter), so you should be able to identify your curves just by analyzing the number of points belonging to each cluster.

The only problem you may have is when the curves are of the same color as some of the interface elements, e.g. if one of them is of the same color as the font, but it's easy to filter out the unwanted points in such a case, because you may analyze the position of the points belonging to the cluster - if they are near the edges of the image, then it's an interface element.

These links can get you started along with the docs I've linked above:

Happy birthday ;)

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-08-06 01:33:58 -0500

Seen: 721 times

Last updated: Aug 07 '17