public void process ( T image , GrayS32 pixelToRegion , GrowQueue_I32 regionMemberCount , FastQueue < float [ ] > regionColor ) { this . image = image ; // Initialize data structures regionSums . resize ( regionColor . size ) ; for ( int i = 0 ; i < regionSums . size ; i ++ ) { float v [ ] = regionSums . get ( i ) ; for ( int j = 0 ; j < v . length ; j ++ ) { v [ j ] = 0 ; } } // Sum up the pixel values for each region for ( int y = 0 ; y < image . height ; y ++ ) { int indexImg = image . startIndex + y * image . stride ; int indexRgn = pixelToRegion . startIndex + y * pixelToRegion . stride ; for ( int x = 0 ; x < image . width ; x ++ , indexRgn ++ , indexImg ++ ) { int region = pixelToRegion . data [ indexRgn ] ; float [ ] sum = regionSums . get ( region ) ; addPixelValue ( indexImg , sum ) ; } } // Compute the average using the sum and update the region color for ( int i = 0 ; i < regionSums . size ; i ++ ) { float N = regionMemberCount . get ( i ) ; float [ ] sum = regionSums . get ( i ) ; float [ ] average = regionColor . get ( i ) ; for ( int j = 0 ; j < numBands ; j ++ ) { average [ j ] = sum [ j ] / N ; } } }
Compute the average color for each region