Image Comparison
Learn how to use BlazeDiff for different types of comparisons - binary, object, and pixel-by-pixel image comparison.
Installation
npm install @blazediff/coreOverview
BlazeDiff provides multiple comparison methods optimized for different use cases. Try the interactive demos below to see each method in action.
Pixel-by-pixel Comparison
Basic Comparison

Image 1

Image 2
Result
import blazediff from "@blazediff/core";
// loadImage can either be a browser function or a server function
const img1 = await loadImage(
"https://raw.githubusercontent.com/teimurjan/blazediff/refs/heads/main/packages/benchmark/fixtures/blazediff/3a.png"
);
const img2 = await loadImage(
"https://raw.githubusercontent.com/teimurjan/blazediff/refs/heads/main/packages/benchmark/fixtures/blazediff/3b.png"
);
const output = new Uint8Array(img1.width * img1.height * 4);
const width = img1.width;
const height = img1.height;
const diff = blazediff(img1, img2, output, width, height);Perceptual Comparison
GMSD (Gradient Magnitude Similarity Deviation)
Basic Comparison

Image 1

Image 2
Result
import gmsd from "@blazediff/gmsd";
const img1 = await loadImage(
"https://raw.githubusercontent.com/teimurjan/blazediff/refs/heads/main/packages/benchmark/fixtures/blazediff/3a.png"
);
const img2 = await loadImage(
"https://raw.githubusercontent.com/teimurjan/blazediff/refs/heads/main/packages/benchmark/fixtures/blazediff/3b.png"
);
const width = img1.width;
const height = img1.height;
const score = gmsd(img1, img2, undefined, width, height);SSIM (Structural Similarity Index)
Original SSIM

Image 1

Image 2
SSIM Map
import ssim from "@blazediff/ssim/ssim";
const img1 = await loadImage(
"https://raw.githubusercontent.com/teimurjan/blazediff/refs/heads/main/packages/benchmark/fixtures/blazediff/3a.png"
);
const img2 = await loadImage(
"https://raw.githubusercontent.com/teimurjan/blazediff/refs/heads/main/packages/benchmark/fixtures/blazediff/3b.png"
);
const output = new Uint8Array(img1.width * img1.height * 4);
const width = img1.width;
const height = img1.height;
const score = ssim(img1, img2, output, width, height);Last updated on