I seem to have found a solution to the problem using a beautiful piece of code written by John D'Errico.
First, I sort my edge pixels according to the following:
- Let e be the unsorted list of edge pixels
- Let s be the sorted list of edge pixels and initialize it to [].
- Let pp be the previous pixel and initialize it to the first pixel in e.
- Remove pp from e.
- Add pp to s.
- Let cp be the closest pixel to pp within e.
- Let cp equal to pp.
- Repeat 4-7 until e is empty.
This will result in the edge pixels being sorted in either clockwise or counter-clockwise orientation. For a complete solution I will have to find a way to determine which it is, and then reverse the list if is in ccw order.
To the sorted edge pixel list I apply John D'Errico's interparc function like so:
pt = interparc(n, px, py, 'spline');
where px, py are the sorted edge pixel coordinates and n is the number of uniformly spaced points along the curve represented by the edge pixels.
The image below shows 100 uniformly spaced points along the edge of the shape from my orignial submission.
Hope someone else finds this useful.