Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
1  
"... 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
add comment

1 Answer

up vote 2 down vote accepted

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]}]

Mathematica graphics

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.