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
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI'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
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]
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.stack.imgur.com/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]
ImageResize
to scale the image down to e.g. 64x64
$\endgroup$
img = Binarize@AlphaChannel@ImageResize[Import["https://i.stack.imgur.com/dYO3S.png"],64]
to load the image.
$\endgroup$