code: public static void countRegionPixels(GrayS32 labeled , int totalRegions , int counts[] ) {
  
  		Arrays.fill(counts,0,totalRegions,0);
  
  		for( int y = 0; y < labeled.height; y++ ) {
  			int index = labeled.startIndex + y*labeled.stride;
  			for( int x = 0; x < labeled.width; x++ ) {
  				counts[labeled.data[index++]]++;
  			}
  		}
  	}
docs: Counts the number of pixels in all regions.  Regions must be have labels from 0 to totalRegions-1.
  
  @param labeled (Input) labeled image
  @param totalRegions Total number of regions
  @param counts Storage for pixel counts