Class PersitentBinaryTreeMatcher

    • Field Detail

      • addedImages

        protected HashSet<String> addedImages
        keep track of images already added. No reason to rehash
      • cacheAddedHashes

        protected boolean cacheAddedHashes
      • cachedHashes

        protected Map<HashingAlgorithm,​Map<String,​Hash>> cachedHashes
        Save the hashes of added images mapped to their unique id for fast retrieval.
    • Constructor Detail

      • PersitentBinaryTreeMatcher

        public PersitentBinaryTreeMatcher​(boolean cacheAddedHashes)
        TODO handle serialization empty constructor?
        Parameters:
        cacheAddedHashes - Additionally to the binary tree hashes of added images will be mapped to their uniqueId. This allows to retrieve matches of added images without loading the image file from disk speeding up the operation Immensely. Saving the hash in a hashmap increases memory overhead.

        Use this setting if getMatchingImages(java.io.File) likely contains an image already added to the match prior.

    • Method Detail

      • getMatchingImages

        public PriorityQueue<Result<String>> getMatchingImages​(BufferedImage image)
        Description copied from class: PersistentImageMatcher
        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
        Specified by:
        getMatchingImages in class PersistentImageMatcher
        Parameters:
        image - the image to check all saved images against
        Returns:
        a list of unique id's identifying the previously matched images sorted by distance of the last applied algorithm
      • getMatchingImagesInternal

        protected abstract PriorityQueue<Result<String>> getMatchingImagesInternal​(BufferedImage bi,
                                                                                   String uniqueId)
        Return 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 getHash(HashingAlgorithm, String, BufferedImage) method call.

        Parameters:
        bi - the buffered image to match or null
        uniqueId - the uniqueId of a previously cached image or null
        Returns:
        a list of unique id's identifying the previously matched images sorted by distance.
      • 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 PersistentImageMatcher
        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 PersistentImageMatcher
      • printAllTrees

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