Skip to content

b-g/image-lut

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image-lut

Image Lookup Table library for Node.js

Build Status

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

countries_small

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] array
  • rgbToNumber(r, g, b, a) -> rgba number

Tests

$ npm install
$ npm test

Acknowledgments