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 ++ ] ] ++ ; } } }
Counts the number of pixels in all regions . Regions must be have labels from 0 to totalRegions - 1 .