2

I have a set of pixilated shapes, and after transforming each shape into a morphological component, I want to be able to return the coordinates for pixels that lie on the contour of the shape. More specifically, I want pixels that have some number of background neighbors in their von Neumann or Moore neighborhoods.

Say this "shape" is a phrase like the following:

http://pixelduke.files.wordpress.com/2010/01/jnbdec2008-hello-world-example2.png

We can isolate and color all of the morphological components / pixilated shapes we care about as follows:

shape = Import["http://pixelduke.files.wordpress.com/2010/01/jnbdec2008-hello-world-example2.png"]
m = MorphologicalComponents[ColorNegate[ImageCrop[shape, {300, 100}]]] // Colorize

How can we return a von Neumann or Moore-neighborhood connected set of contour pixels for each component?

LCook
  • 105
  • 5

1 Answers1

3

1) Isolating boundary pixels of each component:

EdgeDetect[Image[m /. x_Integer /; x =!= # -> 0 // Rescale]] & /@ (Union[Flatten[m]]-1)

enter image description here

2) If you need to wrap a polygon around each - please see:

Vitaliy Kaurov
  • 73,078
  • 9
  • 204
  • 355
  • Thanks. As a quick question, can you explain the Range[12] choice? – LCook Sep 08 '13 at 04:22
  • @user9408 In your image you have 10 letter and 2 punctuation signs. Also Union[Flatten[m]]. Could you please register a name here so it is easier to refer to it? – Vitaliy Kaurov Sep 08 '13 at 04:27
  • Sorry, there's no trouble with your answer, and I accepted it. The "trouble" comment wasn't referring to your answer, and I'll delete it. – LCook Sep 08 '13 at 04:45