Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('check for GREY image 5x5', function () {
let kernel = new Matrix([[1, 1, 1], [1, 1, 1], [1, 1, 1]]);
let image = new Image(5, 5,
[
255, 255, 0, 255, 255,
255, 0, 0, 0, 255,
255, 0, 0, 0, 255,
255, 0, 0, 0, 255,
255, 255, 0, 255, 255
],
{ kind: 'GREY' }
);
expect(Array.from(image.close({ kernel }).data)).toEqual([
255, 255, 255, 255, 255,
255, 0, 0, 0, 255,
255, 0, 0, 0, 255,
255, 0, 0, 0, 255,
it('check for GREY image 5x5', function () {
let kernel = new Matrix([[1, 1, 1], [1, 1, 1], [1, 1, 1]]);
let image = new Image(5, 5,
[
255, 0, 0, 0, 255,
255, 0, 0, 0, 255,
255, 0, 0, 0, 255,
255, 0, 0, 0, 255,
255, 0, 0, 0, 255
],
{ kind: 'GREY' }
);
expect(Array.from(image.dilate({ kernel: kernel }).data)).toEqual([
255, 255, 0, 255, 255,
255, 255, 0, 255, 255,
255, 255, 0, 255, 255,
255, 255, 0, 255, 255,
it('check for GREY image 5x5', function () {
let kernel = new Matrix([[1, 1, 1], [1, 1, 1], [1, 1, 1]]);
let image = new Image(5, 5,
[
0, 0, 255, 0, 0,
0, 255, 255, 255, 0,
0, 255, 255, 255, 0,
0, 255, 255, 255, 0,
0, 0, 255, 0, 0
],
{ kind: 'GREY' }
);
expect(Array.from(image.topHat({ kernel: kernel }).data)).toEqual([
0, 0, 255, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
it('check for GREY image 5x5', function () {
let kernel = new Matrix([[1, 1, 1], [1, 1, 1], [1, 1, 1]]);
let image = new Image(5, 5,
[
255, 255, 0, 255, 255,
255, 0, 0, 0, 255,
255, 0, 0, 0, 255,
255, 0, 0, 0, 255,
255, 255, 0, 255, 255
],
{ kind: 'GREY' }
);
expect(Array.from(image.open({ kernel }).data)).toEqual([
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
it('check for GREY image 5x5 2 iterations', function () {
let kernel = new Matrix([[1, 1, 1], [1, 1, 1], [1, 1, 1]]);
let image = new Image(5, 5,
[
0, 255, 255, 255, 0,
0, 255, 255, 255, 0,
0, 255, 255, 255, 0,
0, 255, 255, 255, 0,
0, 255, 255, 255, 0
],
{ kind: 'GREY' }
);
expect(
Array.from(image.morphologicalGradient({ kernel: kernel, iterations: 2 }).data)
).toEqual([
0, 255, 255, 255, 0,
0, 255, 255, 255, 0,
it('check for GREY image 5x5 2 iterations', function () {
let kernel = new Matrix([[1, 1, 1], [1, 1, 1], [1, 1, 1]]);
let image = new Image(5, 5,
[
0, 0, 255, 0, 0,
0, 255, 255, 255, 0,
0, 255, 255, 255, 0,
0, 255, 255, 255, 0,
0, 0, 255, 0, 0
],
{ kind: 'GREY' }
);
expect(Array.from(image.blackHat({ kernel: kernel, iterations: 2 }).data)).toEqual([
0, 0, 255, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
export default function getMatrix(options = {}) {
let { channel } = options;
this.checkProcessable('getMatrix', {
bitDepth: [8, 16]
});
if (channel === undefined) {
if (this.components > 1) {
throw new RangeError('You need to define the channel for an image that contains more than one channel');
}
channel = 0;
}
let matrix = new Matrix(this.height, this.width);
for (let x = 0; x < this.height; x++) {
for (let y = 0; y < this.width; y++) {
matrix.set(x, y, this.getValueXY(y, x, channel));
}
}
return matrix;
}