Class CumulativeMatcher
- java.lang.Object
-
- dev.brachtendorf.jimagehash.matcher.TypedImageMatcher
-
- dev.brachtendorf.jimagehash.matcher.cached.ConsecutiveMatcher
-
- dev.brachtendorf.jimagehash.matcher.cached.CumulativeMatcher
-
public class CumulativeMatcher extends ConsecutiveMatcher
Convenience class allowing to chain multiple hashing algorithms to find similar images. The CumulativeMatcher keeps the hashes and buffered images in cache, allowing to add and remove hashing algorithms on the fly as well as retrieving the bufferedimage object of matches. On the flip side this approach requires much more memory and is unsuited for large collection of images. Contrary to theConsecutiveMatcher, instead of early aborting if one algorithm fails, 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
-
-
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.cached.ConsecutiveMatcher
addedImages, binTreeMap
-
Fields inherited from class dev.brachtendorf.jimagehash.matcher.TypedImageMatcher
steps
-
-
Constructor Summary
Constructors Constructor Description CumulativeMatcher(double threshold)Create a cumulative in memory image matcher with the specified thresholdCumulativeMatcher(double threshold, boolean normalized)CumulativeMatcher(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.PriorityQueue<Result<BufferedImage>>getMatchingImages(BufferedImage image)Search for all similar images passing the algorithm filters supplied to this matcher.-
Methods inherited from class dev.brachtendorf.jimagehash.matcher.cached.ConsecutiveMatcher
addImage, addImages, clearHashingAlgorithms, getAlgorithms, printAllTrees, removeHashingAlgo
-
Methods inherited from class dev.brachtendorf.jimagehash.matcher.TypedImageMatcher
equals, hashCode
-
-
-
-
Constructor Detail
-
CumulativeMatcher
public CumulativeMatcher(double threshold)
Create a cumulative in memory image matcher with the specified threshold- Parameters:
threshold- The cutoff threshold of the summed and scaled normalizted 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(double threshold, boolean normalized)
-
CumulativeMatcher
public CumulativeMatcher(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 classTypedImageMatcher- 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 classConsecutiveMatcher- 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.
-
getMatchingImages
public PriorityQueue<Result<BufferedImage>> getMatchingImages(BufferedImage image)
Description copied from class:ConsecutiveMatcherSearch for all similar images passing the algorithm filters supplied to this matcher. If the image itself was added to the tree it will be returned with a distance of 0- Overrides:
getMatchingImagesin classConsecutiveMatcher- Parameters:
image- The image other images will be matched against- Returns:
- Similar images Return all images sorted by the hamming distance of the last applied algorithms
-
-