Class WeightedCategoricalMatcher
- java.lang.Object
-
- dev.brachtendorf.jimagehash.matcher.PlainImageMatcher
-
- dev.brachtendorf.jimagehash.matcher.categorize.AbstractCategoricalMatcher
-
- dev.brachtendorf.jimagehash.matcher.categorize.CategoricalMatcher
-
- dev.brachtendorf.jimagehash.matcher.categorize.WeightedCategoricalMatcher
-
- All Implemented Interfaces:
CategoricalImageMatcher
public class WeightedCategoricalMatcher extends CategoricalMatcher
Cluster images into common categories. This matcher clusters images by computing the distance to the closest cluster and adds an image if it is within a given distance. This method works only approximateCategoricalMatcher.recomputeCategories()has to be called after images have been added.Cluster centeroids are represented as FuzzyHashes a prot hash represented as mode hash of all added images.
Opposed to the categorical matcher this matcher calculates the distances to clusters using the weighted distance, resulting in more accurate results but at the cost of increase computational requirements.
- Since:
- 3.0.0
- Author:
- Kilian
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWeightedCategoricalMatcher.DimReduction
-
Field Summary
Fields Modifier and Type Field Description protected ClusterResult[]clusterResultprotected FuzzyBinaryTreefuzzyBinaryTree-
Fields inherited from class dev.brachtendorf.jimagehash.matcher.categorize.CategoricalMatcher
cachedHashes, categories, categoriesAltered, clusterHash, clusterQuality, clusterRecomputed, clusterReverseLookup, newCategoryThreshold, subCategoryMatcher
-
Fields inherited from class dev.brachtendorf.jimagehash.matcher.categorize.AbstractCategoricalMatcher
cachedImagesInCategory, reverseImageCategoryMap
-
Fields inherited from class dev.brachtendorf.jimagehash.matcher.PlainImageMatcher
steps
-
-
Constructor Summary
Constructors Constructor Description WeightedCategoricalMatcher(double newCategoryThreshold, WeightedCategoricalMatcher.DimReduction reductionTechnique)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddHashingAlgorithm(HashingAlgorithm algo)Append a new hashing algorithm to be used by this matcher.protected voidclusterPostcomputation()Method invoked afterCategoricalMatcher.recomputeClusters(int)is being called.protected voidclusterPrecomputation()Method invoked beforeCategoricalMatcher.recomputeClusters(int)is being called.protected doublecomputeDistanceForCategory(Hash[] hashes, int category, double bestDistance)Compute the distance between an image and a category cluster midpoint.protected doublecomputeDistanceToCluster(FuzzyHash cluster, Hash imageHash)protected intgetCategory(int iter, String uniqueId, Hash[] hashes, Set<Integer> categoriesAltered)-
Methods inherited from class dev.brachtendorf.jimagehash.matcher.categorize.CategoricalMatcher
addCategoricalImage, addCategoricalImage, addCategoricalImage, addCategoricalImages, addCategoricalImages, categoricalHashToImage, categorizeImage, categorizeImage, categorizeImage, categorizeImageAndAdd, cleanupEmptyCategories, getAverageDistanceWithinCluster, getCategories, getCategoriesSortedByImageCount, getClusterAverageHash, printClusterInfo, recomputeCategories, recomputeClusters, resetBitWeights, updateCategories
-
Methods inherited from class dev.brachtendorf.jimagehash.matcher.categorize.AbstractCategoricalMatcher
getCategory, getImageCountInCategory, getImagesInCategory, isCategorized
-
Methods inherited from class dev.brachtendorf.jimagehash.matcher.PlainImageMatcher
clearHashingAlgorithms, equals, getAlgorithms, hashCode, removeHashingAlgorithm
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface dev.brachtendorf.jimagehash.matcher.categorize.CategoricalImageMatcher
categorizeImage, categorizeImageAndAdd
-
-
-
-
Field Detail
-
clusterResult
protected transient ClusterResult[] clusterResult
-
fuzzyBinaryTree
protected transient FuzzyBinaryTree fuzzyBinaryTree
-
-
Constructor Detail
-
WeightedCategoricalMatcher
public WeightedCategoricalMatcher(double newCategoryThreshold, WeightedCategoricalMatcher.DimReduction reductionTechnique)
-
-
Method Detail
-
clusterPostcomputation
protected void clusterPostcomputation()
Description copied from class:CategoricalMatcherMethod invoked afterCategoricalMatcher.recomputeClusters(int)is being called.- Overrides:
clusterPostcomputationin classCategoricalMatcher
-
clusterPrecomputation
protected void clusterPrecomputation()
Description copied from class:CategoricalMatcherMethod invoked beforeCategoricalMatcher.recomputeClusters(int)is being called.- Overrides:
clusterPrecomputationin classCategoricalMatcher
-
getCategory
protected int getCategory(int iter, String uniqueId, Hash[] hashes, Set<Integer> categoriesAltered)- Overrides:
getCategoryin classCategoricalMatcher
-
computeDistanceForCategory
protected double computeDistanceForCategory(Hash[] hashes, int category, double bestDistance)
Description copied from class:CategoricalMatcherCompute the distance between an image and a category cluster midpoint. This method is used to compute the minimum distance and therefore might cut the computation short if the distance is higher than the supplied best distance cutoff.- Overrides:
computeDistanceForCategoryin classCategoricalMatcher- Parameters:
hashes- an array containing the hash for an image for each hashing algorithm added to this matchercategory- the category to compute the distance forbestDistance- the best distance found so far. May be used to- Returns:
- the distance between the image and the category midpoint or Double.MAX_VALUE if bestDistance was reached and copmutation was not finished
-
addHashingAlgorithm
public boolean addHashingAlgorithm(HashingAlgorithm algo)
Description copied from class:PlainImageMatcherAppend a new hashing algorithm to be used by this matcher. The same algorithm may only be added once. Attempts to add the same algorithm twice is a NOP.For some matchers the order of added hashing algorithms is crucial. The order the hashes are added is preserved.
- Overrides:
addHashingAlgorithmin classCategoricalMatcher- Parameters:
algo- The algorithms to be added- Returns:
- true if the algorithm was added, false if it was already present
-
computeDistanceToCluster
protected double computeDistanceToCluster(FuzzyHash cluster, Hash imageHash)
- Overrides:
computeDistanceToClusterin classCategoricalMatcher
-
-