Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/olivierlando/path-from-image
Try to find the shortest path between two points of an image, following pixels matching a given colors pattern.
https://github.com/olivierlando/path-from-image
dijsktra-shortest-path douglas-peucker
Last synced: 4 months ago
JSON representation
Try to find the shortest path between two points of an image, following pixels matching a given colors pattern.
- Host: GitHub
- URL: https://github.com/olivierlando/path-from-image
- Owner: olivierlando
- License: mit
- Created: 2017-09-07T13:16:03.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-09-24T13:55:16.000Z (over 7 years ago)
- Last Synced: 2024-09-18T16:56:14.671Z (5 months ago)
- Topics: dijsktra-shortest-path, douglas-peucker
- Language: JavaScript
- Size: 333 KB
- Stars: 7
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# path-from-image
> 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.
## Installation
```shell
npm install --save path-from-image
```## Basic usage
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 :```js
const fs = require('fs');
const jpeg = require('jpeg-js');
const PathFromImage = require('path-from-image');const bluePointCoords = [62, 413];
const redPointCoords = [514, 39];const image = jpeg.decode(fs.readFileSync('road.jpg'), true);
const pathFromImage = new PathFromImage({
width: image.width,
height: image.height,
imageData: image.data,
colorPatterns: [{ r: [60, 255], g: [0, 70], b: [60, 255] }], // description of the mauve / ping color
});
const path = pathFromImage.path(bluePointCoords, redPointCoords); // => [[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 :

##TODO
- add comments :)
- document all options
- improve perfs