Class 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 the ConsecutiveMatcher, 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
    • 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)
    • 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:
        addHashingAlgorithm in class TypedImageMatcher
        Parameters:
        algo - The algorithms to be added
        weight - 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:
        addHashingAlgorithm in class ConsecutiveMatcher
        Parameters:
        algo - The algorithms to be added
        weight - The weight multiplier of this algorithm.
        dummy - not used by this type of image matcher. This method signature is only available due to inheritance.