# image-score-js

This package provide image scoring functions. 

Currentry provided functions is belows.

- PSNR 
- SSIM

This package include three edition. The file size is different, so please choose one depneding on your usecase.
- WASM
- WASM SIMD
- WASM and WASM SIMD

Sample source code is [here](https://github.com/w-okada/image-score-js-demo)

# Installation and basic usage
## Instalattion

```
npm install @dannadori/imager-score-js

```

## Importing to your application

1. WASM edition
```
import { ImageScoreWasm } from '@dannadori/image-score-js/dist/image-score-wasm'
```

2. WASM SIMD edition
```
import { ImageScoreWasmSimd } from '@dannadori/image-score-js/dist/image-score-wasm-simd'

```


3. WASM and WASM SIMD edition
```
import { ImageScore } from '@dannadori/image-score-js'

```
## Initialize
```
const is = new ImageScore() // If you use othere edition, you should change
is.init()
```

# Functions 
## PSNR and SSIM
PSNR and SSIM are implemented according to [this article](https://docs.opencv.org/4.5.2/d5/dc4/tutorial_video_input_psnr_ssim.html)

At first you put two image(HTMLCanvasElement) by setImage, then call psnr or mssim.
```
setImage: (image1: HTMLCanvasElement, image2: HTMLCanvasElement, params: ImageScoreParams) => void;
psnr: (params: ImageScoreParams) => number;
mssim: (params: ImageScoreParams) => {
        mssimR: number;
        mssimG: number;
        mssimB: number;
        mssimA: number;
};
```

ImageScoreParams have useSimd attribute. Only when you use  WASM and WASM SIMD edition, this value is used. Otherewise, ignored
```
export interface ImageScoreParams {
    useSimd: boolean;
}

```

