Class DifferenceHash
- java.lang.Object
-
- dev.brachtendorf.jimagehash.hashAlgorithms.HashingAlgorithm
-
- dev.brachtendorf.jimagehash.hashAlgorithms.DifferenceHash
-
- All Implemented Interfaces:
Serializable
public class DifferenceHash extends HashingAlgorithm
Calculates a hash based on gradient tracking. This hash is cheap to compute and provides a high degree of accuracy. Robust to a huge range of color transformation- Since:
- 1.0.0
- Author:
- Kilian
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDifferenceHash.DHashAn extended hash class allowing dhashes to be visually represented.static classDifferenceHash.PrecisionAlgorithm precision used during calculation.
-
Field Summary
-
Fields inherited from class dev.brachtendorf.jimagehash.hashAlgorithms.HashingAlgorithm
bitResolution, immutableState, keyResolution, opaqueReplacementColor, opaqueReplacementThreshold, preProcessing
-
-
Constructor Summary
Constructors Constructor Description DifferenceHash(int bitResolution, DifferenceHash.Precision precision)Create a difference hasher with the given settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HashcreateAlgorithmSpecificHash(Hash original)Wraps the values supplied in the argument hash into a hash object as it would be produced by this algorithm.DifferenceHash.PrecisiongetPrecision()Hashhash(BufferedImage image)Calculate a hash for the given image.protected BigIntegerhash(BufferedImage image, HashBuilder hash)Calculate a hash for the given image.protected intprecomputeAlgoId()A unique id identifying the settings and algorithms used to generate the output result.-
Methods inherited from class dev.brachtendorf.jimagehash.hashAlgorithms.HashingAlgorithm
addFilter, algorithmId, createPixelAccessor, equals, getKeyResolution, getOpaqueReplacementColor, getOpaqueReplacementThreshold, hash, hash, hash, hashCode, removeFilter, setOpaqueHandling, setOpaqueHandling, toString
-
-
-
-
Constructor Detail
-
DifferenceHash
public DifferenceHash(int bitResolution, DifferenceHash.Precision precision)Create a difference hasher with the given settings. The bit resolution always corresponds to the simple precision value and will increase accordingly depending on the precision chosen.Tests have shown that a 64 bit simple precision hash usually performs better than a 32 bit double precision hash.
- Parameters:
bitResolution- The bit resolution specifies the final length of the generated hash. A higher resolution will increase computation time and space requirement while being able to track finer detail in the image. Be aware that a high resolution is not always desired. The bit resolution is only an approximation of the final hash length.precision- Algorithm precision. Allowed Values:- Simple:
- Calculates top - bottom gradient
- Double:
- Additionally computes left - right gradient (doubles key length)
- Tripple:
- Additionally computes diagonal gradient (triples key length)
-
-
Method Detail
-
hash
protected BigInteger hash(BufferedImage image, HashBuilder hash)
Description copied from class:HashingAlgorithmCalculate a hash for the given image. Invoking the hash function on the same image has to return the same hash value. A comparison of the hashes relates to the similarity of the images. The lower the value the more similar the images are. Equal images will produce a similarity of 0.This method is intended to be overwritten by implementations and takes a baseHash argument to allow concatenating multiple hashes as well to be able to compute the effective hash length in
HashingAlgorithm.getKeyResolution(). Preceding 0's are omitted in big integer objects, while the usual hamming distance can be calculated due to xoring without issue the normalized distance requires the potential length of the key to be known.- Specified by:
hashin classHashingAlgorithm- Parameters:
image- Image whose hash will be calculatedhash- a hash builder used to construct the hash- Returns:
- the hash encoded as a big integer
-
precomputeAlgoId
protected int precomputeAlgoId()
Description copied from class:HashingAlgorithmA unique id identifying the settings and algorithms used to generate the output result. This method shall contain a hash code for the object which- Stays consistent throughout restart of the jvm
- Value does not change after the constructor finished
- Must return the same value if two instances compute the same hashes for identical input
Even if different bitResolutions are used in the constructor
HashingAlgorithm(int)the algorithId MUST return the same id for two instances if the returned hashes for the same input will always be equal. Therefore instead of checking against the bitResolution the actual resolution as returned byHashingAlgorithm.getKeyResolution()should be used. This method algorithm id's as information available to the child class and will be extended by the hashcode of the kernels.- Specified by:
precomputeAlgoIdin classHashingAlgorithm- Returns:
- the preliminary algorithm id identifying this hashing algorithm
-
hash
public Hash hash(BufferedImage image)
Description copied from class:HashingAlgorithmCalculate a hash for the given image. Invoking the hash function on the same image has to return the same hash value. A comparison of the hashes relates to the similarity of the images. The lower the value the more similar the images are. Equal images will produce a similarity of 0.- Overrides:
hashin classHashingAlgorithm- Parameters:
image- Image whose hash will be calculated- Returns:
- The hash representing the image
- See Also:
Hash
-
createAlgorithmSpecificHash
public Hash createAlgorithmSpecificHash(Hash original)
Description copied from class:HashingAlgorithmWraps the values supplied in the argument hash into a hash object as it would be produced by this algorithm.Some algorithms may choose to return an extended hash class to overwrite certain behavior, in particular the
Hash.toImage(int)is likely to differ.If the algorithm does not utilize a special hash sub class this method returns the supplied argument.
- Overrides:
createAlgorithmSpecificHashin classHashingAlgorithm- Parameters:
original- the hash to transform- Returns:
- a hash as it would be created by this algorithm.
-
getPrecision
public DifferenceHash.Precision getPrecision()
-
-