tobius / imagecolors Goto Github PK
View Code? Open in Web Editor NEWUse a combination of color quantization algorithms and human fiddling to get human perceivable colors out of an image.
License: MIT License
Use a combination of color quantization algorithms and human fiddling to get human perceivable colors out of an image.
License: MIT License
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
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
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
npm publish
to run whenever a new version tag gets createdSomewhere 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' } ]
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:
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);
}
});
},
Hi Tobius!
This module filters streams as input although gm could take them. I added stream support in my fork. See this commit please: https://github.com/erkstruwe/imagecolors-stream/tree/191937c696e230f680553e7add65c348bd0066b6 .
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.