public void findMainLabels() {
	    clusters = new int[nLabels + 2];
	    nClusters = 0;
	    
	    /* only one label */
	    if (nLabels == 1) {
	    	nClusters++;
	    	clusters[nClusters] = 1;
	    	clusters[nClusters + 1] = Integer.MAX_VALUE;
	    } else {
	    	boolean reached[] = new boolean[nLabels+1];
	    	int j,i;
	      
	    	for (i=1; labels[i] != Integer.MAX_VALUE ; i++) {
	    		if (labels[i] != Integer.MIN_VALUE) {
	    			for (int k = 1; k < reached.length; k++) {
	    				reached[k] = false;
	    			}
	    		  
	    			reached[i] = true;
	    			j = i;
	    		  
	    			while (labels[j] != Integer.MIN_VALUE) {
	    				j = labels[j];
	    				if (reached[j]) {
	    					labels[i] = Integer.MIN_VALUE;
	    					break;
	    				} else {
	    					reached[j] = true;
	    				}
	    			}
	    			labels[i] = j;
	    		} else {
	    			nClusters++;
	    			clusters[nClusters] = i;
	    		}
	    	}
	      
	    	for (i = 1; labels[i] != Integer.MAX_VALUE ; i++) {
	    		if (labels[i] == Integer.MIN_VALUE) {
	    			labels[i] = i;
	    		}
	    	}
	    	
	    	clusters[nClusters + 1] = Integer.MAX_VALUE;
	    }
	 }