1
$\begingroup$

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!

$\endgroup$
3
$\begingroup$

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]]
$\endgroup$
  • $\begingroup$ If I want half as many points, would I change that 1 to a different number? $\endgroup$ – Jenny Jan 25 '16 at 5:12
  • $\begingroup$ @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). $\endgroup$ – MarcoB Jan 25 '16 at 5:21
  • $\begingroup$ Note that Position[ImageData[...]] returns indices, not coordinates. (The distinction is a bit confusing in MMA image processing, see for example: 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 $\endgroup$ – Niki Estner Jan 25 '16 at 7:58
  • $\begingroup$ @nikie Ha! Excellent point! I had not realized that. Thank you for pointing that out. $\endgroup$ – MarcoB Jan 25 '16 at 8:40
  • $\begingroup$ Perhaps you could keep points with density proportional to the curvature.See @nikie's answer mathematica.stackexchange.com/questions/95425/… $\endgroup$ – Dr. belisarius Jan 30 '16 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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