Try to find the shortest path between two points of an image, following pixels matching a given colors pattern. Usefull to find the shortest path between two locations on a map, by following roads.
npm install --save path-from-image
Let's consider the following image:
Our goal is to find the shortest path from the blue point to the red one, following the mauve / pink roads. Here is how to do that :
const fs = ;const jpeg = ;const PathFromImage = ;const bluePointCoords = 62 413;const redPointCoords = 514 39;const image = jpeg;const pathFromImage =width: imagewidthheight: imageheightimageData: imagedatacolorPatterns: r: 60 255 g: 0 70 b: 60 255 // description of the mauve / ping color;const path = pathFromImage; // => [[62, 413], [63, 406], [69, 390], ...]
path holds the list of coordinates that connect the blue points to the red one. These points are represented in blue on the following image :