ssim.js is a JavaScript library that provides an implementation of the Structural Similarity Index (SSIM) algorithm, which measures the perceived similarity between two images. Unlike traditional metrics like PSNR or MSE, SSIM correlates more closely with human visual perception, yielding a score between 0 and 1, where 1 indicates perfect similarity. The library also supports MSSIM (Multi-scale SSIM) and can generate SSIM maps. The current stable version is 3.5.0, with releases occurring infrequently, often several months apart, as seen from the recent release history. Its key differentiator is providing a readily available, pure JavaScript SSIM implementation suitable for both Node.js and browser environments, often used in image processing, quality assessment, and content-based image retrieval applications.
npm install ssim.jsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to load two image files (using `@napi-rs/canvas` or `canvas` in Node.js, or browser APIs) and compute their SSIM score, printing the result to the console. It includes error handling and a basic interpretation of the SSIM score.
Use a library like `canvas` (for Node.js) or browser `CanvasRenderingContext2D.getImageData()` to convert loaded images into `ImageData` objects or similar pixel arrays before passing them to `ssim()`.
Review results for critical applications if upgrading from pre-3.0.0 versions to ensure consistent SSIM scores. If discrepancies are observed, check options to configure the specific algorithm or parameters being used.
Consider pre-scaling images down before SSIM calculation if exact pixel-level detail is not critical, or perform calculations in a web worker or background thread to avoid blocking the main thread in browser environments.
Ensure `ssim()` receives correctly formatted image data. In Node.js, use a library like `canvas` to load and process image files into `ImageData` objects. In browsers, use `context.getImageData()`.
Run `npm install ssim.js` or `yarn add ssim.js`. Verify the import statement `import ssim from 'ssim.js';` for ESM or `const ssim = require('ssim.js');` for CommonJS.No dependency data recorded yet.