net.sourceforge.jiu.color.quantization

Class MedianCutNode

Implemented Interfaces:
RGBIndex

public class MedianCutNode
extends java.lang.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:
MedianCutQuantizer

Field Summary

private int
axis
private boolean
axisDetermined
private int
diff
private int
index1
private int
index2
private MedianCutNode
leftSuccessor
private int[]
max
private int
medianValue
private int
middleIndex
private int[]
min
private int
paletteIndex
private MedianCutNode
parent
private int[]
reprColor
private MedianCutNode
rightSuccessor

Fields inherited from interface net.sourceforge.jiu.data.RGBIndex

INDEX_BLUE, INDEX_GREEN, INDEX_RED

Constructor Summary

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.

Method Summary

boolean
canBeSplit()
Returns if this node can be split into two.
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.
private void
determineMiddleIndex()
Computes the middle index value of this node.
int
getAxisOfLargestDistribution()
Returns the axis of the channel whose samples are most widely distributed among the colors that belong to this node.
int
getDifferenceOfLargestDistribution()
int
getLeftIndex()
MedianCutNode
getLeftSuccessor()
Returns left successor node (or null if this node is a leaf).
int
getMaxColorSample(int index)
int
getMedianValue()
int
getMiddleIndex()
int
getMinColorSample(int index)
int
getNumColors()
int
getPaletteIndex()
MedianCutNode
getParentNode()
Returns parent node (or null if this node is the root node).
int[]
getRepresentativeColor()
int
getRightIndex()
MedianCutNode
getRightSuccessor()
Returns right successor node (or null if this node is a leaf).
MedianCutNode
getSuccessor(int[] rgb)
boolean
isAxisDetermined()
boolean
isLeaf()
Returns if this node is a leaf by checking if both successors are null.
void
setLargestDistribution(int newAxis, int newDifference)
void
setMaxColor(int red, int green, int blue)
void
setMaxColorSample(int index, int value)
void
setMedianValue(int newMedianValue)
void
setMinColor(int red, int green, int blue)
void
setMinColorSample(int index, int value)
void
setPaletteIndex(int newPaletteIndex)
void
setRepresentativeColor(int[] aRepresentativeColor)
void
setSuccessors(MedianCutNode left, MedianCutNode right)
Sets the successor nodes for this node.

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

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.

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