public int[][] labeling(BufferedImage image){
      int label = 0;
      int width = image.getWidth();
      int height = image.getHeight();
      labeledImage = new int[height][width]; 

      //start labeling
      for(int h = 1 ; h < height-1; h++){
        for(int w = 1 ; w < width-1; w++){
          int pixel = image.getRGB(w,h) & 0xff;    
          if(pixel == BLACK){
            int minLabel = getMinLabel(h,w);
            if(minLabel > 0){
              labeledImage[h][w] = minLabel;
            }else{
              label += 1;
              labeledImage[h][w] = label; 
            }
          }
        }
      }

      //reset label base on equalivalant
      for(int h=1;h<height-1;h++){
        for(int w=1;w<width-1;w++){
          if(equalTable.containsKey(labeledImage[h][w])){
             labeledImage[h][w] = findEqualivalant(labeledImage[h][w]);
          }
        }
      }
      return labeledImage;
  }