ProductPromotion
Logo

Scala

made by https://0x3d.site

GitHub - poslegm/scala-phash: Image comparison by hash codes
Image comparison by hash codes. Contribute to poslegm/scala-phash development by creating an account on GitHub.
Visit Site

GitHub - poslegm/scala-phash: Image comparison by hash codes

GitHub - poslegm/scala-phash: Image comparison by hash codes

Scala pHash

Build Status Maven

Scala fork of pHash library. This library identifies whether images are similar. You can try it at demo page.

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.2.2"

API

There is three functions for each hashing algorithm. Let's consider them by example of DCT hash:

  • def dctHash(image: BufferedImage): Either[Throwable, DCTHash] ― compute image's hash;
  • def unsafeDctHash(image: BufferedImage): DCTHash ― compute image's hash unsafely (danger of exception);
  • def dctHashDistance(hash1: DCTHash, hash2: DCTHash): Long ― compare hashes of two images.

Similar functions written for Marr and Radial Hash algorithms.

All public api with scaladocs decsribed in object PHash.

Example

import scalaphash.PHash._
import javax.imageio.ImageIO

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

val radialDistance: Either[Throwable, Double] = for {
  img1rad <- radialHash(img1)
  img2rad <- radialHash(img2)
} yield radialHashDistance(img1rad, img2rad)

radialDistance.foreach {
  case distance if distance > 0.95 => println("similar")
  case _ => println("not similar")
}

radialDistance.left.foreach(e => println(e.getMessage))

Radial distance is more when images are similar. DCT and Marr distances are less when images are similar. Recommended to make a decision on image similarity when at least two hashes pass thresholds.

radial: 0.9508017124330319
dct: 13
marr: 0.5052083333333334
radial: 0.3996241672331173
dct: 41
marr: 0.4704861111111111

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

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory