New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pixfinder

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pixfinder

Javascript library for extracting objects from images

  • 0.2.1
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Pixfinder is a JavaScript library for object detection.

Table of Contents

  • Demos
  • How it works
  • API
  • Development
  • Changelog

Demos

See live demos here:

How it works

Pixfinder analyzes image and extracts coordinates of each object. Objects should be detected by several criteria, the most important of which is the color.

For example we have aerial shot of planes and want to know how many planes at the airport right now:

To solve this problem we need to write several lines of code and pixfinder will find all planes in the image. So, let's find all planes and draw them all on canvas:

var img = document.getElementById('img');

pix.util.dom.onload(img, function() {
    var planes = pix.findAll({
        img: img,
        distance: 5,
        colors: ['eff1f0'],
        clearNoise: 50
    });
    document.getElementById('count').innerHTML = planes.length;
    planes.forEach(draw);
});

function draw(plane) {
    var ctx = document.getElementById("canv").getContext("2d");
    ctx.beginPath();
    plane.forEach(function(point) {
        ctx.arc(point.x, point.y, 1, 0, 2 * Math.PI);
    });
    ctx.stroke();
    ctx.closePath();
}

Result:

API

findAll

Search all objects in image.

FunctionReturnDescription
pix.findAll(<Object> options) Array Detects objects by given options.
options
OptionTypeDefaultDescription
imgHTMLImageElement | HTMLCanvasElementLoaded image or canvas element which has to be analyzed.
colorsArrayColors of the objects that should be found.
toleranceNumber50Permissible variation of the color (number of shades). Helps to detect objects not only by strict colors (colors option), but by their shades too.
accuracyNumber2If accuracy = 1 then Pixfinder analyzes each pixel of the image, if accuracy = 2 then each 2nd pixel, etc. Large number for better performance and worse quality and vice versa. Number should be positive integer.
distanceNumber10Distance between objects (in pixels). During image analysis Pixfinder detects all pixels according to specified colors and then splits them to several objects by distance. If distance between two pixels lesser then this option then pixels belong to the same object.
clearNoiseBoolean | NumberfalseRemoves all small objects after image analysis. If false then noise clearing is disabled, else if number is setted then all objects that contains less than specified number of pixels will be removed.

find

Starts searching from the start point and returns one object that belongs to this point. This method should be useful for example if you want to highlight building under the mouse cursor.

FunctionReturnDescription
pix.find(<Object> options) Array Returns points of the object that belongs to the startPoint.
options
OptionTypeDefaultDescription
imgHTMLImageElement | HTMLCanvasElementLoaded image or canvas element which has to be analyzed.
colorsArrayColors of the objects that should be found.
startPointPointPoint from which to start the object pixels search.
toleranceNumber50Permissible variation of the color (number of shades). Helps to detect objects not only by strict colors (colors option), but by their shades too.
distanceNumber10Distance between objects (in pixels). If distance between two pixels lesser then this option then Pixfinder thinks that pixels belong to the same object.

util.dom

Various DOM utility functions.

MethodReturnsDescription
onload(<HTMLImageElement> img, <Function> func)Calls func function when img image has been loaded.
loaded(<HTMLImageElement> img)BooleanChecks or img image has been loaded.

Point

Contains information about point.

PropertyTypeDescription
xNumberThe x coordinate.
yNumberThe y coordinate.

To-do

  • write more demos;
  • improve performance.

Development

npm install     # install dependencies
npm gulp build  # check the code with JSHint, run tests and build dist
npm gulp        # build and watch for the src changes

Changelog

0.2.1 — 27.10.2014

  • Readme fixes

0.2.0 — 27.10.2014

  • API changes without backward compatibility

0.1.0 — 16.05.2014

  • First Pixfinder release (unstable alpha version)

Keywords

FAQs

Package last updated on 27 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc