Coder Social home page Coder Social logo

rgbanalyse's Introduction

RGBAnalyse

An RGB-HC histogram library for same-origin images

demonstrator gh-page: http://pomax.github.io/RGBAnalyse

Client-side installation: simply grab the library from the release directory on github, or use bower to install: bower install rgbanalyse.

Node package installation: npm install rgbanalyse.

API

The library sets up an object with the following properties/functions:

  • defaults - a settings object with default values as analysis options.
  • analyse(img,[options]) - performs image analysis on an image element, with optional tweaks.
  • computeHSL(R,G,B) - convert RGB to HSL (note this requires normalised RGB values).
  • computeRGB(H) - convert HSL (no S/L right now) to RGB, H in range [0,6.28].
  • analyse(img,[options]) - convert HSL to rgb (plain {r,g,b}, using range [0,255]).

The defaults object can be set prior to running analyses, and currently supports the following properties:

  • neutrals - 10 - integer from 0 to 255, indicating the how close together {r,g,b} coordinates must be to be considered neutral
  • smoothing - 5 - used to smooth the hue spectrum when determining dominant hues. (value is distance from mean)
  • distance - 10 - minimum distance between recording two hues to end up recorded as major hues (value can range from 0 to 628)

The analyse function returns a two property object. The first is the analysis property, which houses:

  • rgb - A 3 component object with the histographical data for r, g and b.
  • RGB - A 3 component object with the histographical data for R, G,a nd B.
  • hsl - An object with the histographical data for h, and .dominant, a sorted array of {H,strength} major hues.
  • average - the weighted averages for r, g, b, R, G, B, and h.
  • maxima - the absolute maxima for r, g, b, R, G, B, and h.

The second is the visualization property, available only when using the libary in the browser, which houses image source data-uris for:

  • histogram - a 256 x 256 combined rgb histogram
  • spectrum.histogram - a 360 x 200 hues histogram
  • spectrum.spectogram - a 360 x 50 spectrogram

LICNSE

This code is released as Public Domain code. In jurisdictions that do not recognise the public domain, this code is to be considered under an MIT license (http://opensource.org/licenses/MIT)

rgbanalyse's People

Contributors

pomax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

rgbanalyse's Issues

Document Node usage

Hi. This package already can be used in node, as RGBAnalyse.analyse takes either an HTMLCanvasElement or a path as the first argument. May be a good idea to document this for new users.

Cannot analyze mozjpeg encoded images

This image is generated using sharp, which uses libvips built with mozjpeg:

sharp(buffer)
    .resize(maxWidth, maxHeight)
    .interpolateWith(sharp.interpolator.bicubic)
    .max()
    .withoutEnlargement()
    .withMetadata()
    .trellisQuantisation()
    .toFile(...);

andaman-shore 1x

RGBAnalyse.analyse seems to fail silently. I did a quick check, [email protected] seems to be able to read the image into buffer.

make dominant hue smoothing interval defaults-controlled

right now it runs over point+/-5, it'd be good to change that to point+/-defaults.smoothing so that a more accurate dominant hue can be found by checking various smoothing values to rule out spikes over various intervals.

Add hue-at-the-edge detection

It'd be cool to take an image and find the hue at the edges of the image in order to pick a suitable border / background for the image. :D

Support buffer for image argument

Hi, sometimes image file is already read into a buffer, such as when using RGBAnalyse as a step of a gulp pipeline. It'll be nice to not have to read the file again. E.g.:

through.obj(function (chunk, encoding, next) {
    RGBAnalyse.analyse(
        chunk.contents, // buffer
        {neutrals: 20, smoothing: 25, distance: 20},
        function (err, data) {
            console.log(data.analysis.hsl);
        });
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.