# Finding a Moore neighborhood connected path of bright pixels along the contour of a text character

I have a simple image, for example a blowup of a Times New Roman character like 'R' saved as a PNG. I then perform the following operations to extract a minimum representation of the contour lines around the character:

MorphologicalComponents[Thinning[EdgeDetect[Import["http://li.c-b.co/is/image/LandOfNod/Letter_Giant_Enough_R_232459_LL/$web_zoom$&wid=550&hei=550&/1308310656/not-giant-enough-letter-r.jpg"]]]] // Colorize

(The image in the picture is the best I could do looking around for an example on the Internet...)

I'd now like to find a way to pull out an ordered set of coordinates representing the center of pixels connected through their Moore neighborhoods. The hope is that this will yield a polygon representation of the character for 'R'.

Is there a simple way to do this that doesn't require me having to compute a Hamiltonian path or cycle?

• "... an ordered set of coordinates representing the center of pixels connected through their Moore neighborhoods." This bit (arguably your whole question) isn't clear to me at all. Perhaps you should explain in more detail what you mean, and/or supply a simple example. – Aky Nov 21 '13 at 10:16

I'm not completely sure that I fully understand your question, but perhaps:

m = MorphologicalComponents[
Thinning[
EdgeDetect[
Import["http://li.c-b.co/is/image/LandOfNod/Letter_Giant_Enough_\
R_232459_LL/$web_zoom$&wid=550&hei=550&/1308310656/not-giant-enough-\
letter-r.jpg"]]]];
a = (Position[m, #] & /@ Range@Max@m);
cps = FindCurvePath /@ a;
Graphics[{FaceForm[White], EdgeForm[Black],
Rotate[Polygon[a[[#, cps[[#, 1]]]]] & /@ Range@Max@m, -Pi/2]}]