GithubHelp home page GithubHelp logo

pdqhash's Introduction

PDQ Hash

This hash is a pure Rust implementation of the PDQ algorithm described here.

Calculation

The PDQ algorithm was developed and open-sourced by Facebook (now Meta) in 2019. It specifies a transformation which converts images into a binary format ('PDQ Hash') whereby 'perceptually similar’ images produce similar outputs. It was designed to offer an industry standard for representing images to collaborate on threat mitigation.

Obtain PDQ Hash of an image

Comparing two images reduces to computing distance (for example, Hamming distance) between their representations, or as % bit similarity. Comparing two bit strings

(16 bits are just used here for easier interpretation; PDQ hashes represent 256 bits)

Consider additional image transformations

Additionally, PDQ hashes for rotations and mirrors of the original image can be inferred efficiently, by just manipulating the Discrete Cosine Transform created in latter stages of processing. Comparing two bit strings Example: PDQ Hash of mirrored original image only requires manipulation of the transform

DCT Manipulation needed for corresponding PDQ Hash

  • Mirrored Y -> Negate alternate columns
  • Mirrored X -> Negate alternate rows
  • Mirrored Main Diagonal -> Transpose
  • Mirrored Off Diagonal -> Negate off-diagonal, transpose
  • Rotated 90 -> Negate alternate columns, transpose
  • Rotated 180 -> Negate off-diagonal
  • Rotated 270 -> Negate alternate rows, transpose

Offering similarity resilience

The resulting hashes are resilient to certain transformations, some more so than others, to detect additional attempted manipulation. Generally, images retaining overall structure are more resilient than changes to pixel positions and larger areas of pixel change. Obtain PDQ Hash of an image

Transformations that result in similar hashes:

  • File format change
  • Quality reduction
  • Light crops and shifts
  • Rotations (when additional hashes compared)
  • Resizing
  • Light watermarks
  • Mirroring (when additional hashes compared)
  • Noise or filter applied
  • Light logos

pdqhash's People

Contributors

cmoore-darwinium avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.