0.5.0 • Published 6 years ago
ndarray-imhist v0.5.0
ndarray-imhist
A package to plot grayscale images' histograms using node.js and Gnuplot, inspired by Matlab imhist command.
Installation
npm install ndarray-imhistGnuplot is required for this package to work. Make sure that it is installed and added to the path correctly by typing:
gnuplot --versionUsage
Syntax
imhist(img [, options]);
// or
let [x, y] = imhist(img [, options]);displays the histogram of a grayscale image img (should be an ndarray) and return the historgram data as an array of two arrays containing x and y values respectively.
Options
| Option | required | default | description |
|---|---|---|---|
| channel | no | 0 | Select the RGB channel to get the historgram for. 0 for the red channel, 1 for the green and 2 for the blue one. If img is a 2D array, this option has no effect. |
| color | no | "blue" | Set the impulses color, must be a valid Gnuplot "rgbcolor". Otherwise, plotting will fail silently |
| plot | no | true | If true, plot the histogram using Gnuplot. Otherwise, return just the histogram data. |
Examples
const getPixels = require("get-pixels");
const imhist = require("ndarray-imhist");
getPixels("lena.png", function(err, pixels) {
if(!err && pixels) {
// show the image histogram
imhist(pixels);
// return the image histogram data without plotting it.
let [x, y] = imhist(pixels, {plot: false});
console.log(x, y);
}
})Here is how the histogram will look like:
