• Stars
    star
    963
  • Rank 47,492 (Top 1.0 %)
  • Language
    Rust
  • License
    GNU Affero Genera...
  • Created almost 14 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Image similarity comparison simulating human perception (multiscale SSIM in Rust)

RGBA Structural Similarity

This tool computes (dis)similarity between two or more PNG &/or JPEG images using an algorithm approximating human vision. Comparison is done using a variant of the SSIM algorithm.

The value returned is 1/SSIM-1, where 0 means identical image, and >0 (unbounded) is amount of difference. Values are not directly comparable with other tools. See below on interpreting the values.

Features

  • Improved algorithm
    • Compares at multiple weighed resolutions, and scaling is done in linear-light RGB. It's sensitive to distortions of various sizes and blends colors correctly to detect e.g. chroma subsampling errors.
    • Uses L*a*b* color space for the SSIM algorithm. It measures brightness and color much better than metrics from average of RGB channels.
  • Supports alpha channel.
  • Supports images with color profiles.
  • Takes advantage of multi-core CPUs.
  • Can be used as a library in C, Rust, and WASM.
  • No OpenCV or MATLAB needed.

Usage

dssim file-original.png file-modified.png

Will output something like "0.02341" (smaller is better) followed by a filename.

You can supply multiple filenames to compare them all with the first file:

dssim file.png modified1.png modified2.png modified3.png

You can save an image visualising the difference between the files:

dssim -o difference.png file.png file-modified.png

It's also usable as a library.

Please be mindful about color profiles in the images. Different profiles, or lack of support for profiles in other tools, can make images appear different even when the pixels are the same.

Interpreting the values

The amount of difference goes from 0 to infinity. It's not a percentage.

If you're comparing two different image compression codecs, then ensure you either:

  • compress images to the same file size, and then use DSSIM to compare which one is closests to the original, or
  • compress images to the same DSSIM value, and compare file sizes to see how much file size gain each option gives.

More about benchmarking image compression.

When you quote results, please include the DSSIM version. The scale has changed between versions. The version is printed when you run dssim -h.

Download

Download from releases page. It's also available in Mac Homebrew and Ubuntu Snaps.

Build from source

You'll need Rust 1.63 or later. Clone the repo and run:

rustup update
cargo build --release

Will give you ./target/release/dssim.

Accuracy

Scores for version 3.2 measured against TID2013 database:

TID2013 Spearman Kendall
Noise -0.9392 -0.7789
Actual -0.9448 -0.7913
Simple -0.9499 -0.8082
Exotic -0.8436 -0.6574
New -0.8717 -0.6963
Color -0.8789 -0.7032
Full -0.8711 -0.6984

Usage from C

Make sure to build dssim-core library project, not the parent dssim binary project.

cd dssim-core
rustup update
cargo build --release

This will build target/release/libdssim_core.a that you can link with your project. Use dssim.h included in the dssim repo. It's up to you where you put these files.

Alternatively, on Linux there is a more involved but slightly more proper method:

cargo install cargo-c
cargo cinstall --release --destdir=/ --prefix=/usr/lib

This will install libdssim.so in /usr/lib and make dssim available to pkg-config. See target/<platform>/release for all the files built this way.

License

DSSIM is dual-licensed under AGPL or commercial license.

The algorithm improvements in DSSIM

  • The comparison is done on multiple weighed scales (based on IWSSIM) to measure features of different sizes. A single-scale SSIM is biased towards differences smaller than its gaussian kernel.
  • Scaling is done in linear-light RGB to model physical effects of viewing distance/lenses. Scaling in sRGB or Lab would have incorrect gamma and mask distortions caused by chroma subsampling.
  • a/b channels of Lab are compared with lower spatial precision to simulate eyes' higher sensitivity to brightness than color changes.
  • SSIM score is pooled using mean absolute deviation. You can get per-pixel SSIM from the API to implement custom pooling.

Compiling for WASM

For compatibility with single-threaded WASM runtimes, disable the threads Cargo feature. It's enabled by default, so to disable it, disable default features:

dssim-core = { version = "3.2", default-features = false }

More Repositories

1

pngquant

Lossy PNG compressor — pngquant command based on libimagequant library
C
4,782
star
2

slip

Slip.js — UI library for manipulating lists via swipe and drag gestures
JavaScript
2,438
star
3

giflossy

Merged into Gifsicle!
C
968
star
4

cavif-rs

AVIF image creator in pure Rust
Rust
473
star
5

7z

Because 7-zip source code was in a 7z archive [mirror]
C++
472
star
6

ImageAlpha

Mac GUI for pngquant, pngnq and posterizer
Python
470
star
7

cargo-deb

A cargo subcommand that generates Debian packages from information in Cargo.toml
Rust
267
star
8

