Class MedianCutNode

java.lang.Object
net.sourceforge.jiu.color.quantization.MedianCutNode
All Implemented Interfaces:
RGBIndex

public class MedianCutNode extends Object implements RGBIndex
An instance of this node class represents a cuboid part of the color cube representing the three-dimensional RGB color space.
Author:
Marco Schmidt
See Also:
  • Field Details

    • axis

      private int axis
    • axisDetermined

      private boolean axisDetermined
    • diff

      private int diff
    • index1

      private int index1
    • index2

      private int index2
    • leftSuccessor

      private MedianCutNode leftSuccessor
    • max

      private int[] max
    • medianValue

      private int medianValue
    • middleIndex

      private int middleIndex
    • min

      private int[] min
    • paletteIndex

      private int paletteIndex
    • parent

      private MedianCutNode parent
    • reprColor

      private int[] reprColor
    • rightSuccessor

      private MedianCutNode rightSuccessor
  • Constructor Details

    • MedianCutNode

      public MedianCutNode(MedianCutNode parent, int index1, int index2)
      Creates a node for a Median Cut tree of nodes with index values for some external color array and the parent node. This parent is null for the root node.
      Parameters:
      parent - the parent node of this new node, should be null only for the root node
      index1 - the index value of the first element of colors in the color list
      index2 - the index value of the last element of colors in the color list; must be larger than or equal to index1
      Throws:
      IllegalArgumentException - if index1 is larger than index2
  • Method Details

    • canBeSplit

      public boolean canBeSplit()
      Returns if this node can be split into two. This is true if and only if this is a leaf and if the color list index values represent an interval of at least length 2.
      Returns:
      if this node can be split into two nodes
    • computeRgbDistance

      public double computeRgbDistance(MedianCutNode node)
      Computes the distance in RGB color space between the representative color of this node and the argument node and returns it as non-negative value.
    • determineMiddleIndex

      private void determineMiddleIndex()
      Computes the middle index value of this node. It uses the index values given to this node's constructor, index1 and index2.
    • getAxisOfLargestDistribution

      public int getAxisOfLargestDistribution()
      Returns the axis of the channel whose samples are most widely distributed among the colors that belong to this node.
      Returns:
      index of axis, one of the RGBIndex constants
      Throws:
      IllegalArgumentException - if that axis has not been determined
    • getDifferenceOfLargestDistribution

      public int getDifferenceOfLargestDistribution()
    • getLeftIndex

      public int getLeftIndex()
    • getLeftSuccessor

      public MedianCutNode getLeftSuccessor()
      Returns left successor node (or null if this node is a leaf).
    • getMaxColorSample

      public int getMaxColorSample(int index)
    • getMedianValue

      public int getMedianValue()
    • getMiddleIndex

      public int getMiddleIndex()
    • getMinColorSample

      public int getMinColorSample(int index)
    • getNumColors

      public int getNumColors()
    • getPaletteIndex

      public int getPaletteIndex()
    • getParentNode

      public MedianCutNode getParentNode()
      Returns parent node (or null if this node is the root node).
    • getRepresentativeColor

      public int[] getRepresentativeColor()
    • getRightIndex

      public int getRightIndex()
    • getRightSuccessor

      public MedianCutNode getRightSuccessor()
      Returns right successor node (or null if this node is a leaf).
    • getSuccessor

      public MedianCutNode getSuccessor(int[] rgb)
    • isAxisDetermined

      public boolean isAxisDetermined()
    • isLeaf

      public boolean isLeaf()
      Returns if this node is a leaf by checking if both successors are null. Note that the case of one successor being null and the other non-null should never happen.
      Returns:
      if this node is a leaf (true)
    • setLargestDistribution

      public void setLargestDistribution(int newAxis, int newDifference)
    • setMaxColor

      public void setMaxColor(int red, int green, int blue)
    • setMaxColorSample

      public void setMaxColorSample(int index, int value)
    • setMedianValue

      public void setMedianValue(int newMedianValue)
    • setMinColor

      public void setMinColor(int red, int green, int blue)
    • setMinColorSample

      public void setMinColorSample(int index, int value)
    • setPaletteIndex

      public void setPaletteIndex(int newPaletteIndex)
    • setRepresentativeColor

      public void setRepresentativeColor(int[] aRepresentativeColor)
    • setSuccessors

      public void setSuccessors(MedianCutNode left, MedianCutNode right)
      Sets the successor nodes for this node. The successors must be either both null or both initialized. They must not be equal.
      Parameters:
      left - the left successor node
      right - the left successor node