Class ImageAnalysis

java.lang.Object
com.github.darksoulq.abyssallib.common.color.ImageAnalysis

public class ImageAnalysis extends Object
A utility class for performing advanced color analysis on BufferedImage instances.

This class provides methods for dominant color extraction using K-Means clustering, average color calculation, and histogram-based color quantization.

  • Constructor Details

    • ImageAnalysis

      public ImageAnalysis()
  • Method Details

    • extractDominantColors

      public static ColorPalette extractDominantColors(BufferedImage image, int k)
      Extracts a palette of dominant colors from an image using the K-Means clustering algorithm.
      Parameters:
      image - The BufferedImage to analyze.
      k - The number of dominant colors to extract (the number of clusters).
      Returns:
      A ColorPalette containing the extracted dominant colors.
    • getAverageColor

      public static org.bukkit.Color getAverageColor(BufferedImage image)
      Calculates the global average color of an image, ignoring fully transparent pixels.
      Parameters:
      image - The BufferedImage to process.
      Returns:
      The average Color of the image, or Color.WHITE if no non-transparent pixels exist.
    • getHistogramPalette

      public static ColorPalette getHistogramPalette(BufferedImage image, int bins)
      Generates a color palette based on a color histogram with a specified number of bins.

      This method quantizes image colors and selects the most frequent ones to build a palette.

      Parameters:
      image - The BufferedImage to analyze.
      bins - The number of bins to use for color quantization (determines color granularity).
      Returns:
      A ColorPalette containing up to 16 of the most frequent quantized colors.