# How can I import an image, retrieve vertex point values from the shape, and turn that into a list?

I'm using a github repo about turning point data into an array to then create a mirror. The author used a point picker in mathematica, but I want to automate the process. How can I import my image and get vertex values from it?

this is the image

• It would be valuable for you to clarify what you mean by “vertex coordinates”. From your responses to the existing answers, it appears that you want the boundaries of this image, i.e., a list of coordinates that describe the lines that are the boundaries of this image. Commented Nov 13, 2021 at 16:45

Are you looking for a smaller number of coordinates on the boundary of the image? If so, you could convert to a boundary mesh region and extract the coordinates from that.

After importing the image:

mesh = ImageMesh[ColorNegate[img]];
points = MeshCoordinates[mesh];


This gives a list of points on the boundaries of the parts of the image. E.g., to plot those points:

 ListPlot[points, AspectRatio -> Automatic]


• this... this is exactly what I want, but I also need a list of the vertex coordinates. How do I do that? Commented Nov 13, 2021 at 5:08
• The variable 'points' is the list of coordinates. Unless I'm not understanding what you mean by "vertex coordinates".
Commented Nov 13, 2021 at 5:10
• I mean; how can I print a list of the points for copy/pasting? Commented Nov 13, 2021 at 5:12
• Just evaluate "points". It will output a list like {{72.08219949365268, 236.49319696191608}, {74.13043478260869, 245.52173913043475}, ....} which you can then copy.
Commented Nov 13, 2021 at 5:15
• Thank you so much. one more thing; this is how my graph comes out as imgur.com/a/u6QZAfE rather than what yours is. Did I import it wrong? code: Import["i.sstatic.net/dYO3S.png"] as img; Commented Nov 13, 2021 at 5:23

If you need coordinates for the pixels that are black, you can import the image. The information is actually stored in the alpha channel of the image, so we use only that:

img = Binarize@AlphaChannel@Import["https://i.sstatic.net/dYO3S.png"]


Then you can use Position on the image data matrix to get all 1 pixel. I did some transposing and reversing of the matrix so that you get {x,y} coordinates that are in the expected coordinate system:

points = Position[Reverse /@ Transpose[ImageData[img, "Bit"]], 1];
ListPlot[points, AspectRatio -> 1]


• Is there any way I can minimize the number of data points? I want to keep it to a basic shape, because I will be 3d printing this. I do also need the vertex coordinates. Commented Nov 13, 2021 at 4:38
• You can use ImageResize to scale the image down to e.g. 64x64 Commented Nov 13, 2021 at 4:42
• that works, but how do I get the vertex coordinates? I'm very new to mathematica. Commented Nov 13, 2021 at 4:47
• Just use img = Binarize@AlphaChannel@ImageResize[Import["https://i.sstatic.net/dYO3S.png"],64] to load the image. Commented Nov 13, 2021 at 4:53
• Another way to get the coordinates of all the black points in the image: ImageValuePositions[Binarize[ColorNegate@img], 1]