How to use the ml-matrix function in ml-matrix

To help you get started, weā€™ve selected a few ml-matrix examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github image-js / image-js / src / image / morphology / __tests__ / close.js View on Github external
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,
github image-js / image-js / src / image / morphology / __tests__ / dilate.js View on Github external
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,
github image-js / image-js / src / image / morphology / __tests__ / topHat.js View on Github external
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,
github image-js / image-js / src / image / morphology / __tests__ / open.js View on Github external
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,
github image-js / image-js / src / image / morphology / __tests__ / morphologicalGradient.js View on Github external
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,
github image-js / image-js / src / image / morphology / __tests__ / blackHat.js View on Github external
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,
github image-js / image-js / src / image / utility / getMatrix.js View on Github external
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;
}