Group Abstract Group Abstract

Message Boards Message Boards

Breaking up a graphics object

Posted 10 years ago
POSTED BY: Greg Hurst
2 Replies

Nice question! Because devising parts is a topological operation I doubt you can find something simpler than you suggested (I still hope though). What I will show is just an much more elaborate exercise in finding an alternative.

In image processing one can find basins at each regional minimum in image using WatershedComponents:

wsc = WatershedComponents[Dilation[ColorNegate[Binarize[g]], 1]];
Colorize[wsc]

enter image description here

You see your fragments right away and the are just particular integers in the matrix:

Union[Flatten[wsc]]

{0, 1, 2, 3, 4, 5, 6}

Extract them as:

frag = Table[Colorize[Map[KroneckerDelta[k, #] &, wsc, {2}]], {k, 0, 6}]

enter image description here

with 0 being the contour and 6 the background. But that's images now, geometry of the line is lost. To get it back you could try:

Graphics[Line[PixelValuePositions[EdgeDetect[frag[[-2]]], 1]]]

enter image description here

cool but useless ;-) So we need to order points:

Graphics[Line[#[[FindShortestTour[#][[2]]]] &@ PixelValuePositions[Thinning[EdgeDetect[frag[[-2]]]], 1]]]

enter image description here

To get a smoother line one just need to increase image resolution. All in all too complicated ;-)

POSTED BY: Vitaliy Kaurov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard