Class KMeansClassifier

    • Constructor Detail

      • KMeansClassifier

        public KMeansClassifier​(int k,
                                HashingAlgorithm hasher)
        Parameters:
        k - The number of clusters to
        hasher - The hashing algorithm used to create hashes
    • Method Detail

      • recomputeCategories

        public void recomputeCategories()
        Description copied from interface: CategoricalImageMatcher
        Recompute 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:
        recomputeCategories in interface CategoricalImageMatcher
      • categorizeImage

        public CategorizationResult categorizeImage​(BufferedImage bi)
        Description copied from interface: CategoricalImageMatcher
        Compute 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:
        categorizeImage in interface CategoricalImageMatcher
        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
      • categorizeImageAndAdd

        public CategorizationResult categorizeImageAndAdd​(BufferedImage bi,
                                                          String uniqueId)
        Description copied from interface: CategoricalImageMatcher
        Compute 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:
        categorizeImageAndAdd in interface CategoricalImageMatcher
        Parameters:
        bi - the image to categorize
        uniqueId - 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: CategoricalImageMatcher
        Get the current category of the image described by this unique id. A category usually maps an image to a cluster.
        Specified by:
        getCategory in interface CategoricalImageMatcher
        Parameters:
        uniqueId - the id of a previously added image
        Returns:
        the category