I am looking for a GIS tool/script (preference on QGIS but I can also use ArcGIS/Matlab) that allows creating a polyline layer from a polygon layer where a polyline is drawn for each polygon. The polyline is drawn being the main direction of the polygon and being within the polygon.
Below examples in image:
I do not have preference for the drawing method (vertex to vertex or edge to edge, skeletons), only the result is important:
This question can be closed as I found a suitable arcgis tool: Polyline to centerline
I would have preferred a Qgis tool but it is OK for now.
Results of the tool below on real polygon layer:


