• This repository has been archived on 01/May/2020
  • Stars
    star
    1,191
  • Rank 39,271 (Top 0.8 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 10 years ago
  • Updated almost 5 years ago

Reviews

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

Repository Details

A lightweight image comparison tool.

Blink-Diff

A lightweight image comparison tool

Build Status Coveralls Coverage Code Climate Grade

NPM version NPM License

NPM NPM

Coverage Report API Documentation

Gitter Support

Table of Contents

##Image Comparison and Result Composition

##Installation

Install this module with the following command:

npm install blink-diff

Add the module to your package.json dependencies:

npm install --save blink-diff

Add the module to your package.json dev-dependencies:

npm install --save-dev blink-diff

##Usage

The package can be used in two different ways:

  • per command line
  • through an object

###Command-Line usage

The command-line tool can be found in the bin directory. You can run the application with

blink-diff --output <output>.png <image1>.png <image2>.png

Use image1 and image2 as the images you want to compare. Only PNGs are supported at this point.

The command-line tool exposes a couple of flags and parameters for the comparison:

--verbose           Turn on verbose mode
--debug             Turn on debug mode - leaving all filters and modifications on the result
--threshold p       Number of pixels/percent 'p' below which differences are ignored
--threshold-type t  'pixel' and 'percent' as type of threshold. (default: pixel)
--delta p           Max. distance colors in the 4 dimensional color-space without triggering a difference. (default: 20)
--copyImageA        Copies first image to output as base. (default: true)
--copyImageB        Copies second image to output as base.
--no-copy           Doesn't copy anything to output as base.
--output o          Write difference to the file 'o'
--filter f          Filters f (separated with comma) that will be applied before the comparison.
--no-composition    Turns the composition feature off
--compose-ltr       Compose output image from left to right
--compose-ttb       Compose output image from top to bottom
--hide-shift        Hides shift highlighting (default: false)
--h-shift           Acceptable horizontal shift of pixel. (default: 0)
--v-shift           Acceptable vertical shift of pixel. (default: 0)
--block-out x,y,w,h Block-out area. Can be repeated multiple times.
--version           Print version
--help              This help

###Object usage

The package can also be used directly in code, without going through the command-line.

Example:

var diff = new BlinkDiff({
    imageAPath: 'path/to/first/image', // Use file-path
    imageBPath: 'path/to/second/image',

    thresholdType: BlinkDiff.THRESHOLD_PERCENT,
    threshold: 0.01, // 1% threshold

    imageOutputPath: 'path/to/output/image'
});

diff.run(function (error, result) {
   if (error) {
      throw error;
   } else {
      console.log(diff.hasPassed(result.code) ? 'Passed' : 'Failed');
      console.log('Found ' + result.differences + ' differences.');
   }
});

All the parameters that were available in the command-line tool are also available through the class constructor, however they might use slightly different wording. The class exposes additional parameters that are not available from the command-line:

  • imageAPath Defines the path to the first image that should be compared (required; imageAPath or imageA is required - see example below)
  • imageA Supplies first image that should be compared (required; imageAPath or imageA is required - see example below) - This can be a PNGImage instance or a Buffer instance with PNG data
  • imageBPath Defines the path to the second image that should be compared (required; imageBPath or imageB is required - see example below)
  • imageB Supplies second image that should be compared (required; imageBPath or imageB is required - see example below) - This can be a PNGImage instance or a Buffer instance with PNG data
  • imageOutputPath Defines the path to the output-file. If you leaves this one off, then this feature is turned-off.
  • imageOutputLimit Defines when an image output should be created. This can be for different images, similar or different images, or all comparisons. (default: BlinkDiff.OUTPUT_ALL)
  • verbose Verbose output (default: false)
  • thresholdType Type of threshold check. This can be BlinkDiff.THRESHOLD_PIXEL and BlinkDiff.THRESHOLD_PERCENT (default: BlinkDiff.THRESHOLD_PIXEL)
  • threshold Number of pixels/percent p below which differences are ignored (default: 500) - For percentage thresholds: 1 = 100%, 0.2 = 20%
  • delta Distance between the color coordinates in the 4 dimensional color-space that will not trigger a difference. (default: 20)
  • outputMaskRed Red intensity for the difference highlighting in the output file (default: 255)
  • outputMaskGreen Green intensity for the difference highlighting in the output file (default: 0)
  • outputMaskBlue Blue intensity for the difference highlighting in the output file (default: 0)
  • outputMaskAlpha Alpha intensity for the difference highlighting in the output file (default: 255)
  • outputMaskOpacity Opacity of the pixel for the difference highlighting in the output file (default: 0.7 - slightly transparent)
  • outputShiftRed Red intensity for the shift highlighting in the output file (default: 255)
  • outputShiftGreen Green intensity for the shift highlighting in the output file (default: 165)
  • outputShiftBlue Blue intensity for the shift highlighting in the output file (default: 0)
  • outputShiftAlpha Alpha intensity for the shift highlighting in the output file (default: 255)
  • outputShiftOpacity Opacity of the pixel for the shift highlighting in the output file (default: 0.7 - slightly transparent)
  • outputBackgroundRed Red intensity for the background in the output file (default: 0)
  • outputBackgroundGreen Green intensity for the background in the output file (default: 0)
  • outputBackgroundBlue Blue intensity for the background in the output file (default: 0)
  • outputBackgroundAlpha Alpha intensity for the background in the output file (default: undefined)
  • outputBackgroundOpacity Opacity of the pixel for the background in the output file (default: 0.6 - transparent)
  • blockOut Object or list of objects with coordinates that should be blocked before testing.
  • blockOutRed Red intensity for the block-out in the output file (default: 0) This color will only be visible in the result when debug-mode is turned on.
  • blockOutGreen Green intensity for the block-out in the output file (default: 0) This color will only be visible in the result when debug-mode is turned on.
  • blockOutBlue Blue intensity for the block-out in the output file (default: 0) This color will only be visible in the result when debug-mode is turned on.
  • blockOutAlpha Alpha intensity for the block-out in the output file (default: 255)
  • blockOutOpacity Opacity of the pixel for the block-out in the output file (default: 1.0)
  • copyImageAToOutput Copies the first image to the output image before the comparison begins. This will make sure that the output image will highlight the differences on the first image. (default)
  • copyImageBToOutput Copies the second image to the output image before the comparison begins. This will make sure that the output image will highlight the differences on the second image.
  • filter Filters that will be applied before the comparison. Available filters are: blur, grayScale, lightness, luma, luminosity, sepia
  • debug When set, then the applied filters will be shown on the output image. (default: false)
  • composition Creates as output a composition of all three images (approved, highlight, and build) (default: true)
  • composeLeftToRight Creates comparison-composition from left to right, otherwise it lets decide the app on what is best
  • composeTopToBottom Creates comparison-composition from top to bottom, otherwise it lets decide the app on what is best
  • hShift Horizontal shift for possible antialiasing (default: 2) Set to 0 to turn this off.
  • vShift Vertical shift for possible antialiasing (default: 2) Set to 0 to turn this off.
  • hideShift Uses the background color for "highlighting" shifts. (default: false)
  • cropImageA Cropping for first image (default: no cropping) - Format: { x:, y:, width:, height: }
  • cropImageB Cropping for second image (default: no cropping) - Format: { x:, y:, width:, height: }
  • perceptual Turn the perceptual comparison mode on. See below for more information.
  • gamma Gamma correction for all colors (will be used as base) (default: none) - Any value here will turn the perceptual comparison mode on
  • gammaR Gamma correction for red - Any value here will turn the perceptual comparison mode on
  • gammaG Gamma correction for green - Any value here will turn the perceptual comparison mode on
  • gammaB Gamma correction for blue - Any value here will turn the perceptual comparison mode on

Example:

var firstImage = PNGImage.readImage('path/to/first/image', function (err) {

  if (err) {
    throw err;
  }

  var diff = new BlinkDiff({
      imageA: srcImage, // Use already loaded image for first image
      imageBPath: 'path/to/second/image', // Use file-path to select image

      delta: 50, // Make comparison more tolerant
      
      outputMaskRed: 0,
      outputMaskBlue: 255, // Use blue for highlighting differences
      
      hideShift: true, // Hide anti-aliasing differences - will still determine but not showing it

      imageOutputPath: 'path/to/output/image'
  });

  diff.run(function (error, result) {
    if (error) {
      throw error;
    } else {
      console.log(diff.hasPassed(result.code) ? 'Passed' : 'Failed');
      console.log('Found ' + result.differences + ' differences.');
    }
  });
});

####Cropping Images can be cropped before they are compared by using the cropImageA or cropImageB parameters. Single values can be left off, and the system will calculate the correct dimensions. However, x/y coordinates have priority over width/height as the position are usually more important than the dimensions - image will also be clipped by the system when needed.

####Perceptual Comparison The perceptual comparison mode considers the perception of colors in the human brain. It transforms all the colors into a human perception color-space, which is quite different to the typical physical bound RGB color-space. There, in the perceptual color-space, the distance between colors is according to the human perception and should therefore closer resemble the differences a human would perceive seeing the images.

####Logging

By default, the logger doesn't log events anywhere, but you can change this behavior by overwriting blinkDiff.log:

var blinkDiff = new BlinkDiff({
    ...
});

blinkDiff.log = function (text) {
    // Do whatever you want to do
};

...

####Block-Out Sometimes, it is necessary to block-out some specific areas in an image that should be ignored for comparisons. For example, this can be IDs or even time-labels that change with the time. Adding block-outs to images may decrease false positives and therefore stabilizes these comparisons.

The color of the block-outs can be selected by the API parameters. However, the block-out areas will not be visible by default - they are hidden even though they are used. To make them visible, turn the debug-mode on.

##Examples

There are some examples in the examples folder, in which I used screenshots of YDN to check for visual regressions (and made some manual modifications to the dom to make differences appear ;-)). You can find examples for:

  • Color changes in YDN_Color
  • Missing DOM elements in YDN_Missing (including some anti-aliasing)
  • Multiple differences in YDN_Multi
  • Disrupted sorting in YDN_Sort
  • Swapped items in YDN_Swap (including block-out areas)
  • Text capitalization in YDN_Upper

