Skip to content
 
 

Latest commit

 

History

32 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scala pHash

Scala fork of pHash library. This library identifies whether images are similar.
Original pHash uses CImg library for image processing but I could not find CImg for jvm. Therefore I use java.awt and self-made functions for image processing. Consequently, results of my library is different from original phash.

How to use

My library implements three Perceptual Hashing algorithms: Radial Hash, DCT hash and Marr hash. More info about it.

sbt dependencies

libraryDependencies += "com.github.poslegm" %% "scala-phash" % "1.0.1"

Example

import com.github.poslegm.scalaphash.PHash
import javax.imageio.ImageIO

val img1 = ImageIO.read(new File("img1.jpg"))
val img2 = ImageIO.read(new File("img2.jpg"))

val img1rad = PHash.radialHash(img1)
val img2rad = PHash.radialHash(img2)

val radialDistance = PHash.radialHashDistance(img1rad, img2rad)

if (radialDistance > 0.95) {
  println("similar")
} else {
  println("not similar")
}

Radial distance is more when images are similar. DCT and Marr distances are less when images are similar.

radial: 0.9538751316650709
dct: 1
marr: 0.3315972222222222

radial: 0.36438994709451805
dct: 36
marr: 0.4947916666666667

Warning

My results is not compatible with original pHash. Use original library if you have an opportunity.
Also, it works much slower than c++ version (about 5-7 times).

Thanks

About

Image comparison by hash codes

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages