This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Usage
Oscar edited this page Oct 25, 2016
·
10 revisions
Using ssim
is simple. You can pass two images (paths, buffers or urls) to ssim
and it will return a promise with the resulting mean ssim (mssim
). For instance:
import ssim from 'ssim.js';
ssim('./img1.jpg', './img2.jpg')
.then(out => console.log(`SSIM: ${out.mssim} (generated in: ${out.performance}ms)`))
.catch(err => console.error('Error generating SSIM', err));
See it in action here.
You can specify any additional options as a 3rd parameter. Something like:
import ssim from 'ssim.js';
ssim('./img1.jpg', './img2.jpg', { downsample: 'fast' })
The parameters section details all options available.
You can pass a 3rd parameter containing a plain object and any of the following options:
Parameter | Default | Description |
---|---|---|
windowSize | 11 | window size for the SSIM map |
k1 | 0.01 | The first stability constant |
k2 | 0.03 | The second stability constant |
bitDepth | 8 | The number of bits used to encode each pixel |
downsample | 'original' |
false / 'original' / 'fast'
|
ssim | 'fast' |
'original' / 'fast'
|
- Setting
k1
ork2
to0
will use UQI (Universal Quality Index) since it's a subset of SSIM (when C1 or C2 are 0) - When using
canvas
images will be retrieved as 8 bits/channel. You can use thebitDepth
parameter to modify how SSIM computes the value but it will have no effect on how the image is read - There are several downsampling options:
-
false
: disables downsizing -
'original'
: (default) implements the same downsizing than the original Matlab scripts -
fast
: relies on thecanvas
to do the downsizing (may lead to different results)
-
- There are several 'ssim' options:
-
'original'
: Uses a line-by-line port of the Matlab scripts and attempts to match them as closely as possible -
'fast'
: (default) Uses a mathematically equivalent approach to 'original' but it's faster. By not focusing on a line-by-line port, it uses two 1-dimensional filters instead of a 2-D gaussian which results on a 2-3x performance improvement.
-
Parameter | Description |
---|---|
mssim | Mean SSIM, the average of all ssim_map values |
ssim_map | An array of arrays containing the ssim value at each window |
performance | The total time to compute SSIM (in milliseconds) |
To view the steps taken to validate the results, check the wiki page here.