There is a much simpler solution for that - in case you have hard edges:

You just trace all the contours in your level sprite, build up the edges and the create chained line segments out of it.

Also you can create polygons out of that edges, but you must convert non-convex polygons to convex polygons!

The theory behind is really simple, but implementation is not that easy - just google for contour tracing.