Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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["$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
"... 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
up vote 2 down vote accepted

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

m = MorphologicalComponents[
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

Your Answer


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.