Class MedianCut

java.lang.Object
ij.process.MedianCut

public class MedianCut extends Object
Converts an RGB image to 8-bit index color using Heckbert's median-cut color quantization algorithm. Based on median.c by Anton Kruger from the September, 1994 issue of Dr. Dobbs Journal. 2023-11-26 Modifictions by Michael Schmid: Calculates the average color values of the 8x8x8 bins, thus the color in the output is the exact average of the pixel colors (not the weighted average of the bin origins). In addition, bins are assigned to the closest available color, which is not necessarily that from the original median cut segmentation (refinement). This reduces the occurrence of large deviations from the orignal. In most cases, colors that occur very often are exactly perserved.
  • Constructor Details

    • MedianCut

      public MedianCut(int[] pixels, int width, int height)
    • MedianCut

      public MedianCut(ColorProcessor ip)
  • Method Details

    • convert

      public Image convert(int maxcubes)
      Uses Heckbert's median-cut algorithm to divide the color space defined by "hist" into "maxcubes" cubes. The centroids (average value) of each cube are are used to create a color table. "hist" is then updated to function as an inverse color map that is used to generate an 8-bit image.
    • convertToByte

      public ImageProcessor convertToByte(int maxcubes)
      This is a version of convert that returns a ByteProcessor.