# Mapping Resources > How Do I ??? >  Creating a path from the center points of a selection?

## eepjr24

If I have a selection, for simplicity sake we'll start with a 50 pixel wide line at a 45 degree angle from top left to bottom right (see below), how do I create a path that traverses the approximate center of the selection and is one pixel wide?



I know how to create a selection, shrink a selection, create a path from a selection. But simply shrinking will either end you up with gaps in the path or with areas that are wider than a pixel in the path. I am fine if this is something I need to do programatically if someone can point me in the right direction or the terminology to look for to execute this type of operation. I am no great mathematician, but I can muddle through most geometry and basic trig. And I am fine with putting in time to experiment as necessary.

- Ernie

----------


## Redrobes

Is this in any particular application or do you have the coordinates of the line or selection shape ? Is the starting point a set of numerical coordinates or an image which contains something like the line in it ? And if your selection was square then when you traverses, in which direction should it go ? Would it be across the smallest dimension for example.

I would suggest at first glance by looking into OpenCV. You can use that with a number of different programming languages such as python.

----------


## waldronate

What you need is called a morphological skeletonize operation or medial axis transform. It's a common operation in image processing. There are many libraries that can perform this task, but some sort of context in which you perform the operation would be useful.

----------


## eepjr24

> What you need is called a morphological skeletonize operation or medial axis transform. It's a common operation in image processing. There are many libraries that can perform this task, but some sort of context in which you perform the operation would be useful.


Trying to automate some tasks for map making. So say I have a set of roads laid out on a layer. Having a path that followed the center of the road would allow me to perform multiple strokes on the road to lay down color, texture, pot holes or whatever else I would like. So in the end I would like to be able to call this from scripts, but from what I have seen so far most anything you can do from the UI you can do from the pdb. I have been pointed to AutoTrace and a plug in to use it, I am probably going to try that next unless someone has nifty other ideas. =)

Thanks for the responses.

- E

----------


## waldronate

If you're looking to find the centerline of roads and then apply styles to that, you're most likely better off marking them manually because you are unlikely to need to do a huge number of roads (a couple of hundred, at most). That's especially true if you are trying to do this in the context of an existing tool like Photoshop or the GIMP. If you get a good workflow going, you can probably start from the centerlines next time.
Skeletonizing existing images (or selections) is a very error-prone operation that tends to generate a large number of spurious side branches. Simplifying the skeleton is very likely to be more work that it's worth.
Are you doing your own mapping program?

----------


## eepjr24

> If you're looking to find the centerline of roads and then apply styles to that, you're most likely better off marking them manually because you are unlikely to need to do a huge number of roads (a couple of hundred, at most). That's especially true if you are trying to do this in the context of an existing tool like Photoshop or the GIMP. If you get a good workflow going, you can probably start from the centerlines next time.
> Skeletonizing existing images (or selections) is a very error-prone operation that tends to generate a large number of spurious side branches. Simplifying the skeleton is very likely to be more work that it's worth.
> Are you doing your own mapping program?


Marking them manually is pretty much what I am trying to avoid. I think I would rather just start out with paths for roads than go that route.

No, I am just using the GIMP currently. Looking to make creating ad hoc content trivial for minor encounters, stop over points, etc. And ideally also create fast starting points for larger towns and such as well. If skeletonizing is too complex then I'll look at starting with paths, do you have any suggestions or know of tutorials or the like for generating quasi random paths, say in a mosaic or other warpable pattern set?

----------


## waldronate

Not in the context of the GIMP, no. A common and reasonably effective way to generate content is to start with a Voronoi tessellation of random set of points that's given a few rounds of Lloyd's algorithm to regularize things. Adjusting the original distribution can do interesting things. See Amit Patel's Red Blob Games or Oleg Dolya's Watabou thingies for examples.

----------


## Tiana

I have a program on my Mac, SuperVectorizer2, which will let you generate skeletonized vector lines from an artwork that would fit that description. It is a Mac only program though.

----------

