Ask Your Question
1

How to convert pixel segmentation to polylines?

asked 2016-03-31 17:46:15 -0600

sweeneychris gravatar image

I have a pixel segmentation created from a superpixel algorithm such as this. So for each pixel I have a label for which "superpixel" (i.e. group) it belongs to. I would like to convert the boundaries between superpixels into polylines instead of pixels so that they may be simplified with the Douglas-Peucker algorithm.

My problem is that I cannot figure out how to go from the superpixel labels to polylines. It is trivial to draw the superpixel boundaries (see attached image) but I am having trouble understanding how to convert those boundaries to polylines. Any suggestions would be really appreciated!

image description

edit retag flag offensive close merge delete

Comments

As far as I know, a polygon is basically a vector<Points>, so why not loop over points and push them into a vector<Points> you define? This means you can decide which points will belong to which polygon.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-04-01 02:10:39 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-04-01 02:22:59 -0600

Have you try the cv::findContours method directly on the getLabelContourMask() from SEEDS? You can also increase the size of the boundaries to help the detection.

If it does not work, I think the only solution is to do it by hand: iterate through the getLabelContourMask (on vertical, the on horizontal) and add the positive pixel to a line. You have to first find the beginning on the line (let say scanning horizontal pixel until you find a positive one, and then iterate through a vertical neighborhood. Quite old school, but I don't see any other solution...

edit flag offensive delete link more

Comments

You can treat each superpixel segment as a polygon and then decimate the polygon with Douglas Peucker, but this does not enforce that the boundaries between each polygon are consistent. So using findCountours will not work in my case.

I am thinking that tracing boundaries explicitly may be the only way. I'm hoping for a faster solution though.

sweeneychris gravatar imagesweeneychris ( 2016-04-01 12:17:51 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2016-03-31 17:46:15 -0600

Seen: 1,288 times

Last updated: Apr 01 '16