All screenshots were compared to YDN.png, a previously approved screenshot without a regression. Each of the regressions has the screenshot and the output result, highlighting the differences.

##API-Documentation

Generate the documentation with following command:

npm run docs

The documentation will be generated in the docs folder of the module root.

##Tests

Run the tests with the following command:

npm run test

The code-coverage will be written to the coverage folder in the module root.

##Project Focus There are three types of image comparisons:

  • Pixel-by-pixel - Used to compare low-frequency images like screenshots from web-sites, making sure that small styling differences trigger
  • Perceptual - Used to compare image creation applications, for example rendering engines and photo manipulation applications that are taking the human perception into account, ignoring differences a human probably would not see
  • Context - Used to see if parts of images are missing or are severely distorted, but accepts smaller and/or perceptual differences

Blink-Diff was initially created to compare screenshots. These images are generally low-frequency, meaning larger areas with the same color and less gradients than in photos. The pixel-by-pixel comparison was chosen as it will trigger for differences that a human might not be able to see. We believe that a bug is still a bug even if a human won't see it - a regression might have happened that wasn't intended. A perceptual comparison would not trigger small differences, possibly missing problems that could get worse down the road. Pixel-by-pixel comparisons have the reputation of triggering too often, adding manual labor, checking images by hand. Blink-Diff was created to keep this in mind and was optimized to reduce false-positives by taking sub-pixeling and anti-aliasing into account. Additional features like thresholds and the pythagorean distance calculation in the four dimensional color-space makes sure that this won't happen too often. Additionally, filters can be applied to the images, for example to compare luminosity of pixels and not the saturation thereof. Blink-Diff also supports partially the perceptual comparison that can be turned on when supplying perceptual=true. Then, the colors will be compared in accordance with the human perception and not according to the physical world. High-frequency filters, however, are not yet supported.

