Class MedianCutNode
java.lang.Object
net.sourceforge.jiu.color.quantization.MedianCutNode
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprivate int
private boolean
private int
private int
private int
private MedianCutNode
private int[]
private int
private int
private int[]
private int
private MedianCutNode
private int[]
private MedianCutNode
Fields inherited from interface net.sourceforge.jiu.data.RGBIndex
INDEX_BLUE, INDEX_GREEN, INDEX_RED
-
Constructor Summary
ConstructorsConstructorDescriptionMedianCutNode
(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
Modifier and TypeMethodDescriptionboolean
Returns if this node can be split into two.double
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
Computes the middle index value of this node.int
Returns the axis of the channel whose samples are most widely distributed among the colors that belong to this node.int
int
Returns left successor node (or null if this node is a leaf).int
getMaxColorSample
(int index) int
int
int
getMinColorSample
(int index) int
int
Returns parent node (or null if this node is the root node).int[]
int
Returns right successor node (or null if this node is a leaf).getSuccessor
(int[] rgb) boolean
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
-
max
private int[] max -
medianValue
private int medianValue -
middleIndex
private int middleIndex -
min
private int[] min -
paletteIndex
private int paletteIndex -
parent
-
reprColor
private int[] reprColor -
rightSuccessor
-
-
Constructor Details
-
MedianCutNode
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 nodeindex1
- the index value of the first element of colors in the color listindex2
- 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
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
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
Returns parent node (or null if this node is the root node). -
getRepresentativeColor
public int[] getRepresentativeColor() -
getRightIndex
public int getRightIndex() -
getRightSuccessor
Returns right successor node (or null if this node is a leaf). -
getSuccessor
-
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
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 noderight
- the left successor node
-