Class CumulativeMatcher
- java.lang.Object
-
- dev.brachtendorf.jimagehash.matcher.TypedImageMatcher
-
- dev.brachtendorf.jimagehash.matcher.persistent.PersistentImageMatcher
-
- dev.brachtendorf.jimagehash.matcher.persistent.PersitentBinaryTreeMatcher
-
- dev.brachtendorf.jimagehash.matcher.persistent.CumulativeMatcher
-
- All Implemented Interfaces:
Serializable
public class CumulativeMatcher extends PersitentBinaryTreeMatcher
Instead of early aborting if one algorithm fails like theConsecutiveMatcher, this class looks at the summed distance and decides if images match.Example: A CumulativeInMemoryMatcher with a threshold of 0.6 (may be any value desired) Pass: Hasher computes a distance of 0.1 Hasher1 computes a distance of 0.4 ------- Since the summed distance of 0.5 is smaller than 0.6, the two images are considered a match Fail: Hasher computes a distance of 0.7 Hasher1 not executed since distance already greater than threshold ----------------------------- Not considered a match
Additionally each hashing algorithm may be appointed a weight value which transforms the returned hash value accordingly, increasing or decreasing the importance of this algorithm.- Since:
- 2.0.0
- Author:
- Kilian
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class dev.brachtendorf.jimagehash.matcher.TypedImageMatcher
TypedImageMatcher.AlgoSettings
-
-
Field Summary
-
Fields inherited from class dev.brachtendorf.jimagehash.matcher.persistent.PersitentBinaryTreeMatcher
addedImages, binTreeMap, cacheAddedHashes, cachedHashes
-
Fields inherited from class dev.brachtendorf.jimagehash.matcher.persistent.PersistentImageMatcher
addedImageMap, lockedState
-
Fields inherited from class dev.brachtendorf.jimagehash.matcher.TypedImageMatcher
steps
-
-
Constructor Summary
Constructors Modifier Constructor Description CumulativeMatcher(boolean cacheAddedHashes, double threshold)Create a cumulative in memory image matcher with the specified normalized thresholdCumulativeMatcher(boolean cacheAddedHashes, double threshold, boolean normalized)Create a cumulative in memory image matcher with the specified thresholdprotectedCumulativeMatcher(boolean cacheAddedHashes, TypedImageMatcher.AlgoSettings setting)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHashingAlgorithm(HashingAlgorithm algo)Add a hashing algorithm to the matcher with a weight multiplier of 1.voidaddHashingAlgorithm(HashingAlgorithm algo, double weight)Add a hashing algorithm to the matcher with the given weight multiplier.voidaddHashingAlgorithm(HashingAlgorithm algo, double weight, boolean dummy)Add a hashing algorithm to the matcher with the given weight multiplier.protected PriorityQueue<Result<String>>getMatchingImagesInternal(BufferedImage image, String uniqueId)Return a list of images that are considered matching by the definition of this matcher.-
Methods inherited from class dev.brachtendorf.jimagehash.matcher.persistent.PersitentBinaryTreeMatcher
addImageInternal, clearHashingAlgorithms, equals, getHash, getMatchingImages, getMatchingImages, hashCode, printAllTrees, removeHashingAlgo
-
Methods inherited from class dev.brachtendorf.jimagehash.matcher.persistent.PersistentImageMatcher
addImage, addImage, addImage, addImages, checkLockedState, reconstructState, serializeState
-
Methods inherited from class dev.brachtendorf.jimagehash.matcher.TypedImageMatcher
getAlgorithms
-
-
-
-
Constructor Detail
-
CumulativeMatcher
public CumulativeMatcher(boolean cacheAddedHashes, double threshold)Create a cumulative in memory image matcher with the specified normalized threshold- Parameters:
cacheAddedHashes- Additionally to the binary tree, hashes of added images will be mapped to their uniqueId allowing to retrieve matches of added images without loading the image file from disk. This setting increases memory overhead in exchange for performance.Use this setting if calls to
PersitentBinaryTreeMatcher.getMatchingImages(java.io.File)likely contains an image already added to the match prior.threshold- The cutoff threshold of the summed and scaled distances of all hashing algorithm until an image is considered a match.If a negative threshold is supplied no images will ever be returned.
If additional algorithms are added an increase in the threshold parameter is justified.
-
CumulativeMatcher
public CumulativeMatcher(boolean cacheAddedHashes, double threshold, boolean normalized)Create a cumulative in memory image matcher with the specified threshold- Parameters:
cacheAddedHashes- Additionally to the binary tree, hashes of added images will be mapped to their uniqueId allowing to retrieve matches of added images without loading the image file from disk. This setting increases memory overhead in exchange for performance.Use this setting if calls to
PersitentBinaryTreeMatcher.getMatchingImages(java.io.File)likely contains an image already added to the match prior.threshold- The cutoff threshold of the summed and scaled distances of all hashing algorithm until an image is considered a match.If a negative threshold is supplied no images will ever be returned.
If additional algorithms are added an increase in the threshold parameter is justified.
normalized- If true the threshold is considered the normalized distance created by each added Hashing algorithm.
-
CumulativeMatcher
protected CumulativeMatcher(boolean cacheAddedHashes, TypedImageMatcher.AlgoSettings setting)
-
-
Method Detail
-
addHashingAlgorithm
public void addHashingAlgorithm(HashingAlgorithm algo)
Add a hashing algorithm to the matcher with a weight multiplier of 1. In order for images to match they have to be beneath the threshold of the summed distances of all added hashing algorithms.- Parameters:
algo- The algorithm to add to the matcher.
-
addHashingAlgorithm
public void addHashingAlgorithm(HashingAlgorithm algo, double weight)
Add a hashing algorithm to the matcher with the given weight multiplier. In order for images to match they have to be beneath the threshold of the summed distances of all added hashing algorithms.The weight parameter scales the returned hash distance. For example a weight multiplier of 2 means that the returned distance is multiplied by 2. If the total allowed distance of this matcher is 0.7 and the returned hash is 0.3 * 2 the next algorithm only may return a distance of 0.1 or smaller in order for the image to pass.
- Overrides:
addHashingAlgorithmin classPersistentImageMatcher- Parameters:
algo- The algorithms to be addedweight- The weight multiplier of this algorithm.
-
addHashingAlgorithm
public void addHashingAlgorithm(HashingAlgorithm algo, double weight, boolean dummy)
Add a hashing algorithm to the matcher with the given weight multiplier. In order for images to match they have to be beneath the threshold of the summed distances of all added hashing algorithms. *The weight parameter scales the returned hash distance. For example a weight multiplier of 2 means that the returned distance is multiplied by 2. If the total allowed distance of this matcher is 0.7 and the returned hash is 0.3 * 2 the next algorithm only may return a distance of 0.1 or smaller in order for the image to pass.
- Overrides:
addHashingAlgorithmin classPersitentBinaryTreeMatcher- Parameters:
algo- The algorithms to be addedweight- The weight multiplier of this algorithm.dummy- not used by this type of image matcher. This method signature is only available due to inheritance.
-
getMatchingImagesInternal
protected PriorityQueue<Result<String>> getMatchingImagesInternal(BufferedImage image, String uniqueId)
Description copied from class:PersitentBinaryTreeMatcherReturn a list of images that are considered matching by the definition of this matcher.This method is propagated by the super class allowing to utilize caching techniques to avoid reloading known images. Either the bufferedImage or the uniqueId argument is send depending on if the uniqueId is enough to query the hashes using the
PersitentBinaryTreeMatcher.getHash(HashingAlgorithm, String, BufferedImage)method call.- Specified by:
getMatchingImagesInternalin classPersitentBinaryTreeMatcher- Parameters:
image- the buffered image to match or nulluniqueId- the uniqueId of a previously cached image or null- Returns:
- a list of unique id's identifying the previously matched images sorted by distance.
-
-