You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.1 KiB
93 lines
3.1 KiB
package com.sothr.imagetools.hash
|
|
|
|
import java.io.File
|
|
import javax.imageio.ImageIO
|
|
|
|
import scala.collection.mutable
|
|
|
|
class HashServiceAHashTest extends HashServiceBaseTest {
|
|
|
|
def ahashTestCase(filePath: String): Long = {
|
|
val sample = new File(filePath)
|
|
val image = ImageIO.read(sample)
|
|
HashService.getAhash(ahashSetting, image)
|
|
}
|
|
|
|
test("Calculate AHash Large Sample Image 1") {
|
|
debug("Starting 'Calculate AHash Large Sample Image 1' test")
|
|
val sample = new File(LargeSampleImage1)
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}")
|
|
val image = ImageIO.read(sample)
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}")
|
|
val hash = HashService.getAhash(ahashSetting, image)
|
|
debug(s"Testing that $hash = 36070299219713907L")
|
|
assert(hash == 36070299219713907L)
|
|
}
|
|
|
|
test("Calculate AHash Medium Sample Image 1") {
|
|
debug("Starting 'Calculate AHash Medium Sample Image 1' test")
|
|
val sample = new File(MediumSampleImage1)
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}")
|
|
val image = ImageIO.read(sample)
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}")
|
|
val hash = HashService.getAhash(ahashSetting, image)
|
|
debug(s"Testing that $hash = 36070299219713907L")
|
|
assert(hash == 36070299219713907L)
|
|
}
|
|
|
|
test("Calculate AHash Small Sample Image 1") {
|
|
debug("Starting 'Calculate AHash Small Sample Image 1' test")
|
|
val sample = new File(SmallSampleImage1)
|
|
debug(s"Testing File: ${sample.getAbsolutePath} exists: ${sample.exists}")
|
|
val image = ImageIO.read(sample)
|
|
debug(s"Image: width: ${image.getWidth} height: ${image.getHeight}")
|
|
val hash = HashService.getAhash(ahashSetting, image)
|
|
debug(s"Testing that $hash = 36070299219713907L")
|
|
assert(hash == 36070299219713907L)
|
|
}
|
|
|
|
test("AHash Of Large, Medium, And Small Sample 1 Must Be Similar") {
|
|
val largeHash = ahashTestCase(LargeSampleImage1)
|
|
val mediumHash = ahashTestCase(MediumSampleImage1)
|
|
val smallHash = ahashTestCase(SmallSampleImage1)
|
|
assert(HashService.areHashSimilar(ahashSetting, largeHash, mediumHash))
|
|
assert(HashService.areHashSimilar(ahashSetting, largeHash, smallHash))
|
|
assert(HashService.areHashSimilar(ahashSetting, mediumHash, smallHash))
|
|
}
|
|
|
|
test("Benchmark AHash") {
|
|
info("Benchmarking AHash")
|
|
info("AHash Large Image 3684x2736")
|
|
val time = new mutable.MutableList[Long]()
|
|
for (_ <- 0 until benchmarkRuns) {
|
|
time += getTime {
|
|
ahashTestCase(LargeSampleImage1)
|
|
}
|
|
}
|
|
|
|
val largeMean = getMean(time.toArray[Long])
|
|
info(s"The mean time of ${time.size} tests for large was: $largeMean ms")
|
|
time.clear()
|
|
info("AHash Medium Image 1824x1368")
|
|
for (_ <- 0 until benchmarkRuns) {
|
|
time += getTime {
|
|
ahashTestCase(MediumSampleImage1)
|
|
}
|
|
}
|
|
|
|
val mediumMean = getMean(time.toArray[Long])
|
|
info(s"The mean time of ${time.size} tests for medium was: $mediumMean ms")
|
|
time.clear()
|
|
info("AHash Small Image 912x684")
|
|
for (_ <- 0 until benchmarkRuns) {
|
|
time += getTime {
|
|
ahashTestCase(SmallSampleImage1)
|
|
}
|
|
}
|
|
|
|
val smallMean = getMean(time.toArray[Long])
|
|
info(s"The mean time of ${time.size} tests for small was: $smallMean ms")
|
|
time.clear()
|
|
assert(true)
|
|
}
|
|
}
|