scala-phash


License

License

Categories

Categories

Scala Languages
GroupId

GroupId

com.github.poslegm
ArtifactId

ArtifactId

scala-phash_2.13
Last Version

Last Version

1.2.2
Release Date

Release Date

Type

Type

jar
Description

Description

scala-phash
scala-phash
Project URL

Project URL

https://github.com/poslegm/scala-phash
Project Organization

Project Organization

com.github.poslegm
Source Code Management

Source Code Management

https://github.com/poslegm/scala-phash

Download scala-phash_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.poslegm/scala-phash_2.13/ -->
<dependency>
    <groupId>com.github.poslegm</groupId>
    <artifactId>scala-phash_2.13</artifactId>
    <version>1.2.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.poslegm/scala-phash_2.13/
implementation 'com.github.poslegm:scala-phash_2.13:1.2.2'
// https://jarcasting.com/artifacts/com.github.poslegm/scala-phash_2.13/
implementation ("com.github.poslegm:scala-phash_2.13:1.2.2")
'com.github.poslegm:scala-phash_2.13:jar:1.2.2'
<dependency org="com.github.poslegm" name="scala-phash_2.13" rev="1.2.2">
  <artifact name="scala-phash_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.poslegm', module='scala-phash_2.13', version='1.2.2')
)
libraryDependencies += "com.github.poslegm" % "scala-phash_2.13" % "1.2.2"
[com.github.poslegm/scala-phash_2.13 "1.2.2"]

Dependencies

compile (3)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.0
org.scalactic : scalactic_2.13 jar 3.0.8
com.jhlabs : filters jar 2.0.235-1

test (1)

Group / Artifact Type Version
org.scalatest : scalatest_2.13 jar 3.0.8

Project Modules

There are no modules declared in this project.

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

Versions

Version
1.2.2