http-cache-semantics

RFC 7234 in JavaScript. Parses HTTP headers to correctly compute cacheability of responses, even in complex cases
JavaScript
234
star
9

mediancut-posterizer

Lossy PNG compressor for RGBA PNGs. Has two modes: lossy averaging filter (blurizer) that denoises the image and optimal posterization using Median Cut quantization to reduce number of unique colors in the image with minimal visual distortion
C
231
star
10

pngquant-photoshop

Photoshop plug-in for saving PNG images with pngquant compression
C++
201
star
11

rust-security-framework

Bindings to the macOS Security.framework
Rust
197
star
12

jpeg-compressor

Research JPEG encoder
C++
190
star
13

dupe-krill

A fast file deduplicator
Rust
168
star
14

lodepng-rust

All-in-one PNG image encoder/decoder in pure Rust
Rust
93
star
15

rust-rgb

struct RGB for sharing pixels between crates
Rust
88
star
16

imgref

A trivial Rust struct for interchange of pixel buffers with width, height & stride
Rust
51
star
17

libicns

icns2png / libicns for OS X icns files
C
44
star
18

undither

Smart filter to remove Floyd-Steinberg dithering from paletted images
Rust
43
star
19

Sblam

Server-side HTTP spam filter
PHP
39
star
20

rust-lcms2

ICC color profiles in Rust
Rust
38
star
21

mozjpeg-sys

Rust bindings for mozjpeg
Rust
32
star
22

vpsearch

C library for finding nearest (most similar) element in a set
Rust
30
star
23

objc2grammar

Objective-C 2.0 grammar for SableCC 3 parser. Allows reading of Objective-C source files into abstract syntax tree.
Java
21
star
24

yuv

YCbCr to sRGB converter in Rust
Rust
18
star
25

hCardValidator

hCard Microformat Validator
PHP
17
star
26

rgba-hq2x

hq2x scaling algorithm updated to support RGBA
C++
17
star
27

image-gif-dispose

Implements GIF disposal method (full rendering of frames) for the Rust gif crate
Rust
17
star
28

libimagequant-rust

libimagequant (pngquant) bindings for the Rust language
17
star
29

avif-serialize

Minimal pure Rust AVIF writer (bring your own AV1 payload)
Rust
16
star
30

bcrypt

Fast JavaScript implementation of bCrypt
JavaScript
14
star
31

rust-file

Trivial 1-liner for reading files
Rust
13
star
32

Enterprise

HTML5 Game Jam game
JavaScript
11
star
33

avif-decode

Convert AVIF images to PNG (as lossless as possible)
Rust
11
star
34

mysqlcompat

A reimplemenation of as many MySQL functions as possible in PostgreSQL, as an aid to porting
PLpgSQL
11
star
35

core-services

Rust bindings for CoreServices framework
Rust
10
star
36

openjpeg-sys

Rust bindings for the openjpeg library
Rust
10
star
37

atom2rss

XSL stylesheets for converting Atom 0.3 → Atom 1.0 → RSS 2.0.
XSLT
8
star
38

avif-parse

AVIF parser for extracting AV1 payload from image files. Supports alpha channel association. Fork of Firefox's MP4 parser.
Rust
8
star
39

rust-lcms2-sys

Rust bindings for Little CMS liblcms2
Rust
7
star
40

libjpeg

The old libjpeg
C
7
star
41

mss_saliency

Detection of visually salient image regions using Maximum Symmetric Surround algorithm
Rust
7
star
42

pngoo

Automatically exported from code.google.com/p/pngoo
C#
7
star
43

rust-libpng-sys

Build script to get libpng compile on Windows. It's horrible. Stay away.
Rust
4
star
44

CSS-Preprocessor

DEPRECATED; Preprocessor+parser+minifier
PHP
3
star
45

parallel-progressive

Demo site for HTTP/2-parallelized progressive JPEG
JavaScript
3
star
46

crev-proofs

cargo-crev package reviews
2
star
47

read-through-http-cache

Read-through LRU cache that has basic understanding of HTTP cache headers
JavaScript
2
star
48

itunesfixer

Automatically exported from code.google.com/p/itunesfixer
Objective-C
2
star
49

rust-openh264

Unfinished Rust bindings for Cisco's OpenH264
Rust
2
star
50

nota

Not a pragmatic message format
Rust
1
star
51

picture-element

Simplified <picture> element proposal
1
star
52

cargo-static-registry-rfc-proof-of-concept

Testing whether it's feasible to serve crates-io registry over HTTP as static files
Rust
1
star
53

torrentspotlight

Automatically exported from code.google.com/p/torrentspotlight
Objective-C
1
star
54

is-dark-theme

Hacky check whether macOS is configured to use a Dark Mode appearance
Rust
1
star