GithubHelp home page GithubHelp logo

tobius / imagecolors Goto Github PK

View Code? Open in Web Editor NEW
28.0 28.0 15.0 6.79 MB

Use a combination of color quantization algorithms and human fiddling to get human perceivable colors out of an image.

License: MIT License

JavaScript 100.00%
colors imagemagick nodejs palette quantization

imagecolors's People

Contributors

tobius avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

imagecolors's Issues

Allow Mask/pngs

I would like to be able to run this on an image with a mask: so ignoring the areas marked by the mask when generating the color pallet. Accepting a mask, or alternately accepting pngs with a mask applied would be very helpful.

Here is what I have tried so far:
-I have tried adding the mask to the image, and giving imagecolors.extract the path to the resulting png with the background set to transparent, however then I receive the error 'Histogram extraction failed’. I see that that means no chunks were detected within the histogram, however I cannot figure out why that is the case.

-I have forked the code within my project and am trying to find a way to mask out the background using imagemagick. I have tried passing in both the mask and the image, and using imagemagick to run im(image path).mask(mask path), then running imagecolors like normal on that, however the background is still not ignored. I still end up extracting colors from the background. Upon further research i discovered imagemagick.mask simply write-protects those pixels, and so doesn’t prevent imagemagic from reading them in the histogram.

-I see that in the non-node version of image graphics the correct way to apply a mask is using composite, and have found this command: convert image.jpeg mask.jpeg -alpha off -compose copy_opacity -composite result.png. I see that in the npm gm you should be able to add custom commands from imagegraphics, however I have not yet been able to get this command to work succesfully.

Any work around suggestions would be appreciated, Thanks!
Vicki

better extractProminentColors

Hi,

Thank you. Your work made my life easier. Just one suggestion:
in extractProminentColors function you are doing :

image = image.noProfile().bitdepth(8).colors(maxPaletteColors);

you can get much much better results if you do
image.noProfile().bitdepth(8).colorspace('YCbCr').colors(maxPaletteColors)).colorspace('sRGB');

because the color quantization algorithm in YCbCr space (using imagemagick) is closer to human perception. Hope this helped

Histogram extraction fails

Hello!
I do a simple static-generator, and I would like to parse dominant image colors. I do

//imagePath is absolute url to jpg, like `/users/df/projects/site/content/images/1.jpg`
imagecolors.extract(imagePath, 2, function (err, colors) {
    if (err) console.log(err);
});

and I get

Histogram extraction failed

Create `tmp` dir if it doesn't exist

Somewhere along the line, a tmp dir is assumed to exist by imagecolors...

$ ls
index.js
node_modules
package.json
photo.jpg

$ cat index.js 
var imagecolors = require('imagecolors');

imagecolors.extract(__dirname + '/photo.jpg', 6, function(err, colors){
  if (err) throw err;
  console.log(colors);
});

$ node index.js 
events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: ENOENT, open '/Users/zeke/Desktop/imagecolors-test/tmp/photo.jpg.miff'

$ mkdir tmp

$ node index.js 
[ { pixels: 302810,
    hex: '#33BACD',
    labelHex: '#444444',
    rgb: { r: 51, g: 186, b: 205 },
    hsv: { h: 187, s: 75, v: 80 },
    hsl: { h: 187, s: 61, l: 50 },
    luminance: '0.62',
    cmyk: { c: 75, m: 9, y: 0, k: 20 },
    percent: 14.6,
    family: 'blue' },
  { pixels: 674503,
    hex: '#52525F',
    labelHex: '#BBBBBB',
    rgb: { r: 82, g: 82, b: 95 },
    hsv: { h: 240, s: 14, v: 37 },
    hsl: { h: 240, s: 7, l: 35 },
    luminance: '0.33',
    cmyk: { c: 14, m: 14, y: 0, k: 63 },
    percent: 32.53,
    family: 'blue' },
  { pixels: 279434,
    hex: '#B251A1',
    labelHex: '#BBBBBB',
    rgb: { r: 178, g: 81, b: 161 },
    hsv: { h: 311, s: 54, v: 70 },
    hsl: { h: 311, s: 39, l: 51 },
    luminance: '0.42',
    cmyk: { c: 0, m: 54, y: 10, k: 30 },
    percent: 13.48,
    family: 'violet' },
  { pixels: 198365,
    hex: '#C54528',
    labelHex: '#BBBBBB',
    rgb: { r: 197, g: 69, b: 40 },
    hsv: { h: 11, s: 80, v: 77 },
    hsl: { h: 11, s: 66, l: 46 },
    luminance: '0.37',
    cmyk: { c: 0, m: 65, y: 80, k: 23 },
    percent: 9.57,
    family: 'red' },
  { pixels: 343436,
    hex: '#D7D6C8',
    labelHex: '#444444',
    rgb: { r: 215, g: 214, b: 200 },
    hsv: { h: 56, s: 7, v: 84 },
    hsl: { h: 56, s: 16, l: 81 },
    luminance: '0.84',
    cmyk: { c: 0, m: 0, y: 7, k: 16 },
    percent: 16.56,
    family: 'yellow' },
  { pixels: 275052,
    hex: '#DFB232',
    labelHex: '#444444',
    rgb: { r: 223, g: 178, b: 50 },
    hsv: { h: 44, s: 78, v: 87 },
    hsl: { h: 44, s: 73, l: 54 },
    luminance: '0.70',
    cmyk: { c: 0, m: 20, y: 78, k: 13 },
    percent: 13.26,
    family: 'orange' } ]

When a non-existing file is given, the error handling is not executed

Hi,

I think I found a small error in your code.
The way the fileExists is handled is not working when the file doesn't exist.

I suggest the following change in the main.js for the following reasons:

  1. the sync call is removed, better not to block IO
  2. when a file isn't found a nice error is given back
    convertPathToImage: function(path, callback){
        fs.lstat(path, function(err, stats) {
            if (err){
                return callback(err,null); 
            };
            if (path.match(/^htt/) || stats.isFile()){
                return callback(undefined, im(path));
            }
            else {
                callback(new Error('Unable to quantify image path'), null);    
            }
        });
    },

Add PR Templates

  • Add PR template for bug reports
  • Add PR template for feature requests

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.