I have a set of coordinates that I need a robot to draw, thus it must take the shortest path along these coordinates. Plotting them looks like this:
Graphics[Point[maskCoordinates]]
EDIT: maskCoordinates
is derived from the following code, which runs EdgeDetect
and ComponentMeasurements
on any given image, and for this example works with the first mask:
intWidth = 100;
imgCar = Import["https://2hire.io/wp-content/uploads/2016/12/car.png"];
imgCar = ColorConvert[imgCar, "Grayscale"];
imgCar = ImageResize[imgCar, intWidth];
edges = Thinning@EdgeDetect@imgCar;
masks = ComponentMeasurements[edges, "Mask"];
maskCoordinates = PixelValuePositions[Image@masks[[1, 2]], 1];
I have tried using FindShortestTour
, but that only works for "complete" shapes/masks that I'm working with, like a circle. So applying this to the given mask, I get:
Graphics[Line[maskCoordinates[[Last[FindShortestTour[maskCoordinates]]]]]]
Which is close, but not exactly what I want. I thought that FindShortestPath
would get the job done, but haven't had any succes with that yet.
maskCoordinates
. $\endgroup$FindCurvePath
? $\endgroup$Nearest
local point at each step, rather than the global shortest path? $\endgroup$maskCoordinates
doesn't work with the first image from the question. Please provide the explicit set of points or the original imageimgCar
to which the code should be applied. $\endgroup$