##Project Naming The name comes from the Blink comparator that was used in Astronomy to recognize differences in multiple photos, taking a picture of the same area in the sky over consecutive days, months, or years. Most notably, it was used to discover Pluto.

##Contributions Feel free to create an issue or create a pull-request if you have an idea on how to improve blink-diff. We are pretty relaxed on the contribution rules; add tests for your pull-requests when possible, but it is also ok if there are none - we'll add them for you. We are trying to improve blink-diff as much as possible, and this can only be done by contributions from the community.

Also, even if you simply gave us an idea for a feature and did not actually write the code, we will still add you as the Contributor down below since it probably wouldn't be there without you. So, keep them coming!

##Contributors

##Third-party libraries

The following third-party libraries are used by this module:

###Dependencies

###Dev-Dependencies

##License

The MIT License

Copyright 2014-2015 Yahoo Inc.

More Repositories

1

CMAK

CMAK is a tool for managing Apache Kafka clusters
Scala
11,825
star
2

open_nsfw

Not Suitable for Work (NSFW) classification using deep neural network Caffe models.
Python
5,852
star
3

TensorFlowOnSpark

TensorFlowOnSpark brings TensorFlow programs to Apache Spark clusters.
Python
3,873
star
4

serialize-javascript

Serialize JavaScript to a superset of JSON that includes regular expressions and functions.
JavaScript
2,804
star
5

