Class KMeansClassifier
- java.lang.Object
-
- dev.brachtendorf.jimagehash.matcher.categorize.KMeansClassifier
-
- All Implemented Interfaces:
CategoricalImageMatcher
public class KMeansClassifier extends Object implements CategoricalImageMatcher
The kMeans approach requires to know the number of clusters beforehand.- Since:
- 3.0.0
- Author:
- Kilian
-
-
Constructor Summary
Constructors Constructor Description KMeansClassifier(int k, HashingAlgorithm hasher)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddImage(BufferedImage bi, String uniqueId)CategorizationResultcategorizeImage(BufferedImage bi)Compute the category of the supplied image.CategorizationResultcategorizeImageAndAdd(BufferedImage bi, String uniqueId)Compute the closest category of an image and afterwards add it to the internal categorization queue.List<Integer>getCategories()Get a list of available categories this matcher matched images to.intgetCategory(String uniqueId)Get the current category of the image described by this unique id.List<String>getImagesInCategory(int category)Get the unique id's of all images mapped to this categoryvoidrecomputeCategories()Recompute the category definition of this clustering matcher and it's nested matchers.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface dev.brachtendorf.jimagehash.matcher.categorize.CategoricalImageMatcher
categorizeImage, categorizeImageAndAdd
-
-
-
-
Constructor Detail
-
KMeansClassifier
public KMeansClassifier(int k, HashingAlgorithm hasher)- Parameters:
k- The number of clusters tohasher- The hashing algorithm used to create hashes
-
-
Method Detail
-
recomputeCategories
public void recomputeCategories()
Description copied from interface:CategoricalImageMatcherRecompute the category definition of this clustering matcher and it's nested matchers.Recomputing categories will take recently added images into account and update image/category affiliation if necessary. This operation needs to be called manually due to the potential high cost of this method call.
Unless otherwise noted the matcher makes no guarantee that the image category does not change with this method execution.
- Specified by:
recomputeCategoriesin interfaceCategoricalImageMatcher
-
categorizeImage
public CategorizationResult categorizeImage(BufferedImage bi)
Description copied from interface:CategoricalImageMatcherCompute the category of the supplied image. A category is a collection of similar images mapped to a common hash which minimizes the distance of all hashes mapped to this category.- Specified by:
categorizeImagein interfaceCategoricalImageMatcher- Parameters:
bi- The buffered image to categorize- Returns:
- a pair whose first value returns the category and second value returns a distance measure between the category and the supplied image. Smaller distances meaning a closer match
-
addImage
public void addImage(BufferedImage bi, String uniqueId)
-
categorizeImageAndAdd
public CategorizationResult categorizeImageAndAdd(BufferedImage bi, String uniqueId)
Description copied from interface:CategoricalImageMatcherCompute the closest category of an image and afterwards add it to the internal categorization queue. Some matchers may choose to immediately update the current category to reflect the changes.The add action is implementation depended. Some categorizers may choose to directly incorporate the image and update it's category representation other algorithms may require a call to
CategoricalImageMatcher.recomputeCategories()before the addition takes effect.- Specified by:
categorizeImageAndAddin interfaceCategoricalImageMatcher- Parameters:
bi- the image to categorizeuniqueId- the unique id to reference the image by.- Returns:
- the currently closest cluster for this image.
-
getCategories
public List<Integer> getCategories()
Description copied from interface:CategoricalImageMatcherGet a list of available categories this matcher matched images to. Each category represents a set of images with high similarity.- Specified by:
getCategoriesin interfaceCategoricalImageMatcher- Returns:
- A list of id's
-
getImagesInCategory
public List<String> getImagesInCategory(int category)
Description copied from interface:CategoricalImageMatcherGet the unique id's of all images mapped to this category- Specified by:
getImagesInCategoryin interfaceCategoricalImageMatcher- Parameters:
category- to check for- Returns:
- a list of all unique id's mapped to this category
-
getCategory
public int getCategory(String uniqueId)
Description copied from interface:CategoricalImageMatcherGet the current category of the image described by this unique id. A category usually maps an image to a cluster.- Specified by:
getCategoryin interfaceCategoricalImageMatcher- Parameters:
uniqueId- the id of a previously added image- Returns:
- the category
-
-