protected void findAdjacentRegions ( GrayS32 pixelToRegion ) { // -------- Do the inner pixels first if ( connect . length == 4 ) adjacentInner4 ( pixelToRegion ) ; else if ( connect . length == 8 ) { adjacentInner8 ( pixelToRegion ) ; } adjacentBorder ( pixelToRegion ) ; }
Go through each pixel in the image and examine its neighbors according to a 4 - connect rule . If one of the pixels is in a region that is to be pruned mark them as neighbors . The image is traversed such that the number of comparisons is minimized .