Class ConsecutiveMatcher
- java.lang.Object
-
- dev.brachtendorf.jimagehash.matcher.TypedImageMatcher
-
- dev.brachtendorf.jimagehash.matcher.cached.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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class dev.brachtendorf.jimagehash.matcher.TypedImageMatcher
TypedImageMatcher.AlgoSettings
-
-
Field Summary
Fields Modifier and Type Field Description protected HashSet<BufferedImage>addedImageskeep track of images already added.protected HashMap<HashingAlgorithm,BinaryTree<BufferedImage>>binTreeMapBinary Tree holding results for each individual hashing algorithm-
Fields inherited from class dev.brachtendorf.jimagehash.matcher.TypedImageMatcher
steps
-
-
Constructor Summary
Constructors Constructor Description ConsecutiveMatcher()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHashingAlgorithm(HashingAlgorithm algo, double threshold, boolean normalized)Append a new hashing algorithm which will be executed after all hash algorithms passed the test.voidaddImage(BufferedImage image)Add the image to the matcher allowing the image to be found in future searches.voidaddImages(BufferedImage... imagesToAdd)Add the images to the matcher allowing the image to be found in future searches.voidclearHashingAlgorithms()Remove all hashing algorithms used by this image matcher instance.Map<HashingAlgorithm,TypedImageMatcher.AlgoSettings>getAlgorithms()Return an immutable map copy of the algorithms currently used in the matcher.PriorityQueue<Result<BufferedImage>>getMatchingImages(BufferedImage image)Search for all similar images passing the algorithm filters supplied to this matcher.voidprintAllTrees()Print all binary trees currently in use by this image matcher.booleanremoveHashingAlgo(HashingAlgorithm algo)Removes the hashing algorithms from the image matcher.-
Methods inherited from class dev.brachtendorf.jimagehash.matcher.TypedImageMatcher
addHashingAlgorithm, equals, hashCode
-
-
-
-
Field Detail
-
addedImages
protected HashSet<BufferedImage> addedImages
keep track of images already added. No reason to rehash
-
binTreeMap
protected HashMap<HashingAlgorithm,BinaryTree<BufferedImage>> binTreeMap
Binary Tree holding results for each individual hashing algorithm
-
-
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:
addHashingAlgorithmin classTypedImageMatcher- Parameters:
algo- The algorithms to be addedthreshold- 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:
removeHashingAlgoin classTypedImageMatcher- 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:
clearHashingAlgorithmsin classTypedImageMatcher
-
getAlgorithms
public Map<HashingAlgorithm,TypedImageMatcher.AlgoSettings> getAlgorithms()
Return an immutable map copy of the algorithms currently used in the matcher. This map is a hard copy of the hashmap and does not updated if the underlying collection gets altered- Overrides:
getAlgorithmsin classTypedImageMatcher- Returns:
- A map containing all algorithms used in this matcher
-
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
-
-