Class AbstractCategoricalMatcher
- java.lang.Object
-
- dev.brachtendorf.jimagehash.matcher.PlainImageMatcher
-
- dev.brachtendorf.jimagehash.matcher.categorize.AbstractCategoricalMatcher
-
- All Implemented Interfaces:
CategoricalImageMatcher
- Direct Known Subclasses:
CategoricalMatcher
public abstract class AbstractCategoricalMatcher extends PlainImageMatcher implements CategoricalImageMatcher
An abstract implementation of the categorical image matcher supporting classes to keep track of the categories an image was matched to.It is up to the implementing class to keep the field
cachedImagesInCategoryandreverseImageCategoryMapin a valid state.- Since:
- 3.0.0
- Author:
- Kilian
-
-
Field Summary
Fields Modifier and Type Field Description protected Map<Integer,List<String>>cachedImagesInCategoryprotected Map<String,Integer>reverseImageCategoryMap-
Fields inherited from class dev.brachtendorf.jimagehash.matcher.PlainImageMatcher
steps
-
-
Constructor Summary
Constructors Constructor Description AbstractCategoricalMatcher()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description CategorizationResultcategorizeImage(BufferedImage bi)Compute the category of the supplied image.protected abstract CategorizationResultcategorizeImage(String uniqueId, BufferedImage bi)abstract 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.intgetImageCountInCategory(int category)Get the number of images that are were added in this category.List<String>getImagesInCategory(int category)Get the unique id's of all images mapped to this categorybooleanisCategorized(String uniqueId)Check if an image has already been added to the categorizer-
Methods inherited from class dev.brachtendorf.jimagehash.matcher.PlainImageMatcher
addHashingAlgorithm, 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, recomputeCategories
-
-
-
-
Method Detail
-
categorizeImageAndAdd
public abstract 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.
-
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
-
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
-
categorizeImage
protected abstract CategorizationResult categorizeImage(String uniqueId, BufferedImage bi)
-
isCategorized
public boolean isCategorized(String uniqueId)
Check if an image has already been added to the categorizer- Parameters:
uniqueId- the unique id of the image- Returns:
- true if it has been added, false otherwise
-
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
-
getImageCountInCategory
public int getImageCountInCategory(int category)
Get the number of images that are were added in this category.- Parameters:
category- to retrieve the number of images from.- Returns:
- he number of images that were mapped and added to this category
-
-