Class ConsecutiveMatcher

  • Direct Known Subclasses:
    CumulativeMatcher

    public class ConsecutiveMatcher
    extends TypedImageMatcher
    Convenience class allowing to chain multiple hashing algorithms to find similar images. The ConsecutiveMatcher 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.

    InMemoryImage matchers apply the added hashing algorithms successively, requiring all algorithms added to agree to produce a match, discarding the result fast if one of the algorithms does not consider the images similar.

    This means that the order of the hashing algorithms supplied hash has an impact on the performance, the fastest algorithm should be added first.

    Author:
    Kilian
    • Constructor Detail

      • ConsecutiveMatcher

        public ConsecutiveMatcher()
    • Method Detail

      • addHashingAlgorithm

        public void addHashingAlgorithm​(HashingAlgorithm algo,
                                        double threshold,
                                        boolean normalized)
        Append a new hashing algorithm which will be executed after all hash algorithms passed the test.
        Overrides:
        addHashingAlgorithm in class TypedImageMatcher
        Parameters:
        algo - The algorithms to be added
        threshold - the threshold the hamming distance may be in order to pass as identical image.
        normalized - Weather the normalized or default hamming distance shall be used. The normalized hamming distance will be in range of [0-1] while the hamming distance depends on the length of the hash
      • removeHashingAlgo

        public boolean removeHashingAlgo​(HashingAlgorithm algo)
        Removes the hashing algorithms from the image matcher.
        Overrides:
        removeHashingAlgo in class TypedImageMatcher
        Parameters:
        algo - the algorithm to be removed
        Returns:
        true if the algorithms was removed, false otherwise
      • clearHashingAlgorithms

        public void clearHashingAlgorithms()
        Remove all hashing algorithms used by this image matcher instance. At least one algorithm has to be supplied before imaages can be checked for similarity
        Overrides:
        clearHashingAlgorithms in class TypedImageMatcher
      • addImage

        public void addImage​(BufferedImage image)
        Add the image to the matcher allowing the image to be found in future searches.
        Parameters:
        image - The image whose hash will be added to the matcher
      • addImages

        public void addImages​(BufferedImage... imagesToAdd)
        Add the images to the matcher allowing the image to be found in future searches.
        Parameters:
        imagesToAdd - The images whose hash will be added to the matcher
      • getMatchingImages

        public PriorityQueue<Result<BufferedImage>> getMatchingImages​(BufferedImage image)
        Search 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
        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
      • printAllTrees

        public void printAllTrees()
        Print all binary trees currently in use by this image matcher. This gives an internal view of the saved images