0
$\begingroup$

a busy cat

I want to add dots to the maze so far I know only how to get one dot on the maze. I don't know if there is way without using coordinates.

So it would look like this with the dots added

a busy cat
(source: trelford.com)

$\endgroup$

closed as unclear what you're asking by Mr.Wizard Mar 8 '17 at 13:21

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ This question seems to be too broad or unclear in isolation. Please include the context necessary to make sense of the question. $\endgroup$ – Mr.Wizard Dec 6 '16 at 1:58
11
$\begingroup$

I feel this answer is as sensible as the question.

First, binarise the image:

m = Import["maz1.jpg"]
bin = Opening[ColorNegate@Binarize[m], 6]

1

Find the biggest white space, and thin it into a skeleton

thin = Thinning[SelectComponents[bin, "Count", -1], Method -> "MedialAxis"]

2

I used "MedialAxis" here to make it squarer, at the cost of extra bits hanging off. But we'll trim those later.

Turn it into a graph:

g = MorphologicalGraph[thin, VertexSize -> 4, VertexStyle -> Yellow]

3

Extract the coordinates of the vertices:

vertices = VertexCoordinates /. AbsoluteOptions[g, VertexCoordinates];
vrules = Sort[Rule @@@ Transpose[{VertexList[g], vertices}]];

Pick out the edges that don't have a vertex of degree 1:

bad = Pick[VertexList[g], VertexDegree[g], 1];
good = Select[EdgeList[g], ! MemberQ[bad, First@#] && ! MemberQ[bad, Last@#] &];

Calculate dots along each good edge at a vaguely even spacing:

dots = Union@Flatten[Module[{a = #1 /. vrules, b = #2 /. vrules, d},
      d = 1 + 1/10 Round[EuclideanDistance[a, b], 10];
      a + #/d (b - a) & /@ Range[0, d]] & @@@ good, 1];

Show[m, Graphics[{Yellow, Point /@ dots}]]

4

$\endgroup$

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