예제 #1
0
 public GrayScaleImage reconstruction(InfoPrunedTree prunedTree) {
   GrayScaleImage imgOut =
       ImageFactory.createGrayScaleImage(
           imgInput.getDepth(), imgInput.getWidth(), imgInput.getHeight());
   Queue<InfoPrunedTree.NodePrunedTree> fifo = new Queue<InfoPrunedTree.NodePrunedTree>();
   fifo.enqueue(prunedTree.getRoot());
   while (!fifo.isEmpty()) {
     InfoPrunedTree.NodePrunedTree node_ = fifo.dequeue();
     NodeCT node = (NodeCT) node_.getInfo();
     for (NodeCT son : node.children) {
       if (prunedTree.wasPruned(son)) {
         for (int p : son.getPixelsOfCC()) {
           imgOut.setPixel(p, node.level);
         }
       }
     }
     for (int p : node.getCanonicalPixels()) {
       imgOut.setPixel(p, node.level);
     }
     for (InfoPrunedTree.NodePrunedTree son : node_.getChildren()) {
       fifo.enqueue(son);
     }
   }
   return imgOut;
 }
예제 #2
0
  public void computerAdjcencyNodes() {
    long ti = System.currentTimeMillis();

    for (NodeCT node : this.listNode) {
      node.adjcencyNodes = new SimpleLinkedList<NodeCT>();
    }

    int flags[] = new int[listNode.size()];
    Arrays.fill(flags, -1);

    for (NodeCT node : listNode) {
      for (int p : node.getCanonicalPixels()) {
        for (int q : adj.getAdjacencyPixels(imgInput, p)) {
          if (map[p] != map[q]) {
            if (flags[map[q].getId()] != map[p].getId()) {
              flags[map[q].getId()] = map[p].getId();
              map[p].addAdjacencyNode(map[q]);
            }
          }
        }
      }
    }
    flags = null;
    long tf = System.currentTimeMillis();
    if (Utils.debug)
      System.out.println("Tempo de execucao [computerAdjcencyNodes] " + ((tf - ti) / 1000.0) + "s");
  }
예제 #3
0
 public ComponentTree getClone() {
   ComponentTree c = new ComponentTree(this.builder.getClone());
   c.isExtendedTree = this.isExtendedTree;
   c.sup = this.sup;
   c.inf = this.inf;
   for (NodeCT node : c.getListNodes()) {
     node.attributes =
         (HashMap<Integer, Attribute>) this.getSC(node.getCanonicalPixel()).attributes.clone();
   }
   if (this.isExtendedTree) {
     c.extendedTree();
   }
   return c;
 }
예제 #4
0
  public static void prunning(ComponentTree tree, NodeCT node) {
    if (node != tree.root) {
      NodeCT parent = node.parent;
      parent.children.remove(node);
      tree.listLeaves = null;

      for (NodeCT no : node.getNodesDescendants()) {
        tree.listNode.remove(no);
        tree.numNode--;
        for (int p : no.getCanonicalPixels()) {
          parent.addPixel(p);
          tree.map[p] = parent;
        }
      }
    } else {
      tree.numNode = 1;
      tree.listNode.clear();
      tree.listNode.add(node);
      node.children = new ArrayList<NodeCT>();
      for (int p = 0; p < tree.getInputImage().getSize(); p++) {
        tree.map[p] = node;
        node.addPixel(p);
      }
    }
  }
예제 #5
0
 protected void createNodesMap() {
   if (map == null) map = new NodeCT[imgInput.getSize()];
   listNode = new HashSet<NodeCT>();
   listLeaves = new LinkedList<NodeCT>();
   Queue<NodeCT> fifo = new Queue<NodeCT>();
   fifo.enqueue(this.root);
   while (!fifo.isEmpty()) {
     NodeCT no = fifo.dequeue();
     listNode.add(no);
     for (Integer p : no.getCanonicalPixels()) {
       map[p] = no;
     }
     for (NodeCT son : no.children) {
       fifo.enqueue(son);
     }
     if (no.children.isEmpty()) listLeaves.add(no);
   }
 }
예제 #6
0
  public GrayScaleImage reconstruction() {
    GrayScaleImage imgOut =
        ImageFactory.createGrayScaleImage(
            imgInput.getDepth(), imgInput.getWidth(), imgInput.getHeight());
    Queue<NodeCT> fifo = new Queue<NodeCT>();
    fifo.enqueue(this.root);
    while (!fifo.isEmpty()) {
      NodeCT no = fifo.dequeue();
      for (int p : no.getCanonicalPixels()) {
        imgOut.setPixel(p, no.level);
      }

      for (NodeCT son : no.children) {
        fifo.enqueue(son);
      }
    }
    return imgOut;
  }
예제 #7
0
  public void computerInforTree(NodeCT node, int height) {
    node.isNodeMaxtree = isMaxtree;
    node.heightNode = height;
    if (height > heightTree) heightTree = height;

    if (node != root) {
      node.numSiblings = node.parent.children.size();
    }

    for (NodeCT son : node.children) {
      computerInforTree(son, height + 1);

      if (son.isLeaf()) node.numDescendentLeaf += 1;
      node.numDescendent += son.numDescendent;
      node.numDescendentLeaf += son.numDescendentLeaf;
      node.area += son.area;
    }
  }
예제 #8
0
 public void prunning(NodeCT node) {
   if (node != root && map[node.getCanonicalPixel()] == node) {
     NodeCT parent = node.parent;
     parent.children.remove(node);
     listLeaves = null;
     for (NodeCT no : node.getNodesDescendants()) {
       listNode.remove(no);
       numNode--;
       for (int p : no.getCanonicalPixels()) {
         parent.addPixel(p);
         map[p] = parent;
       }
     }
   }
 }
예제 #9
0
  private NodeCT getExtendedBranchOfMintree(NodeCT no, int inicio, int fim) {
    if (inicio <= fim) return null;
    NodeCT ramoInicio = no.getClone();
    NodeCT ramoFim = ramoInicio;

    ramoFim.parent = no.parent;
    if (ramoFim.parent != null) {
      ramoFim.parent.children.remove(no);
      ramoFim.parent.children.add(ramoFim);
    }
    ramoFim.level = inicio;
    ramoFim.id = numNode++;
    for (int i = inicio - 1; i > fim; i--) {
      NodeCT noAtual = no.getClone();

      noAtual.parent = ramoFim;
      noAtual.level = i;
      noAtual.id = numNode++;
      ramoFim.children.add(noAtual);
      ramoFim = noAtual;
    }
    ramoFim.children.add(no);
    no.parent = ramoFim;

    return ramoInicio;
  }