1.0.4 • Published 7 years ago
image-lut v1.0.4
image-lut
Image Lookup Table library for Node.js
Install
$ npm install image-lut
Examples
See the examples folder or test.js for how to use the image-lut.
###Countries Lookup by Lat/Lon
An image with the countries of the world is used to look up country names by latitude/langitude. The image has to be equirectangular projected and every country has to have an unique RGB value.
var ImageLUT = require('image-lut').ImageLUT;
var lut = new ImageLUT();
var countries = {
// "R/G/B/A" -> value
"138/138/138/255": "Luxembourg",
"82/82/82/255": "United Kingdom"
};
lut.init(countries, "../data/countries.png", function (err) {
// optional, set input domain of image coordinates
lut.domain(-180, 180, 83.6341007, -90);
console.log( lut.lookup(6.074,49.787) ); // Luxembourg
console.log( lut.lookup(0,52) ); // United Kingdom
});
(examples/countries.js)
API
ImageLUT
.init(dict, imagePath, callback)
.initSync(dict, imagePath)
.domain(xStart, xEnd, yStart, yEnd)
optional, like d3.domain to set the input domain of the coordinates of the image.lookup(x,y)
-> value.color(x,y)
-> r,g,b,a array.size()
-> image width, hight and channels count.pixel(x,y)
-> RBGA values 4 x 8bit encoded into a single number
Helpers
numberToRgb(rgba)
-> r,g,b,a arrayrgbToNumber(r, g, b, a)
-> rgba number
Tests
$ npm install
$ npm test
Acknowledgments
- image-lut is based on the ideas of Images as datastore by Moritz Stefaner and Stephan & Steffen from Studio NAND
- png reading via pngparse