gryffin

Gryffin is a large scale web security scanning platform.
Go
2,075
star
6

fluxible

A pluggable container for universal flux applications.
JavaScript
1,815
star
7

AppDevKit

AppDevKit is an iOS development library that provides developers with useful features to fulfill their everyday iOS app development needs.
Objective-C
1,442
star
8

mysql_perf_analyzer

MySQL performance monitoring and analysis.
Java
1,436
star
9

squidb

SquiDB is a SQLite database library for Android and iOS
Java
1,312
star
10

react-stickynode

A performant and comprehensive React sticky component.
JavaScript
1,266
star
11

CaffeOnSpark

Distributed deep learning on Hadoop and Spark clusters.
Jupyter Notebook
1,266
star
12

egads

A Java package to automatically detect anomalies in large scale time-series data
Java
1,173
star
13

elide

Elide is a Java library that lets you stand up a GraphQL/JSON-API web service with minimal effort.
Java
1,003
star
14

vssh

Go Library to Execute Commands Over SSH at Scale
Go
952
star
15

webseclab

set of web security test cases and a toolkit to construct new ones
Go
915
star
16

kubectl-flame

Kubectl plugin for effortless profiling on kubernetes
Go
784
star
17

streaming-benchmarks

Benchmarks for Low Latency (Streaming) solutions including Apache Storm, Apache Spark, Apache Flink, ...
Jupyter Notebook
630
star
18

redislite

Redis in a python module.
Python
577
star
19

lopq

Training of Locally Optimized Product Quantization (LOPQ) models for approximate nearest neighbor search of high dimensional data in Python and Spark.
Python
563
star
20

HaloDB

A fast, log structured key-value store.
Java
497
star
21

hecate

Automagically generate thumbnails, animated GIFs, and summaries from videos
C++
477
star
22

fetchr

Universal data access layer for web applications.
JavaScript
447
star
23

storm-yarn

Storm-yarn enables Storm clusters to be deployed into machines managed by Hadoop YARN.
Java
417
star
24

react-i13n

A performant, scalable and pluggable approach to instrumenting your React application.
JavaScript
382
star
25

FEL

