voluptasquisquam
Version:
Image processing and manipulation in JavaScript
72 lines (55 loc) • 2.09 kB
JavaScript
import {Image} from 'test/common';
import 'should';
describe('calculate the histogram', function () {
it('check getHistogram method', function () {
let image = new Image(1, 2, [230, 83, 120, 255, 100, 140, 13, 1]);
let histogram = image.getHistogram({useAlpha: false, channel: 0});
histogram[0].should.equal(0);
histogram[100].should.equal(1);
histogram[230].should.equal(1);
histogram[255].should.equal(0);
histogram = image.getHistogram({useAlpha: false, channel: 2});
histogram[0].should.equal(0);
histogram[13].should.equal(1);
histogram[120].should.equal(1);
histogram[255].should.equal(0);
});
it('check histogram property', function () {
let image = new Image(1, 4, [230, 255, 230, 255, 230, 255, 13, 1], {
kind: 'GREYA'
});
let histogram = image.histogram;
histogram[0].should.equal(0);
histogram[1].should.equal(0);
histogram[13].should.approximately(0.0039, 0.0001);
histogram[100].should.equal(0);
histogram[230].should.equal(3);
histogram[255].should.equal(0);
});
it('check 16 slots histogram', function () {
let image = new Image(1, 4, [230, 255, 230, 255, 230, 255, 13, 1], {
kind: 'GREYA'
});
let histogram = image.getHistogram({maxSlots: 16});
histogram[0].should.approximately(0.0039, 0.0001);
histogram[1].should.equal(0);
histogram[14].should.equal(3);
histogram[15].should.equal(0);
});
it('check histogram for 1 bit image', function () {
let image = new Image(5, 5,
[
0, 0, 0, 0, 0,
0, 255, 255, 255, 0,
0, 255, 255, 255, 0,
0, 255, 255, 255, 0,
0, 0, 0, 0, 0
],
{kind: 'GREY'}
);
let image2 = image.mask();
let histogram = image2.getHistogram();
histogram[0].should.eql(16);
histogram[1].should.eql(9);
});
});