1

Rick Sanchez from Rick and Morty

How can I get an array of coordinates of the edge of Rick in order from left to right? I want to make my delta robot draw images.

Additionally, I know that it is possible for Wolfram Alpha to generate a fairly long parametric equation if you ask it to for example "Draw Dratini", is there any way to get an array of coordinates from this?

Thanks!

MarcoB
  • 67,153
  • 18
  • 91
  • 189
Jenny
  • 559
  • 2
  • 9

1 Answers1

3

I'm not sure that I fully understand what you need, but perhaps the following will help you get started.

First, import the picture:

img = Import["https://vignette4.wikia.nocookie.net/rickandmorty/images/d/dd/Rick.png/revision/latest?cb=20131230003659"]

figure

Then find the outer edge:

edge = EdgeDetect@ColorQuantize[img, 1]

Mathematica graphics

Finally, find the position of white pixels in the edge image:

edgepoints = Position[ImageData[edge], 1]

(* Out:

{{1, 85}, {1, 88}, {1, 89}, {2, 85}, {2, 89}, {2, 90}, {3, 85}, {3, 90}, ...}

*)

If you want only some of those points, then you can pick e.g. every other point from those results:

edgepoints[[1 ;; All ;; 2]]
MarcoB
  • 67,153
  • 18
  • 91
  • 189
  • If I want half as many points, would I change that 1 to a different number? – Jenny Jan 25 '16 at 05:12
  • @Jenny No, the $1$ directs position to find the white pixels in the image, that are represented by a 1 value. If you want half as many points, you could pick e.g. every other point from the result (see edit). – MarcoB Jan 25 '16 at 05:21
  • Note that Position[ImageData[...]] returns indices, not coordinates. (The distinction is a bit confusing in MMA image processing, see for example: http://mathematica.stackexchange.com/a/104047/242). Use PixelValuePositions[edge, 1] to get the coordinates. Rule of thumb: If you want to manipulate the raw array returned by ImageData, use indices. If you want to draw something over the image using e.g. Show, use coordinates – Niki Estner Jan 25 '16 at 07:58
  • @nikie Ha! Excellent point! I had not realized that. Thank you for pointing that out. – MarcoB Jan 25 '16 at 08:40
  • Perhaps you could keep points with density proportional to the curvature.See @nikie's answer http://mathematica.stackexchange.com/questions/95425/can-i-get-the-curvature-at-any-point-of-a-random-curve/95442#95442 – Dr. belisarius Jan 30 '16 at 18:24