Fast Entity Linker Toolkit for training models to link entities to KnowledgeBase (Wikipedia) in documents and queries.
Java
335
star
26

monitr

A Node.js process monitoring tool.
C++
312
star
27

Oak

A Scalable Concurrent Key-Value Map for Big Data Analytics
Java
267
star
28

TDOAuth

A BSD-licensed single-header-single-source OAuth1 implementation.
Swift
249
star
29

routr

A component that provides router related functionalities for both client and server.
JavaScript
246
star
30

mysql_partition_manager

MySQL Partition Manager
SQLPL
212
star
31

l3dsr

Direct Server Return load balancing across Layer 3 boundaries.
Shell
193
star
32

dnscache

dnscache for Node
JavaScript
184
star
33

object_relation_transformer

Implementation of the Object Relation Transformer for Image Captioning
Python
176
star
34

fili

Easily make RESTful web services for time series reporting with Big Data analytics engines like Druid and SQL Databases.
Java
173
star
35

check-log4j

To determine if a host is vulnerable to log4j CVE‐2021‐44228
Shell
172
star
36

sherlock

Sherlock is an anomaly detection service built on top of Druid
Java
152
star
37

YMTreeMap

High performance Swift treemap layout engine for iOS and macOS.
Swift
134
star
38

maha

A framework for rapid reporting API development; with out of the box support for high cardinality dimension lookups with druid.
Scala
129
star
39

covid-19-data

COVID-19 datasets are constructed entirely from primary (government and public agency) sources
109
star
40

subscribe-ui-event

Subscribe-ui-event provides a cross-browser and performant way to subscribe to browser UI Events.
JavaScript
109
star
41

jafar

🌟!(Just another form application renderer)
JavaScript
109
star
42

panoptes

A Global Scale Network Telemetry Ecosystem
Python
99
star
43

reginabox

Registry In A Box
JavaScript
97
star
44

preceptor

Test runner and aggregator
JavaScript
85
star
45

hive-funnel-udf

Hive UDFs for funnel analysis
Java
85
star
46

graphkit

A lightweight Python module for creating and running ordered graphs of computations.
Python
84
star
47

SparkADMM

Generic Implementation of Consensus ADMM over Spark
Python
83
star
48

react-cartographer

Generic component for displaying Yahoo / Google / Bing maps.
JavaScript
82
star
49

storm-perf-test

A simple storm performance/stress test
Java
76
star
50

UDPing

UDPing measures latency and packet loss across a link.
C++
75
star
51

bgjs

TypeScript
67
star
52

ycb

A multi-dimensional configuration library that builds bundles from resource files describing a variety of values.
JavaScript
66
star
53

ariel

Ariel is an AWS Lambda designed to collect, analyze, and make recommendations about Reserved Instances for EC2.
Python
64
star
54

YMCache

YMCache is a lightweight object caching solution for iOS and Mac OS X that is designed for highly parallel access scenarios.
Objective-C
63
star
55

validatar

Functional testing framework for Big Data pipelines.
Java
58
star
56

imapnio

Java imap nio client that is designed to scale well for thousands of connections per machine and reduce contention when using large number of threads and cpus.
Java
55
star
57

serviceping

A ping like utility for tcp services
Python
52
star
58

proxy-verifier

Proxy Verifier is an HTTP replay tool designed to verify the behavior of HTTP proxies. It builds a verifier-client binary and a verifier-server binary which each read a set of YAML or JSON files that specify the HTTP traffic for the two to exchange.
C++
45
star
59

express-busboy

A simple body-parser like module for express that uses connect-busboy under the hood.
JavaScript
45
star
60

covid-19-api

Yahoo Knowledge COVID-19 API provides JSON-API and GraphQL interfaces to access COVID-19 publicly sourced data
JavaScript
45
star
61

covid-19-dashboard

Source code for the Yahoo Knowledge Graph COVID-19 Dashboard
JavaScript
42
star
62

