Skip to content

This library contains basic matrix process, Please contact with me if you contribute to this project. ergen5171@gmail.com

License

Notifications You must be signed in to change notification settings

gokhanergen-tech/core_matrixjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

matrixjs-core



Goal


The goal is that providing matrix processes which is neccesary for linear algebra or others



Matrix Class

  • constructor(matrix: number[][], dataType: dataTypes = "Float64")
  • public transpose(): Matrix
  • public getX(): number
  • public getY(): number
  • public set(x: number, y: number, number: number): void
  • public convertNumberToDataType(number: number, dataType: dataTypes): number
  • public getTypedArray():MatrixType
  • public get type(): string
  • public clone(): number[][]
  • public convertDataType(dataType: dataTypes): number[][] | undefined to Matrix class
  • dataType can be "Float64" | "Float32" | "UInt8" | "UInt16" | "UInt32" | "Int8" | "Int16" | "Int32"
  • public write(options?)
  • options { rows?: { start?: number, end?: number }, cols?: { start?: number, end?: number } }

Matrix Inherited Processes

  • public static constArithmeticProcess(matrix: Matrix, num: number, process: "mul" | "div" | "sub" | "sum", fixed?: number): Matrix
  • public static multiply(matrixFirst: Matrix, matrixSecond: Matrix, options?: ArithmeticProps): Matrix
  • options { fixed?: number }
  • public static sum(matrixFirst: Matrix, matrixSecond: Matrix, options?: ArithmeticProps): Matrix
  • options { fixed?: number }
  • public static sub(matrixFirst: Matrix, matrixSecond: Matrix, options?: ArithmeticProps): Matrix
  • options { fixed?: number }
  • public static generateMatrix(options: GenerateMatrixProps): Matrix
  • options { x: number, y: number, fixed?: number, dataType?: dataTypes, scala: { max: number, min: number } }
  • public static ifso(matrix: Matrix, queryFunc: (value: number) => boolean, doFunc: (value: number) => number, doFalseFunc?: (value: number) => number): Matrix
  • public static eye(y:number,x:number):Matrix
  • public static fill(x:number,y:number,number:number):Matrix

Installation

npm i matrixjs-core

Usage

const {Matrix} =require("matrixjs-core")

let matrix=new Matrix([[1,1,1],[1,2,3]])
Matrix.constArithmeticProcess(matrix,3,"mul",2)

Image Processing With jimp

import { Matrix } from './index' import * as jimp from 'jimp' const rgbToGray=async ()=>{ const myarray:number[][] = [];
await new Promise<any>(resolve=>{
    jimp.read("test.jpg").then((image:any) => {
        let k=0;
        let row:number[]=[]
        image.scan(0, 0, image.bitmap.width, image.bitmap.height, function (x:number, y:number, idx:number) {
        
            row.push(Math.round(image.bitmap.data[idx + 0]*0.3+image.bitmap.data[idx + 1]*0.59+image.bitmap.data[idx + 2]*0.11));
            k++;
            if(k===1280){
                myarray.push(row);
                k=0;
                row=[]
            }
            
           })
        resolve("ok");
    })
  
})
return myarray;

} const createImage=(path:string,x:number,y:number,array:number[][])=>{ const test=new jimp(x,y); const bitmap=test.bitmap;

const fleatted=array.flat();
let i=0;
test.scan(0, 0, x, y, function (_x:number,_y:number, idx:number) {
   
    bitmap.data[idx + 0] = fleatted[i]
    bitmap.data[idx + 1] = fleatted[i]
    bitmap.data[idx + 2] = fleatted[i]
    bitmap.data[idx + 3] = 255
    i++;
   })
test.writeAsync(path);   

}

const init=async ()=>{ const img=new Matrix(await rgbToGray() as number[][],"UInt8");
const croppedImage=img.filter({
    rows:{
      start:200,
      end:500
    },
    cols:{
      start:0,
      end:500
    }
})



createImage("aa.jpg",croppedImage.getX(),croppedImage.getY(),croppedImage.clone());

}

init();

Version 1.0.5-BETA

    Deprecated
  • getMatrix() from Matrix class
    News
  • added 'type' property to Matrix class
  • Matrix constructor changed to constructor(matrix: number[][], dataType: dataTypes = "Float64") from constructor(matrix: number[][])
  • added public convertDataType(dataType: dataTypes): number[][] | undefined to Matrix class
  • added generateMatrix method with dataType
  • added Data types like "Float64" | "Float32" | "UInt8" | "UInt16" | "UInt32" | "Int8" | "Int16" | "Int32"
  • added public getTypedArray():MatrixType method to Matrix class
  • MatrixType Uint16Array | Uint8Array | Uint32Array | Int32Array | Int8Array | Int16Array | Float32Array | Float64Array | null

Version 1.0.5

  • added public set(x: number, y: number, number: number): void
  • added public convertNumberToDataType(number: number, dataType: dataTypes): number
  • added public static eye(y:number,x:number):Matrix
  • added public static fill(x:number,y:number,number:number):Matrix

Version 1.0.53

  • Fixed setting value problem

Version 1.0.6

  • Solved Maximum call stack size exceeded problem
  • Solved shallow clone problem
  • Added ravel function
  • Added filter function

About

This library contains basic matrix process, Please contact with me if you contribute to this project. ergen5171@gmail.com

Resources

License

Stars

Watchers

Forks

Packages

No packages published