public int getMinLabel(int h,int w){
    int label = Integer.MAX_VALUE;
    int min = 0;

    /*  check  OOO
     *         OX      get minimum value for labeling
     *                 also check if there is smaller value for equalTable
     */
    for(int i = -1; i<2; i++){
      if(labeledImage[h-1][w+i] > 0){
        min = Math.min(label,labeledImage[h-1][w+i]);
        if(min < label){
          if(!equalTable.containsKey(label)){
            equalTable.put(label,min);
          }
          label = min;
        }
      }
    }

    if(labeledImage[h][w-1] > 0){
      min = Math.min(label,labeledImage[h][w-1]);
      if(min < label){
        if(!equalTable.containsKey(label)){
          equalTable.put(label,min);
        }
        label = min;
      }
    }

    return label == Integer.MAX_VALUE ? 0 : label;
  }