-
Notifications
You must be signed in to change notification settings - Fork 64
/
open.js
50 lines (44 loc) · 1.2 KB
/
open.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Image } from 'test/common';
import Matrix from 'ml-matrix';
describe('check the open function', function () {
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,
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,
[
255, 255, 255, 255, 255,
255, 255, 0, 255, 255,
255, 0, 0, 0, 255,
255, 255, 0, 255, 255,
255, 255, 255, 255, 255
],
{ kind: 'GREY' }
);
expect(Array.from(image.open({ kernel, iterations: 2 }).data)).toEqual([
255, 255, 0, 255, 255,
255, 255, 0, 255, 255,
0, 0, 0, 0, 0,
255, 255, 0, 255, 255,
255, 255, 0, 255, 255
]);
});
});