コード例 #1
0
  public static int[] calculateVectorSpace(BufferedImage image) {
    clusters = createClusters(image);
    int[] vectorSpace = new int[IMAGE_WIDTH * IMAGE_HEIGHT];
    Arrays.fill(vectorSpace, -1);

    boolean refineNeeded = true;
    int loops = 0;
    while (refineNeeded) {
      refineNeeded = false;
      loops++;

      for (int y = 0; y < IMAGE_HEIGHT; y++) {
        for (int x = 0; x < IMAGE_WIDTH; x++) {
          int pixel = image.getRGB(x, y);
          Cluster cluster = getMinCluster(pixel);

          if (vectorSpace[IMAGE_WIDTH * y + x] != cluster.getId()) {
            if (vectorSpace[IMAGE_WIDTH * y + x] != -1) {
              clusters[vectorSpace[IMAGE_WIDTH * y + x]].removePixel(pixel);
            }
            cluster.addPixel(pixel);
            refineNeeded = true;
            vectorSpace[IMAGE_WIDTH * y + x] = cluster.getId();
          }
        }
      }
    }

    System.out.println("Took " + loops + " loops.");
    return vectorSpace;
  }
コード例 #2
0
ファイル: ClutoTree.java プロジェクト: hiralv/TableViewNew
  /** Generate the hierarchical cluster and display it as a denogram in the graph */
  public TreeNode makeTree(ClutoSolution cs) {
    int[] tsize = cs.getTreeCounts();
    int[][] ftree = cs.getForwardTree();
    int nnrows = tsize.length;
    int nrows = cs.getMatrix().getRowCount();

    // for (int i = 0; i < nnrows-1; i++) {
    // String s = "ftree" + "\t" + i + "\t" + ftree[i][0] + "\t" + ftree[i][1] + "\t" + tsize[i];
    // System.out.println(s);
    // }

    Cluster[] ca = new Cluster[nnrows];
    for (int i = 0; i < nnrows - 1; i++) {

      if (!true) {
        String s = "ftree" + "\t" + i + "\t" + ftree[i][0] + "\t" + ftree[i][1] + "\t" + tsize[i];
        System.out.println(s);
      }

      Cluster cn = i < nrows ? (Cluster) new RowCluster(tm, i, null) : new CompositeCluster();
      cn.setSimilarity(Math.abs(tsize[i]));
      ca[i] = cn;
      if (ftree[i][0] > -1) {
        cn.add(ca[ftree[i][0]]);
      }
      if (ftree[i][0] > -1) {
        cn.add(ca[ftree[i][1]]);
      }
      rootNode = cn;
    }
    return rootNode;
  }
コード例 #3
0
 // -------------------------------------------------------------------------------------
 public void handleCluster(String source, Cluster cluster) {
   handleNameList(myGaggleName, new Namelist(cluster.getSpecies(), cluster.getRowNames()));
 }