ij.process
Class MedianCut

java.lang.Object
  extended by ij.process.MedianCut

public class MedianCut
extends java.lang.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.


Field Summary
(package private) static int HSIZE
           
(package private) static int MAXCOLORS
           
 
Constructor Summary
MedianCut(ColorProcessor ip)
           
MedianCut(int[] pixels, int width, int height)
           
 
Method Summary
 java.awt.Image convert(int maxcubes)
          Uses Heckbert's median-cut algorithm to divide the color space defined by "hist" into "maxcubes" cubes.
 ImageProcessor convertToByte(int maxcubes)
          This is a version of convert that returns a ByteProcessor.
(package private)  int getColorCount()
           
(package private)  java.awt.Color getModalColor()
           
(package private)  ImageProcessor makeImage()
           
(package private)  void makeInverseMap(int[] hist, int ncubes)
           
(package private)  void quickSort(int[] a, int lo0, int hi0)
           
(package private)  void reorderColors(int[] a, int lo, int hi, int longDim)
           
(package private)  void restoreColorOrder(int[] a, int lo, int hi, int longDim)
           
(package private)  void Shrink(Cube cube)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAXCOLORS

static final int MAXCOLORS
See Also:
Constant Field Values

HSIZE

static final int HSIZE
See Also:
Constant Field Values
Constructor Detail

MedianCut

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

MedianCut

public MedianCut(ColorProcessor ip)
Method Detail

getColorCount

int getColorCount()

getModalColor

java.awt.Color getModalColor()

convert

public java.awt.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.


Shrink

void Shrink(Cube cube)

makeInverseMap

void makeInverseMap(int[] hist,
                    int ncubes)

reorderColors

void reorderColors(int[] a,
                   int lo,
                   int hi,
                   int longDim)

restoreColorOrder

void restoreColorOrder(int[] a,
                       int lo,
                       int hi,
                       int longDim)

quickSort

void quickSort(int[] a,
               int lo0,
               int hi0)

makeImage

ImageProcessor makeImage()