protected void computeScoreFive ( int top [ ] , int middle [ ] , int bottom [ ] , int score [ ] , int width ) { // disparity as the outer loop to maximize common elements in inner loops, reducing redundant calculations for ( int d = minDisparity ; d < maxDisparity ; d ++ ) { // take in account the different in image border between the sub-regions and the effective region int indexSrc = ( d - minDisparity ) * width + ( d - minDisparity ) + radiusX ; int indexDst = ( d - minDisparity ) * width + ( d - minDisparity ) ; int end = indexSrc + ( width - d - 4 * radiusX ) ; while ( indexSrc < end ) { int s = 0 ; // sample four outer regions at the corners around the center region int val0 = top [ indexSrc - radiusX ] ; int val1 = top [ indexSrc + radiusX ] ; int val2 = bottom [ indexSrc - radiusX ] ; int val3 = bottom [ indexSrc + radiusX ] ; // select the two best scores from outer for regions if ( val1 < val0 ) { int temp = val0 ; val0 = val1 ; val1 = temp ; } if ( val3 < val2 ) { int temp = val2 ; val2 = val3 ; val3 = temp ; } if ( val3 < val0 ) { s += val2 ; s += val3 ; } else if ( val2 < val1 ) { s += val2 ; s += val0 ; } else { s += val0 ; s += val1 ; } score [ indexDst ++ ] = s + middle [ indexSrc ++ ] ; } } }
Compute the final score by sampling the 5 regions . Four regions are sampled around the center region . Out of those four only the two with the smallest score are used .