• Stars
    star
    700
  • Rank 62,105 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 14 years ago
  • Updated 5 months ago

Reviews

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

Repository Details

Ruby wrapper around pHash, the perceptual hash library for detecting duplicate multimedia files

Phashion

Build Status

Phashion is a Ruby wrapper around the pHash library, "perceptual hash", which detects duplicate and near-duplicate multimedia files (e.g. images, audio, video, though Phashion currently only supports images.). "Near-duplicates" are images that come from the same source and show essentially the same thing, but may have differences in such features as dimensions, bytesizes, lossy-compression artifacts, and color levels.

See an overview of Phashion on Mike's blog.

Installation

You install it just like any other Ruby gem:

gem install phashion

Phashion is somewhat involved to install as it has a few dependencies. Phashion wraps these dependencies into a custom tarball that is built locally just for this gem so you don't have to do anything special. Look in the ext/phashion_ext folder for more details.

Compatibility

Because of this complexity, it is possible the gem install will fail on your platform. Phashion has been tested on:

  • Mac OSX 10.6
  • Mac OSX 10.9
  • Ubuntu 8.04
  • Ubuntu 12.04

Please open a GitHub issue if you have installation problems.

Prerequisites

Linux

  • libjpeg-dev
  • libpng-dev

Mac

  • imagemagick
  • libjpeg (Hombrew, brew install libjpeg; Macports, port install jpeg)
  • libpng (Hombrew, brew install libpng; Macports, port install libpng)

Common Errors

  • ld: library not found for -ljpeg – Did you install libjpeg?
  • ... sh: convert: command not found; sh: gm: command not found – Did you install imagemagick?
  • ... checking for sqlite3ext.h... *** extconf.rb failed *** ... – Did you install libpng-dev and/or libjpeg-dev?

Usage

Testing if one image is a duplicate of another

require 'phashion'
img1 = Phashion::Image.new(filename1)
img2 = Phashion::Image.new(filename2)
img1.duplicate?(img2)
# --> true

Optionally, you can set the minimum Hamming distance in the second argument, an options Hash:

img1.duplicate?(img2, :threshold => 5)
# --> true

img1.duplicate?(img2, :threshold => 0)  
# --> false

Finding the Hamming distance between two images

require 'phashion'
img1 = Phashion::Image.new(filename1)
img2 = Phashion::Image.new(filename2)
img1.distance_from(img2)  
# --> 6

Threshold for dupe-detection

Currently, the maximum Hamming distance between two duplicate images is set at 15. As per mperham's explanation:

A “perceptual hash”is a 64-bit value based on the discrete cosine transform of the image’s frequency spectrum data. Similar images will have hashes that are close in terms of Hamming distance. That is, a binary hash value of 1000 is closer to 0000 than 0011 because it only has one bit different whereas the latter value has two bits different. The duplicate threshold defines how many bits must be different between two hashes for the two associated images to be considered different images. Our testing showed that 15 bits is a good value to start with, it detected all duplicates with a minimum of false positives.

As a reference point, here are the Hamming distances in these test comparisons using /test/jpg/Broccoli_Super_Food.jpg as the source image:

Variation Hamming distance
JPG to PNG 0
Lossy JPG (Photoshop Save for Web quality = 20) 0
Thumbnail (from 500px to 100px) 2
Color correction (saturation +20 w auto-correct) 2
Black and white 2
Extraneous whitespace cropped (500x349 to 466x312) 12
A sloppy rotation of 5 degrees clockwise 14
Horizontally-flipped 32

Gem uses customized pHash 0.9.6

In order to detech duplicate alpha PNGs, the gem uses a custom version of pHash 0.9.6. The customization is limited to only these changes, westonplatter/phash@ff255d2. The gem will be moving back to the pHash master branch once it supports detection of alpha PNG file types.

Testing

To run the test suite:

$ cd phashion
$ bundle install
$ rake compile
$ rake test

Author

Mike Perham, http://mikeperham.com, http://twitter.com/mperham, mperham AT gmail.com

Copyright

Copyright (c) 2010-2014 Mike Perham. See LICENSE for details.

More Repositories

1

fast_arrow

(no longer maintained) A simple yet robust (stock+options) API client for Robinhood
Python
124
star
2

example-golang-todo

Golang API backend powering a TodoList app
CSS
33
star
3

finx-option-pricer

Price options, visualize PnL/1st+2nd order greeks in Dash app UI
Jupyter Notebook
23
star
4

ta_scanner

Scanner that finds patterns in stocks/options/futures and discerns future risk/reward. Ie, money ball engine.
Jupyter Notebook
19
star
5

simple_portfolio

Export trades from Robinhood and run basic reporting on portfolio performance
Python
18
star
6

portfolio_management

Engine and UI for tracking trading performance across stocks and derivatives (options, futures, & future options).
Jupyter Notebook
15
star
7

example_meteor_deploy

Example for how to provision a linux server and deploy meteor app to it
Ruby
12
star
8

ibdatafetcher

Fetch data (futures, stock, coming next => options) from IBKR for local use.
Python
12
star
9

railsy_backbone

Use https://github.com/codebrew/backbone-rails
Ruby
9
star
10

Black-Litterman-Entropy-Pooling

Python
7
star
11

finx-option-data

Fetch, store, and warehouse Option Data
Python
6
star
12

ledgerx-python

Client for the LedgerX exchange (BTC and ETH derivatives)
Python
5
star
13

fast_arrow_auth

Robinhood API Authentication for fast_arrow
Python
4
star
14

finx-tracker

Web app to track PnL for options & futures strategies.
Python
4
star
15

example_ios_coredata_tdd

Build a simple Todo iOS app showing how to TDD the CoreData/JSON functionality
Objective-C
2
star
16

opening_range_breakout

opening range breakout modeling in ruby and python
Jupyter Notebook
2
star
17

learning_javascript

learn Javascript by proving concepts with tests
JavaScript
2
star
18

phash

fork of the official pHash library
Shell
2
star
19

simple_metrics

Simple metrics for Robinhood trading
Python
2
star
20

gdi-boulder-servers-intro

GDI Course - Intro to Servers
CSS
1
star
21

ta_visualizer

Visualizations of Pre-Entry, Post-Exit trades based on TA. Basically a heads up display for westonplatter/ta_scanner
Python
1
star
22

mapper

Android Mapper Application
Java
1
star
23

finx-reports-ib

Compose custom reports from IBKR Flex Statements.
Python
1
star
24

example_rails_bower

Example Rails app integrated with Bower so Bower manages all JS/CSS dependencies
Ruby
1
star
25

finx-pm

Python
1
star
26

zing

simple Nodejs + Socket.io chat app
JavaScript
1
star