2
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ "... 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. $\endgroup$ – Aky Nov 21 '13 at 10:16
2
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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