Package net.sourceforge.jiu.color.quantization

Examples of net.sourceforge.jiu.color.quantization.MedianCutNode


      }
      return node;
    }
    else
    {
      MedianCutNode node1 = findLeafToBeSplit(node.getLeftSuccessor());
      boolean canSplit1 = (node1 != null && node1.canBeSplit());
      MedianCutNode node2 = findLeafToBeSplit(node.getRightSuccessor());
      boolean canSplit2 = (node2 != null && node2.canBeSplit());
      if (canSplit1)
      {
        if (canSplit2)
        {
          // case 1 of 4: both nodes can be split; find out which one has the largest distribution
          // of samples for one of the three RGB channels
          if (node1.getDifferenceOfLargestDistribution() >= node2.getDifferenceOfLargestDistribution())
          {
            return node1;
          }
          else
          {
View Full Code Here


   *  three entries; {@link RGBIndex} constants are used to address the samples
   * @return node with best match
   */
  public MedianCutNode findNearestNeighbor(int[] rgb)
  {
    MedianCutNode result = root;
    while (!result.isLeaf())
    {
      result = result.getSuccessor(rgb);
    }
    return result;
  }
View Full Code Here

  {
    int index = -1;
    double distance = 1000000;
    for (int i = 0; i < nodes.length; i++)
    {
      MedianCutNode node = nodes[i];
      int[] reprColor = node.getRepresentativeColor();
      double d = RGBColor.computeDistance(red, green, blue,
        reprColor[INDEX_RED], reprColor[INDEX_GREEN], reprColor[INDEX_BLUE]);
      if (d < distance)
      {
        distance = d;
View Full Code Here

  {
    int colorsLeft = paletteSize - 1;
    while (colorsLeft > 0)
    {
      // find leaf with largest sample difference
      MedianCutNode node = findLeafToBeSplit(root);
      splitNode(node);
      colorsLeft--;
    }
    findRepresentativeColors(root);
    setAllPaletteIndexValues();
View Full Code Here

    return outputTruecolor;
  }

  public int map(int[] origRgb, int[] quantizedRgb)
  {
    MedianCutNode node = findNearestNeighbor(origRgb);
    int[] reprColor = node.getRepresentativeColor();
    quantizedRgb[INDEX_RED] = reprColor[INDEX_RED];
    quantizedRgb[INDEX_GREEN] = reprColor[INDEX_GREEN];
    quantizedRgb[INDEX_BLUE] = reprColor[INDEX_BLUE];
    return node.getPaletteIndex();
  }
View Full Code Here

      for (int x = 0; x < in.getWidth(); x++)
      {
        rgb[INDEX_RED] = in.getSample(INDEX_RED, x, y);
        rgb[INDEX_GREEN] = in.getSample(INDEX_GREEN, x, y);
        rgb[INDEX_BLUE] = in.getSample(INDEX_BLUE, x, y);
        MedianCutNode node = findNearestNeighbor(rgb);
        int[] reprColor = node.getRepresentativeColor();
        out.putSample(INDEX_RED, x, y, reprColor[INDEX_RED]);
        out.putSample(INDEX_GREEN, x, y, reprColor[INDEX_GREEN]);
        out.putSample(INDEX_BLUE, x, y, reprColor[INDEX_BLUE]);
      }
    }
View Full Code Here

      for (int x = 0; x < in.getWidth(); x++)
      {
        rgb[INDEX_RED] = in.getSample(INDEX_RED, x, y);
        rgb[INDEX_GREEN] = in.getSample(INDEX_GREEN, x, y);
        rgb[INDEX_BLUE] = in.getSample(INDEX_BLUE, x, y);
        MedianCutNode node = findNearestNeighbor(rgb);
        out.putSample(0, x, y, node.getPaletteIndex());
      }
    }
  }
View Full Code Here

    }
    else
    {
      throw new WrongParameterException("Input image must implement RGB24Image.");
    }
    root = new MedianCutNode(null, 0, list.getNumEntries() - 1);
    root.setMinColor(0, 0, 0);
    root.setMaxColor(maxValue, maxValue, maxValue);
    findPalette();
    if (doNotMap)
    {
View Full Code Here

    node.setMedianValue(medianValue);
    if (leftIndex == rightIndex)
    {
      throw new IllegalArgumentException("Cannot split leaf that only holds one color. This should never happen.");
    }
    MedianCutNode left = new MedianCutNode(node, leftIndex, middleIndex);
    MedianCutNode right = new MedianCutNode(node, middleIndex + 1, rightIndex);
    node.setSuccessors(left, right);
    for (int i = 0; i < 3; i++)
    {
      int max = node.getMaxColorSample(i);
      left.setMaxColorSample(i, max);
      right.setMaxColorSample(i, max);
      int min = node.getMinColorSample(i);
      left.setMinColorSample(i, min);
      right.setMinColorSample(i, min);
    }
    left.setMaxColorSample(axis, medianValue);
    right.setMinColorSample(axis, medianValue + 1);
  }
View Full Code Here

TOP

Related Classes of net.sourceforge.jiu.color.quantization.MedianCutNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.