photo-background-generation

Jupyter Notebook
41
star
63

yql-plus

The YQL+ parser, execution engine, and source SDK.
Java
40
star
64

panoptes-stream

A cloud native distributed streaming network telemetry.
Go
40
star
65

context-parser

A robust HTML5 context parser that parses HTML 5 web pages and reports the execution context of each character.
HTML
40
star
66

FmFM

Python
39
star
67

cocoapods-blocklist

A CocoaPods plugin used to check a project against a list of pods that you do not want included in your build. Security is the primary use, but keeping specific pods that have conflicting licenses is another possible use.
Ruby
39
star
68

ember-gridstack

Ember components to build drag-and-drop multi-column grids powered by gridstack.js
JavaScript
37
star
69

k8s-namespace-guard

K8s - Admission controller for guarding namespace
Go
35
star
70

VerizonVideoPartnerSDK-controls-ios

Public iOS implementation of the OneMobileSDK default custom controls interface... demonstrating how customers can implement their own custom video player controls.
Swift
35
star
71

SubdomainSleuth

Scanner to identify dangling DNS records and subdomain takeovers
Go
34
star
72

fluxible-action-utils

Utility methods to aid in writing actions for fluxible based applications.
JavaScript
34
star
73

parsec

A collection of libraries and utilities to simplify the process of building web service applications.
Java
34
star
74

mod_statuspage

Simple express/connect middleware to provide a status page with following details of the nodejs host.
JavaScript
32
star
75

bftkv

A distributed key-value storage that's tolerant to Byzantine fault.
JavaScript
30
star
76

spivak

Python
30
star
77

protractor-retry

Use protractor features to automatically re-run failed tests with a specific configurable number of attempts.
JavaScript
28
star
78

cubed

Data Mart As A Service
Java
27
star
79

jsx-test

An easy way to test your React Components (`.jsx` files).
JavaScript
27
star
80

ycb-java

YCB Java
Java
27
star
81

fluxible-immutable-utils

A mixin that provides a convenient interface for using Immutable.js inside react components.
JavaScript
25
star
82

maaf

Modality-Agnostic Attention Fusion for visual search with text feedback
Python
25
star
83

node-limits

Simple express/connect middleware to set limit to upload size, set request timeout etc.
JavaScript
24
star
84

GitHub-Security-Alerts-Workflow

Automation to Incorporate GitHub Security Alerts Into your Business Workflow
Python
23
star
85

bandar-log

Monitoring tool to measure flow throughput of data sources and processing components that are part of Data Ingestion and ETL pipelines.
Scala
21
star
86

fumble

Simple error objects in node. Created specifically to be used with https://github.com/yahoo/fetchr and based on https://github.com/hapijs/boom
JavaScript
21
star
87

SongbirdCharts

Allows for other apps to render accessible audio charts
Kotlin
21
star
88

express-csp

Express extension for Content Security Policy
JavaScript
19
star
89

elide-js

Elide is a library that makes it easy to talk to a JSON API compliant backend.
JavaScript
18
star
90

Zake

A python package that works to provide a nice set of testing utilities for the kazoo library.
Python
18
star
91

npm-auto-version

Automatically generate new NPM versions based on Git tags when publishing
JavaScript
18
star
92

httpmi

An HTTP proxy for IPMI commands.
Python
17
star
93

hodman

Selenium object library
JavaScript
17
star
94

elide-spring-boot-example

Spring Boot example using the Elide framework.
Java
17
star
95

cerebro

JavaScript
17
star
96

Override

In app feature flag management
Swift
16
star
97

ychaos

YChaos - The Resilience Framework by Yahoo!
Python
16
star
98

parsec-libraries

Tools to simplify deploying web services with Parsec.
Java
16
star
99

NetCHASM

An Automated health checking and server status verification system.
C++
14
star
100

k8s-ingress-claim

An admission control policy that safeguards against accidental duplicate claiming of Hosts/Domains.
Go
14
star